Skip to content

Commit

Permalink
Add default security analysis parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven committed Nov 19, 2023
1 parent ca0588d commit dda3795
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/ApiUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.github.statnett.loadflowservice
import com.fasterxml.jackson.databind.ObjectMapper
import com.powsybl.iidm.network.Network
import com.powsybl.nad.NetworkAreaDiagram
import com.powsybl.security.SecurityAnalysisParameters
import com.powsybl.security.json.SecurityAnalysisJsonModule
import com.powsybl.sensitivity.SensitivityAnalysisParameters
import com.powsybl.sensitivity.json.SensitivityJsonModule
import com.powsybl.sld.SingleLineDiagram
Expand Down Expand Up @@ -116,11 +118,18 @@ fun defaultSensitivityAnalysisParameters(): String {
return mapper.writeValueAsString(SensitivityAnalysisParameters())
}

fun defaultSecurityAnalysisParameters(): String {
val mapper = ObjectMapper()
mapper.registerModule(SecurityAnalysisJsonModule())
return mapper.writeValueAsString(SecurityAnalysisParameters())
}

class UnknownRouteException(message: String) : Exception(message)

fun defaultParameterSet(name: String): String {
val loadParams = "load-params"
val sensitivityAnalysisParams = "sensitivity-analysis-params"
val securityAnalysisParams = "security-analysis-params"
return when (name) {
loadParams -> {
defaultLoadFlowParameters()
Expand All @@ -130,6 +139,10 @@ fun defaultParameterSet(name: String): String {
defaultSensitivityAnalysisParameters()
}

securityAnalysisParams -> {
defaultSecurityAnalysisParameters()
}

else -> {
val allowed = listOf(loadParams, sensitivityAnalysisParams)
throw UnknownRouteException("Unknown parameters set $name. Must be one of $allowed")
Expand Down
12 changes: 12 additions & 0 deletions src/test/AppTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ class ApplicationTest {
}
}

@Test
fun `test default security analysis parameters`() {
testApplication {
val response = client.get("default-values/security-analysis-params")
assertEquals(HttpStatusCode.OK, response.status)
val body = response.bodyAsText()
assertTrue(body.startsWith("{"))
assertTrue(body.endsWith("}"))
}

}


}

Expand Down

0 comments on commit dda3795

Please sign in to comment.