Skip to content

Commit

Permalink
Merge branch 'dev' into df/#878-thermalGridIT
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
danielfeismann committed Nov 19, 2024
2 parents 0d40632 + c2def29 commit 05bebe4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed `CHANGELOG` entry for issue ([#103](https://github.com/ie3-institute/simona/issues/103)) [#941](https://github.com/ie3-institute/simona/issues/941)
- Fix grammar and spelling in docs and comments [#1022](https://github.com/ie3-institute/simona/issues/1022)
- Fix some minor issues and findings from inspections [#1019](https://github.com/ie3-institute/simona/issues/1019)
- Fix initialisation freezing on empty primary data [#981](https://github.com/ie3-institute/simona/issues/981)
- Refactoring of `ThermalGrid.handleInfeed` to fix thermal storage recharge correctly when empty [#930](https://github.com/ie3-institute/simona/issues/930)

## [3.0.0] - 2023-08-07
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ protected trait ParticipantAgentFundamentals[

/* Confirm final initialization */
releaseTick()
senderToMaybeTick._2.foreach { tick =>
scheduler ! Completion(self.toTyped, Some(tick))
}
scheduler ! Completion(self.toTyped, senderToMaybeTick._2)

goto(Idle) using stateData
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import edu.ie3.simona.agent.participant.data.Data.PrimaryData.RichValue
import edu.ie3.simona.config.SimonaConfig.Simona.Input.Primary.SqlParams
import edu.ie3.simona.exceptions.InitializationException
import edu.ie3.simona.exceptions.WeatherServiceException.InvalidRegistrationRequestException
import edu.ie3.simona.exceptions.agent.ServiceRegistrationException
import edu.ie3.simona.ontology.messages.services.ServiceMessage
import edu.ie3.simona.ontology.messages.services.ServiceMessage.RegistrationResponseMessage.RegistrationSuccessfulMessage
import edu.ie3.simona.service.ServiceStateData.{
Expand Down Expand Up @@ -131,32 +132,47 @@ final case class PrimaryServiceWorker[V <: Value](
s"Provided init data '${unsupported.getClass.getSimpleName}' for primary service are invalid!"
)
)
}).map { case (source, simulationStart) =>
}).flatMap { case (source, simulationStart) =>
implicit val startDateTime: ZonedDateTime = simulationStart

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

/* Set up the state data and determine the next activation tick. */
val initializedStateData =
PrimaryServiceInitializedStateData(
maybeNextTick,
furtherActivationTicks,
simulationStart,
source,
)
(initializedStateData, maybeNextTick)
(maybeNextTick, furtherActivationTicks) match {
case (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)

case (Some(tick), _) if tick > 0L =>
/* The start of the data needs to be at the first tick of the simulation. */
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!"
)
)

case _ =>
/* No data for the simulation. */
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

0 comments on commit 05bebe4

Please sign in to comment.