From ecd71c9147f32075f15c29a3c6cd948598b1eb80 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Tue, 30 Jul 2024 13:15:11 +0200 Subject: [PATCH 1/2] Merging both `FixedFeedInModelSpec` tests. --- CHANGELOG.md | 1 + .../participant/FixedFeedInModelSpec.scala | 31 ++++++++++ .../participant/FixedFeedModelSpec.scala | 56 ------------------- 3 files changed, 32 insertions(+), 56 deletions(-) delete mode 100644 src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala diff --git a/CHANGELOG.md b/CHANGELOG.md index 75964bde00..95250f60d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rewrote FixedLoadModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) - Rewrote SystemComponentTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) - Converting remaining rst files to markdown [#838](https://github.com/ie3-institute/simona/issues/838) +- Merging both `FixedFeedInModelSpec` tests [#870](https://github.com/ie3-institute/simona/issues/870) ### 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/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala index bbd90653f1..3447a39d7c 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala @@ -13,6 +13,7 @@ import edu.ie3.simona.model.participant.load.{LoadModelBehaviour, LoadReference} import edu.ie3.simona.test.common.input.FixedFeedInputTestData import edu.ie3.simona.test.common.{DefaultTestData, UnitSpec} import edu.ie3.simona.util.ConfigUtil +import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.quantities.PowerSystemUnits.MEGAVOLTAMPERE import org.scalatest.PrivateMethodTester import squants.energy.{Kilowatts, Megawatts, Watts} @@ -69,5 +70,35 @@ class FixedFeedInModelSpec cosPhiRated shouldBe fixedFeedInput.getCosPhiRated } } + + "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()), + Kilowatts( + fixedFeedInput + .getsRated() + .to(PowerSystemUnits.KILOWATT) + .getValue + .doubleValue() + ), + fixedFeedInput.getCosPhiRated, + ) + + actualModel.calculateActivePower( + ModelState.ConstantState, + CalcRelevantData.FixedRelevantData, + ) shouldBe expectedPower + } } } diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala deleted file mode 100644 index 1cb083d9a0..0000000000 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala +++ /dev/null @@ -1,56 +0,0 @@ -/* - * © 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.simona.model.participant.control.QControl -import edu.ie3.simona.test.common.UnitSpec -import edu.ie3.simona.test.common.input.FixedFeedInputTestData -import edu.ie3.util.quantities.PowerSystemUnits -import org.scalatest.prop.TableDrivenPropertyChecks -import squants.energy.{Kilowatts, Power, Watts} - -class FixedFeedModelSpec - extends UnitSpec - with FixedFeedInputTestData - with TableDrivenPropertyChecks { - implicit val tolerance: Power = Watts(1d) - "Having a fixed feed model" when { - - "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()), - Kilowatts( - fixedFeedInput - .getsRated() - .to(PowerSystemUnits.KILOWATT) - .getValue - .doubleValue() - ), - fixedFeedInput.getCosPhiRated, - ) - - actualModel.calculateActivePower( - ModelState.ConstantState, - CalcRelevantData.FixedRelevantData, - ) shouldBe expectedPower - } - } - - } -} From 76be5d344ff66bd707e44791f9df98930d2019cf Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Thu, 1 Aug 2024 13:43:20 +0200 Subject: [PATCH 2/2] Fixing duration calculation in result events. --- CHANGELOG.md | 1 + .../io/runtime/RuntimeEventLogSink.scala | 22 ++++++++++++------- .../RuntimeEventListenerLoggingSpec.scala | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95250f60d8..468de1d410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Finally fixing `RuntimeEventListenerSpec` [#849](https://github.com/ie3-institute/simona/issues/849) - Fixed result output for thermal houses and cylindrical storages [#844](https://github.com/ie3-institute/simona/issues/844) - Fixed FixedFeedModelSpec [#861](https://github.com/ie3-institute/simona/issues/861) +- Fixing duration calculation in result events [#801](https://github.com/ie3-institute/simona/issues/801) ## [3.0.0] - 2023-08-07 diff --git a/src/main/scala/edu/ie3/simona/io/runtime/RuntimeEventLogSink.scala b/src/main/scala/edu/ie3/simona/io/runtime/RuntimeEventLogSink.scala index 2af82e5589..b46ccc06b0 100644 --- a/src/main/scala/edu/ie3/simona/io/runtime/RuntimeEventLogSink.scala +++ b/src/main/scala/edu/ie3/simona/io/runtime/RuntimeEventLogSink.scala @@ -14,6 +14,7 @@ import edu.ie3.util.TimeUtil import org.slf4j.Logger import java.time.ZonedDateTime +import scala.concurrent.duration.DurationLong /** Runtime event sink that just logs all received events. * @@ -26,6 +27,7 @@ import java.time.ZonedDateTime final case class RuntimeEventLogSink( simulationStartDate: ZonedDateTime, log: Logger, + private var last: Long = 0L, ) extends RuntimeEventSink { override def handleRuntimeEvent( @@ -43,13 +45,15 @@ final case class RuntimeEventLogSink( case CheckWindowPassed(tick, duration) => log.info( - s"******* Simulation until ${calcTime(tick)} completed. ${durationAndMemoryString(duration)} ******" + s"******* Simulation until ${calcTime(tick)} completed. ${durationAndMemoryString(duration - last)} ******" ) + last = duration case Ready(tick, duration) => log.info( - s"******* Switched from 'Simulating' to 'Ready'. Last simulated time: ${calcTime(tick)}. ${durationAndMemoryString(duration)} ******" + s"******* Switched from 'Simulating' to 'Ready'. Last simulated time: ${calcTime(tick)}. ${durationAndMemoryString(duration - last)} ******" ) + last = duration case Simulating(startTick, endTick) => log.info( @@ -84,12 +88,14 @@ final case class RuntimeEventLogSink( } private def convertDuration(duration: Long): String = { - val durationInSeconds = duration / 1000 - - val hours = durationInSeconds / 3600 - val minutes = (durationInSeconds / 60) % 60 - val seconds = durationInSeconds % 60 - s"${hours}h : ${minutes}m : ${seconds}s" + val time = duration.milliseconds + + val hours = time.toHours + val minutes = time.toMinutes % 60 + val seconds = time.toSeconds % 60 + val milliseconds = + (time - hours.hours - minutes.minutes - seconds.seconds).toMillis + s"${hours}h : ${minutes}m : ${seconds}s : ${milliseconds}ms" } private def durationAndMemoryString(duration: Long) = { diff --git a/src/test/scala/edu/ie3/simona/event/listener/RuntimeEventListenerLoggingSpec.scala b/src/test/scala/edu/ie3/simona/event/listener/RuntimeEventListenerLoggingSpec.scala index 714a698baa..4e37001c11 100644 --- a/src/test/scala/edu/ie3/simona/event/listener/RuntimeEventListenerLoggingSpec.scala +++ b/src/test/scala/edu/ie3/simona/event/listener/RuntimeEventListenerLoggingSpec.scala @@ -78,7 +78,7 @@ class RuntimeEventListenerLoggingSpec ( InitComplete(0L), Level.INFO, - s"Initialization complete. (duration: 0h : 0m : 0s )", + s"Initialization complete. (duration: 0h : 0m : 0s : 0ms )", ), ( Ready(currentTick, 0L),