-
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.
Add SensitivityAnalysisParameters container
- Loading branch information
1 parent
50d9f99
commit a906d8f
Showing
2 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.statnett.loadflowservice | ||
|
||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
|
||
|
||
import com.powsybl.sensitivity.SensitivityAnalysisParameters | ||
import com.powsybl.sensitivity.json.JsonSensitivityAnalysisParameters | ||
import io.ktor.http.content.* | ||
|
||
private val logger = KotlinLogging.logger {} | ||
class SensitivityAnalysisParametersContainer: AutoVersionableJsonParser(), FormItemLoadable { | ||
var parameters = SensitivityAnalysisParameters() | ||
|
||
override fun currentVersion(): String { | ||
return SensitivityAnalysisParameters.VERSION | ||
} | ||
|
||
fun update(jsonString: String) { | ||
val withVersion = jsonStringWithVersion(jsonString) | ||
this.parameters = JsonSensitivityAnalysisParameters.update(this.parameters, withVersion.byteInputStream()) | ||
} | ||
|
||
override fun formItemHandler(part: PartData.FormItem) { | ||
val name = part.name ?: "" | ||
if (name == "sensitivity-analysis-parameters") { | ||
this.update(part.value) | ||
logger.info { "Received load flow 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import com.github.statnett.loadflowservice.ContingencyListContainer | ||
import com.github.statnett.loadflowservice.SensitivityAnalysisParametersContainer | ||
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory | ||
import kotlin.math.abs | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
import kotlin.test.assertTrue | ||
|
||
class SensitivityAnalysisParametersContainerTest { | ||
@Test | ||
fun `load basic json`() { | ||
val jsonString = "{\"voltage-voltage-sensitivity-value-threshold\": 1234.0}" | ||
val container = SensitivityAnalysisParametersContainer() | ||
container.update(jsonString) | ||
|
||
assertTrue(abs(container.parameters.voltageVoltageSensitivityValueThreshold - 1234.0) < 1e-8) | ||
} | ||
} |