Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix initialisation freezing on empty primary data. #1016

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix CheckWindow duration [#921](https://github.com/ie3-institute/simona/issues/921)
- Fixed ThermalStorageResults having multiple entries [#924](https://github.com/ie3-institute/simona/issues/924)
- Fix filter for thermal result checking for lastTick not for currentTick [#1008](https://github.com/ie3-institute/simona/issues/1008)
- Fix initialisation freezing on empty primary data [#1014](https://github.com/ie3-institute/simona/issues/1014)
- Fix initialisation freezing on empty primary data [#981](https://github.com/ie3-institute/simona/issues/981)

## [3.0.0] - 2023-08-07

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,35 +138,41 @@ final case class PrimaryServiceWorker[V <: Value](
val (maybeNextTick, furtherActivationTicks) = SortedDistinctSeq(
// Note: The whole data set is used here, which might be inefficient depending on the source implementation.
source.getTimeSeries.getEntries.asScala
.filter { timeBasedValue =>
val dateTime = timeBasedValue.getTime
dateTime.isEqual(simulationStart) || dateTime.isAfter(
simulationStart
)
}
.map(timeBasedValue => timeBasedValue.getTime.toTick)
.filter(_ >= 0L)
.toSeq
.sorted
).pop

if (maybeNextTick.nonEmpty) {
(maybeNextTick, furtherActivationTicks) match {
case (maybeNextTick @ Some(tick), furtherActivationTicks)
if tick == 0L =>
/* Set up the state data and determine the next activation tick. */
val initializedStateData =
PrimaryServiceInitializedStateData(
maybeNextTick,
furtherActivationTicks,
simulationStart,
source,
)

Success(initializedStateData, maybeNextTick)

/* Set up the state data and determine the next activation tick. */
val initializedStateData =
PrimaryServiceInitializedStateData(
maybeNextTick,
furtherActivationTicks,
simulationStart,
source,
case (Some(tick), _) if tick > 0L =>
/* The start of the data needs to be at the first tick of the simulation or before. */
staudtMarius marked this conversation as resolved.
Show resolved Hide resolved
Failure(
new ServiceRegistrationException(
s"The data for the timeseries '${source.getTimeSeries.getUuid}' starts after the start of this simulation (tick: $tick)! This is not allowed!"
)
)

Success(initializedStateData, maybeNextTick)
} else
Failure(
new ServiceRegistrationException(
s"No appropriate data found within simulation time range in timeseries ${source.getTimeSeries.getUuid}!"
case _ =>
Failure(
new ServiceRegistrationException(
s"No appropriate data found within simulation time range in timeseries '${source.getTimeSeries.getUuid}'!"
)
)
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,32 @@ class PrimaryServiceWorkerSpec
}
}

"fail to init, if time series ends with delay before simulation start" in {
val initData = validInitData.copy(
simulationStart = validInitData.simulationStart.plusHours(1)
)

service.init(initData) match {
case Failure(exception) =>
exception.getMessage shouldBe "No appropriate data found within simulation time range in timeseries '9185b8c1-86ba-4a16-8dea-5ac898e8caa5'!"
case Success(_) =>
fail("Initialisation with unsupported init data is meant to fail.")
}
}

"fail to init, if time series starts with delay after simulation start" in {
val initData = validInitData.copy(
simulationStart = validInitData.simulationStart.minusHours(1)
)

service.init(initData) match {
case Failure(exception) =>
exception.getMessage shouldBe "The data for the timeseries '9185b8c1-86ba-4a16-8dea-5ac898e8caa5' starts after the start of this simulation (tick: 3600)! This is not allowed!"
case Success(_) =>
fail("Initialisation with unsupported init data is meant to fail.")
}
}

"fail, if pointed to the wrong file" in {
// time series exists, but is malformed
val tsUuid = UUID.fromString("3fbfaa97-cff4-46d4-95ba-a95665e87c27")
Expand Down