-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03ab7d6
commit ecd81dd
Showing
10 changed files
with
229 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.statnett.loadflowservice | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.powsybl.security.SecurityAnalysisResult | ||
import com.powsybl.security.json.SecurityAnalysisJsonModule | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
object SecurityAnalysisResultSerializer : KSerializer<SecurityAnalysisResult> { | ||
private val mapper = ObjectMapper() | ||
|
||
init { | ||
mapper.registerModule(SecurityAnalysisJsonModule()) | ||
} | ||
|
||
override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("security-analysis-report", PrimitiveKind.STRING) | ||
|
||
override fun serialize(encoder: Encoder, value: SecurityAnalysisResult) { | ||
val string = mapper.writeValueAsString(value) | ||
encoder.encodeString(string) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): SecurityAnalysisResult { | ||
val string = decoder.decodeString() | ||
return mapper.readValue(string, SecurityAnalysisResult::class.java) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/formItemHandlers/SecurityAnalysisParametersContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.github.statnett.loadflowservice.formItemHandlers | ||
|
||
import com.powsybl.security.SecurityAnalysisParameters | ||
import com.powsybl.security.json.JsonSecurityAnalysisParameters | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import io.ktor.http.content.* | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
class SecurityAnalysisParametersContainer : AutoVersionableJsonParser(), FormItemLoadable { | ||
var parameters = SecurityAnalysisParameters() | ||
|
||
override fun currentVersion(): String { | ||
return SecurityAnalysisParameters.VERSION | ||
} | ||
|
||
fun update(jsonString: String) { | ||
val withVersion = jsonStringWithVersion(jsonString) | ||
this.parameters = JsonSecurityAnalysisParameters.update(this.parameters, withVersion.byteInputStream()) | ||
} | ||
|
||
override fun formItemHandler(part: PartData.FormItem) { | ||
val name = part.name ?: "" | ||
if (name == "security-analysis-parameters") { | ||
this.update(part.value) | ||
logger.info { "Received security analysis parameters: ${part.value}" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package testDataFactory | ||
|
||
import io.ktor.client.request.forms.* | ||
import io.ktor.http.content.* | ||
|
||
fun ieee14SecurityParams(): String { | ||
return "{\"flow-proportional-threshold\": 0.2}" | ||
} | ||
|
||
fun securityParams(): List<PartData> { | ||
return formData { | ||
append( | ||
"security-analysis-parameters", | ||
ieee14SecurityParams() | ||
) | ||
} | ||
} | ||
|
||
data class SecurityAnalysisFormDataContainer( | ||
val network: List<PartData> = formDataFromFile(ieeeCdfNetwork14CgmesFile()), | ||
val loadParams: List<PartData> = loadParams(), | ||
val securityParams: List<PartData> = securityParams(), | ||
val contingencies: List<PartData> = contingencies(), | ||
) { | ||
fun formData(): List<PartData> { | ||
val parts: MutableList<PartData> = arrayListOf() | ||
parts += network | ||
parts += contingencies | ||
//parts += securityParams | ||
parts += loadParams | ||
return parts | ||
} | ||
} |