From 15770cab3de43ea4154012d44b8b1ea3759012c9 Mon Sep 17 00:00:00 2001 From: David Kleiven Date: Tue, 26 Sep 2023 12:27:44 +0200 Subject: [PATCH] Run code formatting --- src/main/ApiUtil.kt | 9 ++++++--- src/main/Solver.kt | 1 - src/test/AppTest.kt | 26 ++++++++++++-------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/ApiUtil.kt b/src/main/ApiUtil.kt index b8d3513..550ac76 100644 --- a/src/main/ApiUtil.kt +++ b/src/main/ApiUtil.kt @@ -1,7 +1,6 @@ package com.github.statnett.loadflowservice import com.powsybl.loadflow.LoadFlowParameters -import com.powsybl.loadflow.LoadFlowResult import com.powsybl.loadflow.json.JsonLoadFlowParameters import io.ktor.http.content.* import java.io.ByteArrayInputStream @@ -19,7 +18,7 @@ class FileContent(val name: String, val bytes: ByteArray) /** * Convenience class used to deserialize and update a load parameter instance */ -class LoadParameterContainer() { +class LoadParameterContainer { var parameters = LoadFlowParameters() private var parametersModified = false private fun update(jsonString: String) { @@ -35,13 +34,17 @@ class LoadParameterContainer() { } } -suspend fun multiPartDataHandler(multiPartData: MultiPartData, formItemHandler: (part: PartData.FormItem) -> Unit = {}): List { +suspend fun multiPartDataHandler( + multiPartData: MultiPartData, + formItemHandler: (part: PartData.FormItem) -> Unit = {} +): List { val files = mutableListOf() multiPartData.forEachPart { part -> when (part) { is PartData.FormItem -> { formItemHandler(part) } + is PartData.FileItem -> { val name = part.originalFileName as String val content = part.streamProvider().readBytes() diff --git a/src/main/Solver.kt b/src/main/Solver.kt index 06471d5..c42f375 100644 --- a/src/main/Solver.kt +++ b/src/main/Solver.kt @@ -3,7 +3,6 @@ package com.github.statnett.loadflowservice import com.powsybl.iidm.network.Network import com.powsybl.loadflow.LoadFlow import com.powsybl.loadflow.LoadFlowParameters -import com.powsybl.loadflow.LoadFlowResult import com.powsybl.loadflow.json.JsonLoadFlowParameters import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream diff --git a/src/test/AppTest.kt b/src/test/AppTest.kt index f400507..c2dafb3 100644 --- a/src/test/AppTest.kt +++ b/src/test/AppTest.kt @@ -1,17 +1,14 @@ import com.github.statnett.loadflowservice.busPropertiesFromNetwork import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory import io.ktor.client.request.* -import io.ktor.client.request.forms.formData -import io.ktor.client.request.forms.submitFormWithBinaryData +import io.ktor.client.request.forms.* import io.ktor.client.statement.* -import io.ktor.http.Headers -import io.ktor.http.HttpHeaders -import io.ktor.http.HttpStatusCode +import io.ktor.http.* import io.ktor.http.content.* -import io.ktor.server.testing.testApplication +import io.ktor.server.testing.* import java.io.File import java.nio.file.Paths -import java.util.Properties +import java.util.* import kotlin.math.abs import kotlin.test.Test import kotlin.test.assertContains @@ -34,9 +31,9 @@ class ApplicationTest { client.submitFormWithBinaryData( url = "/get-buses", formData = - formData { - append("network", "not file content") - }, + formData { + append("network", "not file content") + }, ) assertEquals(HttpStatusCode.UnprocessableEntity, response.status) } @@ -57,7 +54,8 @@ class ApplicationTest { assertTrue(body.startsWith("[{")) assertTrue(body.endsWith("}]")) - val busString = "{\"id\":\"VL1_0\",\"voltage\":143.1,\"angle\":0.0,\"activePower\":0.0,\"reactivePower\":0.0}" + val busString = + "{\"id\":\"VL1_0\",\"voltage\":143.1,\"angle\":0.0,\"activePower\":0.0,\"reactivePower\":0.0}" assertContains(body, busString) } @@ -87,12 +85,12 @@ class ApplicationTest { val angles = busPropertiesFromNetwork(solvedNetwork).map { bus -> bus.angle }.toList() val regex = Regex("\"angle\":([0-9.-]+)") - val anglesFromJsonStr = regex.findAll(body).map {match -> match.groupValues[1].toDouble()}.toList() + val anglesFromJsonStr = regex.findAll(body).map { match -> match.groupValues[1].toDouble() }.toList() // It seems like the solved version from Powsybl contains rounded angles assertTrue( - angles.zip(anglesFromJsonStr).all { - pair -> abs(pair.component1() - pair.component2()) < 0.01 + angles.zip(anglesFromJsonStr).all { pair -> + abs(pair.component1() - pair.component2()) < 0.01 } ) }