Skip to content

Commit

Permalink
Merge branch 'sp/#000-em-combined' into sp/#339-em-it
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-peter committed Oct 19, 2022
2 parents 15aa35f + 2c7df1b commit 5909e38
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed deprecations from `CsvGridSource` and added `TestGridFactory` [#304](https://github.com/ie3-institute/simona/issues/304)
- Fixed config of vn_146_lv_small [#290](https://github.com/ie3-institute/simona/issues/290)
- Adapted to changes of EvcsInput in PSDM [#377](https://github.com/ie3-institute/simona/pull/377)
- Fix breaking SIMONA caused by changes in simonaAPI [#384] (https://github.com/ie3-institute/simona/issues/384)

### Removed
- Remove workaround for tscfg tmp directory [#178](https://github.com/ie3-institute/simona/issues/178)
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ plugins {
id 'pmd' // code check, working on source code
id 'com.diffplug.spotless' version '6.11.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.42.0'
id "de.undercouch.download" version "5.2.1" // downloads plugin
id "com.github.ben-manes.versions" version '0.43.0'
id "de.undercouch.download" version "5.3.0" // downloads plugin
id "kr.motd.sphinx" version "2.10.1" // documentation generation
id "com.github.johnrengelman.shadow" version "7.1.2" // fat jar
id "org.sonarqube" version "3.4.0.2513" // sonarqube
Expand Down
68 changes: 55 additions & 13 deletions src/main/scala/edu/ie3/simona/agent/participant/em/EmAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,47 @@ class EmAgent(

private val handleIdleEm: StateFunction = {
case Event(
triggerToSchedule: ScheduleTriggerMessage,
scheduleTriggerMessage: ScheduleTriggerMessage,
baseStateData: EmModelBaseStateData
) =>
val nextScheduledTickOpt = getNextScheduledTick(
baseStateData.schedulerStateData
)
createNextTriggerIfApplicable(
baseStateData.schedulerStateData,
scheduleTriggerMessage.trigger.tick
) foreach (scheduler ! _)

// FIXME it'd be better if we also revoked the "last next tick", because that one could also be revoked before it is reached
nextScheduledTickOpt.foreach { nextScheduledTick =>
if (triggerToSchedule.trigger.tick < nextScheduledTick) {
// we need to schedule an activation for the trigger tick
scheduler ! ScheduleTriggerMessage(
ActivityStartTrigger(triggerToSchedule.trigger.tick),
self
stay() using
baseStateData.copy(schedulerStateData =
sendEligibleTrigger(
scheduleTrigger(
scheduleTriggerMessage,
baseStateData.schedulerStateData
)
)
}
)

case Event(
TriggerWithIdMessage(
scheduleTriggerMessage: ScheduleTriggerMessage,
triggerId,
_
),
baseStateData: EmModelBaseStateData
) =>
createNextTriggerIfApplicable(
baseStateData.schedulerStateData,
scheduleTriggerMessage.trigger.tick
) foreach { stm =>
// since we've been sent a trigger, we need to complete it as well
scheduler ! CompletionMessage(triggerId, Some(Seq(stm)))
}

stay() using
baseStateData.copy(schedulerStateData =
sendEligibleTrigger(
scheduleTrigger(triggerToSchedule, baseStateData.schedulerStateData)
scheduleTrigger(
scheduleTriggerMessage,
baseStateData.schedulerStateData
)
)
)

Expand Down Expand Up @@ -492,6 +511,29 @@ class EmAgent(
)
}

protected def createNextTriggerIfApplicable(
schedulerStateData: EmSchedulerStateData,
newTick: Long
): Option[ScheduleTriggerMessage] = {
// FIXME it'd be better if we also revoked the former next tick, because that one could also be revoked before it is reached

val isCurrentlyInactive = schedulerStateData.mainTriggerId.isEmpty

// this defaults to true if no next tick is scheduled
val scheduleNextTrigger = getNextScheduledTick(
schedulerStateData
).forall { nextScheduledTick =>
newTick < nextScheduledTick
}

Option.when(isCurrentlyInactive && scheduleNextTrigger) {
ScheduleTriggerMessage(
ActivityStartTrigger(newTick),
self
)
}
}

private def maybeIssueFlexControl(
baseStateData: EmModelBaseStateData
): State = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ object SchedulerMessage {
priority: Boolean = false
) extends SchedulerMessage
with Trigger {
// FIXME this currently only works as intended for triggers scheduled for the current tick
override def tick: Long = trigger.tick
}

Expand Down

0 comments on commit 5909e38

Please sign in to comment.