Skip to content

Commit

Permalink
Add report to the run result
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven committed Oct 3, 2023
1 parent 6dad01d commit 0ad8301
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/ApiDataModels.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.statnett.loadflowservice

import com.powsybl.commons.reporter.Reporter
import com.powsybl.commons.reporter.ReporterModel
import com.powsybl.iidm.network.Network
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -46,7 +48,7 @@ data class LoadFlowResultForApi(
val isOk: Boolean,
val buses: List<BusProperties>,
val branches: List<LineProperties>,
val log: String
val report: String
)

fun branchPropertiesFromNetwork(network: Network): List<LineProperties> {
Expand Down
29 changes: 27 additions & 2 deletions src/main/Solver.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.statnett.loadflowservice

import com.powsybl.commons.reporter.ReporterModel
import com.powsybl.computation.local.LocalComputationManager
import com.powsybl.iidm.network.ImportersServiceLoader
import com.powsybl.iidm.network.Network
import com.powsybl.loadflow.LoadFlow
Expand All @@ -8,6 +10,7 @@ import com.powsybl.loadflow.json.JsonLoadFlowParameters
import io.github.oshai.kotlinlogging.KotlinLogging
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.StringWriter

private val logger = KotlinLogging.logger {}

Expand Down Expand Up @@ -45,15 +48,37 @@ fun defaultLoadFlowParameters(): String {
return undoPrettyPrintJson(stream.toString())
}

fun loadFlowTaskName(): String {
return "load-flow"
}

fun loadFlowReporter(): ReporterModel {
val name = loadFlowTaskName()
return ReporterModel(name, name)
}

fun reporterToString(reporter: ReporterModel): String {
val writer = StringWriter()
reporter.export(writer)
return writer.toString()
}

fun solve(
network: Network,
parameters: LoadFlowParameters,
): LoadFlowResultForApi {
val result = LoadFlow.run(network, parameters)
val reporter = loadFlowReporter()
val result = LoadFlow.run(
network,
network.variantManager.workingVariantId,
LocalComputationManager.getDefault(),
parameters,
reporter
)
return LoadFlowResultForApi(
isOk = result.isOk,
buses = busPropertiesFromNetwork(network),
branches = branchPropertiesFromNetwork(network),
log = result.logs ?: ""
report = reporterToString(reporter)
)
}

0 comments on commit 0ad8301

Please sign in to comment.