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

Included previousResults in BaseData. Adapted handleResult function in a way that results are only updated when changes occur. #519

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Speeding up additionalActivationTicks in participant's BaseStateData [#421](https://github.com/ie3-institute/simona/pull/421)
- Changed format of example grid `vn_simona` [#216](https://github.com/ie3-institute/simona/issues/216)
- Renamed ChpData to ChpRelevantData [#494](https://github.com/ie3-institute/simona/issues/494)
- Changed handleResult function so that results are only updated if changes occur [#487](https://github.com/ie3-institute/simona/issues/487)

### Fixed
- Location of `vn_simona` test grid (was partially in Berlin and Dortmund) [#72](https://github.com/ie3-institute/simona/issues/72)
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ dependencies {
implementation "com.sksamuel.avro4s:avro4s-core_${scalaVersion}:4.1.1"

implementation 'org.apache.commons:commons-math3:3.6.1' // apache commons math3
implementation 'org.apache.commons:commons-lang3:3.12.0' // apache commons lang3 FIXME Temporarily used for cloning
implementation 'org.apache.poi:poi-ooxml:5.2.3' // used for FilenameUtils
implementation 'javax.measure:unit-api:2.1.3'
implementation 'tech.units:indriya:2.1.4' // quantities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import edu.ie3.simona.io.result._
import edu.ie3.simona.logging.SimonaFSMActorLogging
import edu.ie3.simona.ontology.messages.StopMessage
import edu.ie3.simona.util.ResultFileHierarchy
import org.apache.commons.lang3.SerializationUtils
import sourcecode.Text.generate

import java.util.UUID
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.DurationInt
import scala.concurrent.{Await, Future}
Expand Down Expand Up @@ -64,13 +67,16 @@ object ResultEventListener extends Transformer3wResultSupport {
* @param classToSink
* a map containing the sink for each class that should be processed by the
* listener
* @param previousResults
* a map containing only the previous results
*/
private final case class BaseData(
classToSink: Map[Class[_], ResultEntitySink],
threeWindingResults: Map[
Transformer3wKey,
AggregatedTransformer3wResult
] = Map.empty
] = Map.empty,
previousResults: Map[UUID, ResultEntity] = Map.empty
) extends ResultEventListenerData

def props(
Expand Down Expand Up @@ -190,7 +196,11 @@ class ResultEventListener(
self ! Init
}

/** Handle the given result and possibly update the state data
/** Handle the given result and possibly update the state data The state data
* is compared to the previous corresponding data. Both maps are only updated
* if the state data has changed. Before comparing both maps, previous
* results are cloned and the time is adapted to the corresponding time in
* the state data.
*
* @param resultEntity
* Result entity to handle
Expand All @@ -203,8 +213,21 @@ class ResultEventListener(
resultEntity: ResultEntity,
baseData: BaseData
): BaseData = {
handOverToSink(resultEntity, baseData.classToSink)
baseData
val previousResult = baseData.previousResults.get(resultEntity.getUuid)
val previousResultClone = previousResult.map { previousResult =>
val resultEntityClone = SerializationUtils.clone(previousResult)
resultEntityClone.setTime(resultEntity.getTime)
resultEntityClone
}
if (previousResultClone.exists(_.equals(resultEntity))) {
baseData
} else {
val updatedPreviousResults =
baseData.previousResults + (resultEntity.getUuid -> SerializationUtils
.clone(resultEntity))
handOverToSink(resultEntity, baseData.classToSink)
baseData.copy(previousResults = updatedPreviousResults)
}
}

/** Handle a partial three winding result properly by adding it to an
Expand Down