Skip to content

Commit

Permalink
Merge pull request #875 from ie3-institute/ms/#801-fixing-duration-ca…
Browse files Browse the repository at this point in the history
…lculation-in-result-events

Fixing duration calculation in result events.
  • Loading branch information
danielfeismann authored Aug 1, 2024
2 parents 288aab2 + 76be5d3 commit f6ea63f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 14 additions & 8 deletions src/main/scala/edu/ie3/simona/io/runtime/RuntimeEventLogSink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit f6ea63f

Please sign in to comment.