Skip to content

Commit

Permalink
First running test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven committed Sep 24, 2023
1 parent 11c13a5 commit cfec04e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.{kt,kts}]
max_line_length = 120
ktlint_code_style = ktlint_official
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<kotlin.version>1.9.10</kotlin.version>
<ktor.version>2.3.4</ktor.version>
<main.class>com.github.statnett.loadflowservice.AppKt</main.class>
<kotlin.code.style>official</kotlin.code.style>
</properties>

<repositories>
Expand Down Expand Up @@ -38,6 +39,11 @@
<artifactId>ktor-server-netty-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>1.9.20-Beta2</version>
</dependency>
</dependencies>

<build>
Expand Down
26 changes: 26 additions & 0 deletions src/main/ApiDataModels.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.statnett.loadflowservice

import com.powsybl.iidm.network.Network

/**
* Class for holding properties from the PowsbyBl bus class that are
* returned via the Rest API
*/
data class BusProperties(
val id: String,
val voltage: Double,
val angle: Double,
val activePower: Double,
val reactivePower: Double,
)

fun busPropertiesFromNetwork(network: Network) =
network.getBusView().getBusStream().map {
BusProperties(
id = it.getId(),
voltage = it.getV(),
angle = it.getAngle(),
activePower = it.getP(),
reactivePower = it.getQ(),
)
}
6 changes: 3 additions & 3 deletions src/main/app.kt → src/main/App.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.statnett.loadflowservice

import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.Netty
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*

fun main() {
embeddedServer(Netty, port = 8080) {
Expand All @@ -14,4 +14,4 @@ fun main() {
}
}
}.start(wait = true)
}
}
18 changes: 12 additions & 6 deletions src/main/solver.kt → src/main/Solver.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.github.statnett.loadflowservice

import com.powsybl.iidm.network.Network
import com.powsybl.loadflow.LoadFlowParameters
import com.powsybl.loadflow.LoadFlow
import com.powsybl.loadflow.LoadFlowParameters
import java.io.InputStream

fun networkFromStream(fname: String, content: InputStream): Network {
fun networkFromStream(
fname: String,
content: InputStream,
): Network {
return Network.read(fname, content)
}
}

fun solve(network: Network, parameters: LoadFlowParameters) {
LoadFlow.run(network, parameters);
}
fun solve(
network: Network,
parameters: LoadFlowParameters,
) {
LoadFlow.run(network, parameters)
}
14 changes: 14 additions & 0 deletions src/test/ApiDataModelsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import kotlin.test.Test
import kotlin.test.assertEquals
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory
import com.github.statnett.loadflowservice.busPropertiesFromNetwork

class ApiDataModelTest {

@Test
fun `Should be 14 buses in test network`() {
val network = IeeeCdfNetworkFactory.create14()
val buses = busPropertiesFromNetwork(network)
assertEquals(buses.count(), 14)
}
}

0 comments on commit cfec04e

Please sign in to comment.