-
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
f56ea7c
commit ed063c3
Showing
3 changed files
with
73 additions
and
1 deletion.
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,55 @@ | ||
package com.github.statnett.loadflowservice | ||
|
||
import com.powsybl.contingency.ContingencyContext | ||
import com.powsybl.contingency.ContingencyContextType | ||
import com.powsybl.sensitivity.SensitivityFactor | ||
import com.powsybl.sensitivity.SensitivityFunctionType | ||
import com.powsybl.sensitivity.SensitivityVariableType | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import io.ktor.http.content.* | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.Json | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
@Serializable | ||
class AutoSerializableSensitivityFactor( | ||
private val functionType: String, | ||
private val functionId: String, | ||
private val variableType: String, | ||
private val variableId: String, | ||
private val variableSet: Boolean, | ||
private val contingencyContextType: String | ||
) { | ||
fun asSensitivityFactor(): SensitivityFactor { | ||
val ctgType = ContingencyContextType.valueOf(contingencyContextType) | ||
return SensitivityFactor( | ||
SensitivityFunctionType.valueOf(functionType), functionId, | ||
SensitivityVariableType.valueOf(variableType), variableId, variableSet, | ||
|
||
// TODO: Check how contingencyId is passed when type is SPECIAL | ||
ContingencyContext.create(null, ctgType) | ||
) | ||
} | ||
} | ||
|
||
typealias AutoSerializableSensitivityFactorList = List<AutoSerializableSensitivityFactor> | ||
|
||
class SensitivityFactorContainer : FormItemLoadable { | ||
var factors: List<SensitivityFactor> = listOf() | ||
|
||
fun update(jsonString: String) { | ||
this.factors = Json.decodeFromString<AutoSerializableSensitivityFactorList>(jsonString).map { item -> | ||
item.asSensitivityFactor() | ||
} | ||
} | ||
|
||
override fun formItemHandler(part: PartData.FormItem) { | ||
val name = part.name ?: "" | ||
if (name == "sensitivity-factors") { | ||
this.update(part.value) | ||
logger.info { "Received sensitivity factors 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
import com.github.statnett.loadflowservice.SensitivityFactorContainer | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class SensitivityFactorContainerTest { | ||
} | ||
@Test | ||
fun `load basic json`() { | ||
val container = SensitivityFactorContainer() | ||
container.update(sensitivityFactorList()) | ||
assertEquals(1, container.factors.size) | ||
|
||
} | ||
} |