Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/df/#924-ThermalStor…
Browse files Browse the repository at this point in the history
…ageResults-have-multiple-entries' into df/tmpHPmergeall

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
danielfeismann committed Aug 24, 2024
2 parents baabf85 + 37bc66a commit 7659750
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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)
- Handle MobSim requests for current prices [#892](https://github.com/ie3-institute/simona/issues/892)
- Fixed ThermalStorageResults having multiple entries [#924](https://github.com/ie3-institute/simona/issues/924)
- Fix determineState of ThermalHouse [#926](https://github.com/ie3-institute/simona/issues/926)

## [3.0.0] - 2023-08-07
Expand Down
42 changes: 40 additions & 2 deletions src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,44 @@ final case class ThermalGrid(
def results(
state: ThermalGridState
)(implicit startDateTime: ZonedDateTime): Seq[ResultEntity] = {
/* FIXME: We only want to write results when there is a change within the participant.
* At the moment we write an storage result when the house result gets updated and vice versa.
* */

val houseResultTick: Option[Long] = house
.zip(state.houseState)
.headOption
.flatMap {
case (
thermalHouse,
ThermalHouseState(tick, _, _),
) =>
Some(tick)
case _ => None
}

val storageResultTick: Option[Long] = storage
.zip(state.storageState)
.headOption
.flatMap {
case (
thermalStorage,
ThermalStorageState(tick, _, _),
) =>
Some(tick)
case _ => None
}

val actualResultTick: Long = (houseResultTick, storageResultTick) match {
case (Some(hTick), Some(sTick)) => math.max(hTick, sTick)
case (Some(hTick), None) => hTick
case (None, Some(sTick)) => sTick
case (None, None) =>
throw new RuntimeException(
"ThermalGrid result should be carried out but it was not possible to get the tick for the result"
)
}

val houseResults = house
.zip(state.houseState)
.map {
Expand All @@ -417,7 +455,7 @@ final case class ThermalGrid(
ThermalHouseState(tick, innerTemperature, thermalInfeed),
) =>
Seq.empty[ResultEntity] :+ new ThermalHouseResult(
tick.toDateTime,
actualResultTick.toDateTime,
thermalHouse.uuid,
thermalInfeed.toMegawatts.asMegaWatt,
innerTemperature.toKelvinScale.asKelvin,
Expand All @@ -433,7 +471,7 @@ final case class ThermalGrid(
ThermalStorageState(tick, storedEnergy, qDot),
) =>
houseResults :+ new CylindricalStorageResult(
tick.toDateTime,
actualResultTick.toDateTime,
storage.uuid,
storedEnergy.toMegawattHours.asMegaWattHour,
qDot.toMegawatts.asMegaWatt,
Expand Down

0 comments on commit 7659750

Please sign in to comment.