From 3f6cf1353a39368dc31155d5a7be8c370589acc7 Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Mon, 17 Jun 2024 21:58:21 +0200 Subject: [PATCH 1/6] FixedfeedModelSpec.scala, spotlessApply --- .../model/participant/FixedFeedInModel.scala | 2 +- .../participant/FixedFeedModelTest.groovy | 2 +- .../participant/FixedFeedModelSpec.scala | 102 ++++++++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala diff --git a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala index c50b2f6211..dbda236e4c 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala @@ -68,7 +68,7 @@ final case class FixedFeedInModel( * @return * Active power */ - override protected def calculateActivePower( + override def calculateActivePower( modelState: ConstantState.type, data: FixedRelevantData.type = FixedRelevantData, ): Power = diff --git a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy index 268323d95f..486d29524f 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy @@ -76,4 +76,4 @@ class FixedFeedModelTest extends Specification { then: actualModel.calculateActivePower(ModelState.ConstantState$.MODULE$, CalcRelevantData.FixedRelevantData$.MODULE$) =~ expectedPower } -} +} \ No newline at end of file diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala new file mode 100644 index 0000000000..efa3d8b4a3 --- /dev/null +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala @@ -0,0 +1,102 @@ +/* + * © 2024. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ + +package edu.ie3.simona.model.participant + +import edu.ie3.datamodel.models.OperationTime +import edu.ie3.datamodel.models.input.NodeInput +import edu.ie3.datamodel.models.input.OperatorInput +import edu.ie3.datamodel.models.input.system.FixedFeedInInput +import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed +import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils +import edu.ie3.simona.model.SystemComponent +import edu.ie3.simona.model.participant.control.QControl +import edu.ie3.simona.test.common.UnitSpec +import edu.ie3.util.TimeUtil +import edu.ie3.util.quantities.PowerSystemUnits +import edu.ie3.util.scala.quantities.Sq +import org.scalatest.prop.TableDrivenPropertyChecks +import squants.Power +import squants.energy.Watts +import tech.units.indriya.quantity.Quantities + +import java.util.UUID + +class FixedFeedModelSpec extends UnitSpec with TableDrivenPropertyChecks { + implicit val tolerance: Power = Watts(1d) + "Having a fixed feed model" when { + val fixedFeedInput = new FixedFeedInInput( + UUID.fromString("4eeaf76a-ec17-4fc3-872d-34b7d6004b03"), + "testFixedFeed", + OperatorInput.NO_OPERATOR_ASSIGNED, + OperationTime.notLimited(), + new NodeInput( + UUID.fromString("e5c1cde5-c161-4a4f-997f-fcf31fecbf57"), + "TestNodeInputModel", + OperatorInput.NO_OPERATOR_ASSIGNED, + OperationTime.notLimited(), + Quantities.getQuantity(1d, PowerSystemUnits.PU), + false, + NodeInput.DEFAULT_GEO_POSITION, + GermanVoltageLevelUtils.LV, + -1, + ), + new CosPhiFixed("cosPhiFixed:{(0.0,0.95)}"), + null, + Quantities.getQuantity(282.74d, PowerSystemUnits.VOLTAMPERE), + 0.95, + ) + + def simulationStartDate = + TimeUtil.withDefaults.toZonedDateTime("2020-01-01T00:00:00Z") + + def simulationEndDate = + TimeUtil.withDefaults.toZonedDateTime("2020-12-31T23:59:00Z") + + def foreSeenOperationInterval = + SystemComponent.determineOperationInterval( + simulationStartDate, + simulationEndDate, + fixedFeedInput.getOperationTime, + ) + + val expectedPower = Sq.create( + fixedFeedInput + .getsRated() + .to(PowerSystemUnits.KILOWATT) + .getValue + .doubleValue() * -1 * fixedFeedInput.getCosPhiRated * 1.0, + PowerSystemUnits.KILOWATT, + ) + + "The fixed feed model" should { + "return approximately correct power calculations" in { + val actualModel = new FixedFeedInModel( + fixedFeedInput.getUuid, + fixedFeedInput.getId, + foreSeenOperationInterval, + QControl.apply(fixedFeedInput.getqCharacteristics()), + Sq.create( + fixedFeedInput + .getsRated() + .to(PowerSystemUnits.KILOWATT) + .getValue + .doubleValue() + .doubleValue(), + PowerSystemUnits.KILOWATT, + ), + fixedFeedInput.getCosPhiRated, + ) + + actualModel.calculateActivePower( + ModelState.ConstanteState, + FixedFeedModel.FixedRelevantData, + ) =~ expectedPower + } + } + + } +} From 97c03b65d620be85a8957622bbee4a283de62118 Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Wed, 26 Jun 2024 16:30:45 +0200 Subject: [PATCH 2/6] Rewrote FixedFeedModelTest from groovy to scala --- CHANGELOG.md | 1 + .../participant/FixedFeedModelTest.groovy | 79 ------------------- .../participant/FixedFeedModelSpec.scala | 12 ++- 3 files changed, 6 insertions(+), 86 deletions(-) delete mode 100644 src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy diff --git a/CHANGELOG.md b/CHANGELOG.md index c05424bddc..93dc7b0cd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Refactoring of `GridAgent` messages [#736](https://github.com/ie3-institute/simona/issues/736) - Rewrote PVModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) - Making configuration of `RefSystem` via config optional [#769](https://github.com/ie3-institute/simona/issues/769) +- Rewrote FixedFeedModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) ### Fixed - Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658) diff --git a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy deleted file mode 100644 index 486d29524f..0000000000 --- a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy +++ /dev/null @@ -1,79 +0,0 @@ -/* - * © 2020. TU Dortmund University, - * Institute of Energy Systems, Energy Efficiency and Energy Economics, - * Research group Distribution grid planning and operation - */ - -package edu.ie3.simona.model.participant - -import static edu.ie3.util.quantities.PowerSystemUnits.* - -import edu.ie3.datamodel.models.OperationTime -import edu.ie3.datamodel.models.input.NodeInput -import edu.ie3.datamodel.models.input.OperatorInput -import edu.ie3.datamodel.models.input.system.FixedFeedInInput -import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed -import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils -import edu.ie3.simona.model.SystemComponent -import edu.ie3.simona.model.participant.control.QControl -import edu.ie3.util.TimeUtil -import edu.ie3.util.scala.quantities.Sq -import spock.lang.Specification -import squants.energy.* -import tech.units.indriya.quantity.Quantities - -class FixedFeedModelTest extends Specification { - - def fixedFeedInput = new FixedFeedInInput( - UUID.fromString("4eeaf76a-ec17-4fc3-872d-34b7d6004b03"), - "testFixedFeed", - OperatorInput.NO_OPERATOR_ASSIGNED, - OperationTime.notLimited(), - new NodeInput( - UUID.fromString("e5c1cde5-c161-4a4f-997f-fcf31fecbf57"), - "TestNodeInputModel", - OperatorInput.NO_OPERATOR_ASSIGNED, - OperationTime.notLimited(), - Quantities.getQuantity(1d, PU), - false, - NodeInput.DEFAULT_GEO_POSITION, - GermanVoltageLevelUtils.LV, - -1 - ), - new CosPhiFixed("cosPhiFixed:{(0.0,0.95)}"), - null, - Quantities.getQuantity(282.74d, VOLTAMPERE), - 0.95 - ) - def simulationStartDate = TimeUtil.withDefaults.toZonedDateTime("2020-01-01T00:00:00Z") - def simulationEndDate = TimeUtil.withDefaults.toZonedDateTime("2020-12-31T23:59:00Z") - def foreSeenOperationInterval = - SystemComponent.determineOperationInterval( - simulationStartDate, - simulationEndDate, - fixedFeedInput.operationTime - ) - - def expectedPower = Sq.create(fixedFeedInput.sRated.value.doubleValue() * -1 * fixedFeedInput.cosPhiRated * 1.0, Kilowatts$.MODULE$) - - def "A fixed feed model should return approximately correct power calculations"() { - when: - def actualModel = new FixedFeedInModel( - fixedFeedInput.uuid, - fixedFeedInput.id, - foreSeenOperationInterval, - QControl.apply(fixedFeedInput.qCharacteristics), - Sq.create( - fixedFeedInput.sRated - .to(KILOWATT) - .value.doubleValue() - .doubleValue(), - Kilowatts$.MODULE$ - ), - fixedFeedInput.cosPhiRated - ) - - then: - actualModel.calculateActivePower(ModelState.ConstantState$.MODULE$, CalcRelevantData.FixedRelevantData$.MODULE$) =~ expectedPower - } -} \ No newline at end of file diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala index efa3d8b4a3..18b49b0101 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala @@ -19,8 +19,7 @@ import edu.ie3.util.TimeUtil import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.quantities.Sq import org.scalatest.prop.TableDrivenPropertyChecks -import squants.Power -import squants.energy.Watts +import squants.energy.{Kilowatts, Power, Watts} import tech.units.indriya.quantity.Quantities import java.util.UUID @@ -69,7 +68,7 @@ class FixedFeedModelSpec extends UnitSpec with TableDrivenPropertyChecks { .to(PowerSystemUnits.KILOWATT) .getValue .doubleValue() * -1 * fixedFeedInput.getCosPhiRated * 1.0, - PowerSystemUnits.KILOWATT, + Kilowatts, ) "The fixed feed model" should { @@ -84,16 +83,15 @@ class FixedFeedModelSpec extends UnitSpec with TableDrivenPropertyChecks { .getsRated() .to(PowerSystemUnits.KILOWATT) .getValue - .doubleValue() .doubleValue(), - PowerSystemUnits.KILOWATT, + Kilowatts, ), fixedFeedInput.getCosPhiRated, ) actualModel.calculateActivePower( - ModelState.ConstanteState, - FixedFeedModel.FixedRelevantData, + ModelState.ConstantState, + CalcRelevantData.FixedRelevantData, ) =~ expectedPower } } From bf73c61e147f9d905b7a2495f2fc3c2991ffbe2d Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Wed, 26 Jun 2024 17:03:27 +0200 Subject: [PATCH 3/6] Codacy --- .../edu/ie3/simona/model/participant/FixedFeedModelSpec.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala index 18b49b0101..a5715ab781 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala @@ -7,8 +7,7 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.OperationTime -import edu.ie3.datamodel.models.input.NodeInput -import edu.ie3.datamodel.models.input.OperatorInput +import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput} import edu.ie3.datamodel.models.input.system.FixedFeedInInput import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils From 1fbb2857568c4531a7ea101fee2c99ff15a6dc2d Mon Sep 17 00:00:00 2001 From: pierrepetersmeier <155652256+pierrepetersmeier@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:10:25 +0200 Subject: [PATCH 4/6] Update src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala Co-authored-by: Daniel Feismann <98817556+danielfeismann@users.noreply.github.com> --- .../ie3/simona/model/participant/FixedFeedModelSpec.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala index a5715ab781..59f1de1d02 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala @@ -61,13 +61,12 @@ class FixedFeedModelSpec extends UnitSpec with TableDrivenPropertyChecks { fixedFeedInput.getOperationTime, ) - val expectedPower = Sq.create( + val expectedPower = Kilowatts( fixedFeedInput .getsRated() .to(PowerSystemUnits.KILOWATT) .getValue - .doubleValue() * -1 * fixedFeedInput.getCosPhiRated * 1.0, - Kilowatts, + .doubleValue() * -1 * fixedFeedInput.getCosPhiRated ) "The fixed feed model" should { From d338fec6e3574e362179581342a544810bf00e86 Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Wed, 10 Jul 2024 13:07:54 +0200 Subject: [PATCH 5/6] FixedFeedModelSpec.scala simplified with FixedFeedInputTestData and DefaultTestData. --- .../participant/FixedFeedModelSpec.scala | 52 +++---------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala index 59f1de1d02..0c75a8b745 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala @@ -6,60 +6,20 @@ package edu.ie3.simona.model.participant -import edu.ie3.datamodel.models.OperationTime -import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput} -import edu.ie3.datamodel.models.input.system.FixedFeedInInput -import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed -import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils -import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.test.common.UnitSpec -import edu.ie3.util.TimeUtil +import edu.ie3.simona.test.common.input.FixedFeedInputTestData import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.quantities.Sq import org.scalatest.prop.TableDrivenPropertyChecks import squants.energy.{Kilowatts, Power, Watts} -import tech.units.indriya.quantity.Quantities -import java.util.UUID - -class FixedFeedModelSpec extends UnitSpec with TableDrivenPropertyChecks { +class FixedFeedModelSpec + extends UnitSpec + with FixedFeedInputTestData + with TableDrivenPropertyChecks { implicit val tolerance: Power = Watts(1d) "Having a fixed feed model" when { - val fixedFeedInput = new FixedFeedInInput( - UUID.fromString("4eeaf76a-ec17-4fc3-872d-34b7d6004b03"), - "testFixedFeed", - OperatorInput.NO_OPERATOR_ASSIGNED, - OperationTime.notLimited(), - new NodeInput( - UUID.fromString("e5c1cde5-c161-4a4f-997f-fcf31fecbf57"), - "TestNodeInputModel", - OperatorInput.NO_OPERATOR_ASSIGNED, - OperationTime.notLimited(), - Quantities.getQuantity(1d, PowerSystemUnits.PU), - false, - NodeInput.DEFAULT_GEO_POSITION, - GermanVoltageLevelUtils.LV, - -1, - ), - new CosPhiFixed("cosPhiFixed:{(0.0,0.95)}"), - null, - Quantities.getQuantity(282.74d, PowerSystemUnits.VOLTAMPERE), - 0.95, - ) - - def simulationStartDate = - TimeUtil.withDefaults.toZonedDateTime("2020-01-01T00:00:00Z") - - def simulationEndDate = - TimeUtil.withDefaults.toZonedDateTime("2020-12-31T23:59:00Z") - - def foreSeenOperationInterval = - SystemComponent.determineOperationInterval( - simulationStartDate, - simulationEndDate, - fixedFeedInput.getOperationTime, - ) val expectedPower = Kilowatts( fixedFeedInput @@ -74,7 +34,7 @@ class FixedFeedModelSpec extends UnitSpec with TableDrivenPropertyChecks { val actualModel = new FixedFeedInModel( fixedFeedInput.getUuid, fixedFeedInput.getId, - foreSeenOperationInterval, + defaultOperationInterval, QControl.apply(fixedFeedInput.getqCharacteristics()), Sq.create( fixedFeedInput From 45196679531a16ec89ecaddb991793b95d36deca Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Wed, 24 Jul 2024 21:22:28 +0200 Subject: [PATCH 6/6] remove sq.create(), fmt --- .../participant/FixedFeedModelSpec.scala | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala index 0c75a8b745..1de88e0918 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala @@ -21,28 +21,27 @@ class FixedFeedModelSpec implicit val tolerance: Power = Watts(1d) "Having a fixed feed model" when { - val expectedPower = Kilowatts( - fixedFeedInput - .getsRated() - .to(PowerSystemUnits.KILOWATT) - .getValue - .doubleValue() * -1 * fixedFeedInput.getCosPhiRated - ) - "The fixed feed model" should { "return approximately correct power calculations" in { + val expectedPower = Kilowatts( + fixedFeedInput + .getsRated() + .to(PowerSystemUnits.KILOWATT) + .getValue + .doubleValue() * -1 * fixedFeedInput.getCosPhiRated + ) + val actualModel = new FixedFeedInModel( fixedFeedInput.getUuid, fixedFeedInput.getId, defaultOperationInterval, QControl.apply(fixedFeedInput.getqCharacteristics()), - Sq.create( + Kilowatts( fixedFeedInput .getsRated() .to(PowerSystemUnits.KILOWATT) .getValue - .doubleValue(), - Kilowatts, + .doubleValue() ), fixedFeedInput.getCosPhiRated, )