From 9c1334afcb83bf7d6949613b5c03ac947ba8afa4 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Thu, 19 Sep 2024 16:24:39 +0200 Subject: [PATCH] rollback change to fallback to latest weatherData --- .../participant/hp/HpAgentFundamentals.scala | 43 ++++++------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala index 1c360e0451..a5a8578e9a 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala @@ -407,44 +407,25 @@ trait HpAgentFundamentals tick: Long, ): HpRelevantData = { /* extract weather data from secondary data, which should have been requested and received before */ - val weatherData = { - val currentWeatherData = baseStateData.receivedSecondaryDataStore + val weatherData = + baseStateData.receivedSecondaryDataStore .last(tick) .flatMap { case (receivedTick, receivedValues) => - if (receivedTick == tick) { - receivedValues.collectFirst { case (_, data: WeatherData) => - data - } - } else None - } - - // If current weather data is not found, fallback to the latest entry where the map is not empty - currentWeatherData - .orElse { - val latestEntry = - baseStateData.receivedSecondaryDataStore.store.toSeq.findLast { - case (_, receivedValues) => receivedValues.nonEmpty - } - - latestEntry.flatMap { case (receivedTick, receivedValues) => - if (tick - receivedTick > 3600) { - log.warning( - s"The model ${baseStateData.model.getUuid} is using weather data from tick $receivedTick, " + - s"but there is a discrepancy of ${tick - receivedTick} seconds compared to the current tick $tick." - ) - } - - receivedValues.collectFirst { case (_, data: WeatherData) => - data - } + if (receivedTick != tick) + log.debug( + s"The model ${baseStateData.model.getUuid} needs to do calculations with values received " + + s"in tick $receivedTick, as no weather data has been received in tick $tick." + ) + receivedValues.collectFirst { + // filter secondary data for weather data + case (_, data: WeatherData) => data } } - .getOrElse { + .getOrElse( throw new InconsistentStateException( s"The model ${baseStateData.model} was not provided with needed weather data." ) - } - } + ) HpRelevantData( tick,