Skip to content

Commit

Permalink
Add SensitivityAnalysisParameters container
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven committed Oct 8, 2023
1 parent 50d9f99 commit a906d8f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/SensitivityAnalysisParametersContainer.kt
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}" }
}
}
}
19 changes: 19 additions & 0 deletions src/test/SensitivityAnalysisParametersContainerTest.kt
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)
}
}

0 comments on commit a906d8f

Please sign in to comment.