Skip to content

Commit

Permalink
Merge branch 'dev' into sp/#24-kafka-result-output
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-peter committed Jan 21, 2022
2 parents 77ad357 + c5566e9 commit 59256f8
Show file tree
Hide file tree
Showing 16 changed files with 412 additions and 374 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ updates:
- johanneshiry
- t-ober
- sensarmad
ignore:
- dependency-name: org.spockframework:spock-core
versions:
- 2.1-groovy-3.0-SNAPSHOT
- 2.1-groovy-2.5-SNAPSHOT
- dependency-name: org.scalatest:scalatest_2.13
versions:
- 3.3.0-SNAP+
- dependency-name: org.scalatestplus:mockito-3-4_2.13
versions:
- 3.3.0.0-SNAP+
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Improving code readability in EvcsAgent by moving FreeLotsRequest to separate methods

### Fixed
- Location of `vn_simona` test grid (was partially in Berlin and Dortmund)

[Unreleased]: https://github.com/ie3-institute/simona/compare/a14a093239f58fca9b2b974712686b33e5e5f939...HEAD
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ plugins {
id 'signing'
id 'maven-publish' // publish to a maven repo (local or mvn central, has to be defined)
id 'pmd' // code check, working on source code
id 'com.diffplug.spotless' version '6.1.2'// code format
id 'com.diffplug.spotless' version '6.2.0'// code format
id 'com.github.onslip.gradle-one-jar' version '1.0.6' // pack a self contained jar
id "com.github.ben-manes.versions" version '0.40.0'
id "com.github.ben-manes.versions" version '0.41.0'
id "de.undercouch.download" version "4.1.2" // downloads plugin
id "kr.motd.sphinx" version "2.10.1" // documentation generation
id "com.github.johnrengelman.shadow" version "7.1.2" // fat jar
Expand All @@ -27,7 +27,7 @@ ext {
scalaVersion = '2.13'
scalaBinaryVersion = '2.13.7'
akkaVersion = '2.6.18'
tscfgVersion = '0.9.996'
tscfgVersion = '0.9.997'

scriptsLocation = 'gradle' + File.separator + 'scripts' + File.separator // location of script plugins
}
Expand Down Expand Up @@ -94,7 +94,7 @@ dependencies {

/* testing */
testImplementation 'org.spockframework:spock-core:2.1-M2-groovy-3.0'
testImplementation 'org.scalatestplus:mockito-3-4_2.13:3.2.9.0'
testImplementation 'org.scalatestplus:mockito-3-4_2.13:3.2.10.0'
implementation 'org.mockito:mockito-core:4.2.0' // mocking framework
testImplementation "org.scalatest:scalatest_${scalaVersion}:3.2.10"
testRuntimeClasspath 'com.vladsch.flexmark:flexmark-all:0.62.2'
Expand All @@ -109,7 +109,7 @@ dependencies {
implementation "com.typesafe.akka:akka-actor_${scalaVersion}:${akkaVersion}"
implementation "com.typesafe.akka:akka-slf4j_${scalaVersion}:${akkaVersion}"
implementation "com.typesafe.akka:akka-cluster_${scalaVersion}:${akkaVersion}"
implementation "com.lightbend.akka:akka-stream-alpakka-csv_${scalaVersion}:1.1.2"
implementation "com.lightbend.akka:akka-stream-alpakka-csv_${scalaVersion}:3.0.4"
implementation "com.typesafe.akka:akka-actor_${scalaVersion}:${akkaVersion}"
implementation "com.typesafe.akka:akka-cluster-sharding_${scalaVersion}:${akkaVersion}"
implementation "com.typesafe.akka:akka-cluster-tools_${scalaVersion}:${akkaVersion}"
Expand All @@ -126,7 +126,7 @@ dependencies {
implementation 'org.locationtech.jts.io:jts-io-common:1.18.2'

/* Scala compiler plugin for static code analysis */
implementation "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}:1.4.11"
implementation "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}:1.4.12"
scalaCompilerPlugin "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}:1.4.11"

/* Kafka */
Expand All @@ -136,7 +136,7 @@ dependencies {
testImplementation 'org.testcontainers:kafka:1.16.2' // kafka testing

implementation 'org.apache.commons:commons-math3:3.6.1' // apache commons math3
implementation 'org.apache.poi:poi-ooxml:5.1.0' // used for FilenameUtils
implementation 'org.apache.poi:poi-ooxml:5.2.0' // used for FilenameUtils
implementation 'javax.measure:unit-api:2.1.3'
implementation 'tech.units:indriya:2.1.2' // quantities
implementation 'org.apache.commons:commons-csv:1.9.0'
Expand Down
320 changes: 160 additions & 160 deletions input/samples/vn_simona/fullGrid/line_input.csv

Large diffs are not rendered by default.

208 changes: 104 additions & 104 deletions input/samples/vn_simona/fullGrid/node_input.csv

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/main/scala/edu/ie3/simona/agent/ValueStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ final case class ValueStore[+D](
*/
def last(requestedTick: Long): Option[(Long, D)] =
store
.filter(entry => entry._1 <= requestedTick)
.maxByOption(entry => entry._1)
.filter(_._1 <= requestedTick)
.maxByOption(_._1)

/** Get the last known entry (with the highest tick)
*
* @return
* An Option to the last entry
*/
def last(): Option[(Long, D)] =
store.maxByOption(_._1)

/** Acquires the stored information within the specified tick window
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{
}
import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService
import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorEvMovementsService
import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData
import edu.ie3.simona.agent.participant.statedata.ParticipantStateData
import edu.ie3.simona.agent.state.AgentState.Idle
import edu.ie3.simona.config.SimonaConfig.EvcsRuntimeConfig
import edu.ie3.simona.model.participant.EvcsModel
import edu.ie3.simona.model.participant.EvcsModel.EvcsRelevantData
import edu.ie3.simona.ontology.messages.services.EvMessage.EvFreeLotsRequest
import tech.units.indriya.ComparableQuantity

import javax.measure.quantity.Power
Expand Down Expand Up @@ -57,6 +60,19 @@ class EvcsAgent(
with EvcsAgentFundamentals {
override val alternativeResult: ApparentPower = ZERO_POWER

when(Idle) {
case Event(
EvFreeLotsRequest(tick),
modelBaseStateData: ParticipantModelBaseStateData[
ApparentPower,
EvcsRelevantData,
EvcsModel
]
) =>
handleFreeLotsRequest(tick, modelBaseStateData)
stay()
}

/** Determine the average result within the given tick window
*
* @param tickToResults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import edu.ie3.simona.model.participant.EvcsModel
import edu.ie3.simona.model.participant.EvcsModel.EvcsRelevantData
import edu.ie3.simona.ontology.messages.services.EvMessage.{
DepartedEvsResponse,
EvFreeLotsRequest,
EvMovementData,
FreeLotsResponse
}
Expand Down Expand Up @@ -264,12 +263,6 @@ protected trait EvcsAgentFundamentals
modelBaseStateData,
evcsData
)
case (_, Some(EvFreeLotsRequest)) =>
handleFreeLotsRequestAndGoIdle(
currentTick,
scheduler,
modelBaseStateData
)
}
.getOrElse(
throw new InconsistentStateException(
Expand All @@ -285,44 +278,33 @@ protected trait EvcsAgentFundamentals
}

/** Returns the number of free parking lots based on the last available state
* data. Sends completion message to scheduler without scheduling new
* activations.
* @param currentTick
* The current tick that has been triggered
* @param scheduler
* The scheduler ref
* data.
* @param tick
* The tick that free lots have been requested for
* @param modelBaseStateData
* The state data
* @return
* [[Idle]] state
*/
private def handleFreeLotsRequestAndGoIdle(
currentTick: Long,
scheduler: ActorRef,
protected def handleFreeLotsRequest(
tick: Long,
modelBaseStateData: ParticipantModelBaseStateData[
_ <: ApparentPower,
_,
_
]
): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = {
): Unit = {
val evServiceRef = getService[ActorEvMovementsService](
modelBaseStateData.services
)

val (_, lastEvs) =
getTickIntervalAndLastEvs(currentTick, modelBaseStateData)
getTickIntervalAndLastEvs(tick, modelBaseStateData)

val evcsModel = getEvcsModel(modelBaseStateData)

evServiceRef ! FreeLotsResponse(
evcsModel.uuid,
evcsModel.chargingPoints - lastEvs.size
)

goToIdleReplyCompletionAndScheduleTriggerForNextAction(
modelBaseStateData,
scheduler
)
}

/** Handles a evcs movements message that contains information on arriving and
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/edu/ie3/simona/api/ExtMessageUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ object ExtMessageUtils {
) {
def toSimona(triggerId: Long, triggerActor: ActorRef): CompletionMessage = {
val newTriggers =
Option.when(!extCompl.getNewTriggers.isEmpty) {
extCompl.getNewTriggers.asScala.map { tick =>
Option.when(!extCompl.newTriggers.isEmpty) {
extCompl.newTriggers.asScala.map { tick =>
ScheduleTriggerMessage(ActivityStartTrigger(tick), triggerActor)
}.toSeq
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ object EvMessage {
) extends EvMessage
with ProvisionMessage[EvData]

final case object EvFreeLotsRequest extends EvData
/** Requests number of free lots from evcs
* @param tick
* The latest tick that the data is requested for
*/
final case class EvFreeLotsRequest(
tick: Long
)

/** Hold EV movements for one Evcs
*
Expand Down
22 changes: 6 additions & 16 deletions src/main/scala/edu/ie3/simona/service/ev/ExtEvDataService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import edu.ie3.simona.api.data.ev.ontology.{
RequestEvcsFreeLots
}
import edu.ie3.simona.api.data.ontology.ExtDataMessage
import edu.ie3.simona.exceptions.InitializationException
import edu.ie3.simona.exceptions.{InitializationException, ServiceException}
import edu.ie3.simona.exceptions.WeatherServiceException.InvalidRegistrationRequestException
import edu.ie3.simona.ontology.messages.SchedulerMessage
import edu.ie3.simona.ontology.messages.SchedulerMessage.ScheduleTriggerMessage
Expand Down Expand Up @@ -186,7 +186,7 @@ class ExtEvDataService(override val scheduler: ActorRef)
Option[Seq[SchedulerMessage.ScheduleTriggerMessage]]
) = {
serviceStateData.extEvMessage.getOrElse(
throw new RuntimeException(
throw ServiceException(
"ExtEvDataActor was triggered without ExtEvMessage available"
)
) match {
Expand All @@ -200,19 +200,9 @@ class ExtEvDataService(override val scheduler: ActorRef)
private def requestFreeLots(tick: Long)(implicit
serviceStateData: ExtEvStateData
): (ExtEvStateData, Option[Seq[ScheduleTriggerMessage]]) = {
val scheduleTriggerMsgs =
serviceStateData.uuidToActorRef.map { case (_, evcsActor) =>
evcsActor ! ProvideEvDataMessage(
tick,
EvFreeLotsRequest
)

// schedule activation of participant
ScheduleTriggerMessage(
ActivityStartTrigger(tick),
evcsActor
)
}
serviceStateData.uuidToActorRef.foreach { case (_, evcsActor) =>
evcsActor ! EvFreeLotsRequest(tick)
}

val freeLots: Map[UUID, Option[Int]] =
serviceStateData.uuidToActorRef.map { case (evcs, _) =>
Expand All @@ -228,7 +218,7 @@ class ExtEvDataService(override val scheduler: ActorRef)
extEvMessage = None,
freeLots = freeLots
),
Option.when(scheduleTriggerMsgs.nonEmpty)(scheduleTriggerMsgs.toSeq)
None
)
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/edu/ie3/simona/sim/setup/ExtSimLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ object ExtSimLoader extends LazyLogging {
name.substring(name.lastIndexOf('.') + 1).toLowerCase
)
}
.toIterable
}

def loadExtLink(myJar: File): ExtLinkInterface = {
Expand All @@ -59,7 +58,7 @@ object ExtSimLoader extends LazyLogging {
this.getClass.getClassLoader
)
val classToLoad = Class.forName(extLinkClassPath, true, classLoader)
classToLoad.newInstance match {
classToLoad.getDeclaredConstructor().newInstance() match {
case extSim: ExtLinkInterface =>
extSim
case other =>
Expand Down
8 changes: 8 additions & 0 deletions src/test/scala/edu/ie3/simona/agent/ValueStoreSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class ValueStoreSpec extends UnitSpec with PrivateMethodTester {
emptyValueStore.last(100L) shouldBe None
}

"return None on request of the overall last known entry" in {
emptyValueStore.last() shouldBe None
}

"return an empty map on request of tick window" in {
emptyValueStore.get(50L, 100L) shouldBe Map
.empty[Long, String]
Expand Down Expand Up @@ -61,6 +65,10 @@ class ValueStoreSpec extends UnitSpec with PrivateMethodTester {
filledValueStore.last(100L) shouldBe Some((4L, "Four"))
}

"return (4L, \"Four\") on request of the overall last known entry" in {
filledValueStore.last() shouldBe Some((4L, "Four"))
}

"return an empty map on request of tick window" in {
filledValueStore.get(2L, 3L) shouldBe Map(
2L -> "Two",
Expand Down
Loading

0 comments on commit 59256f8

Please sign in to comment.