Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into jb/#671-externaldatase…
Browse files Browse the repository at this point in the history
…rvice

# Conflicts:
#	build.gradle
#	src/main/scala/edu/ie3/simona/event/listener/ResultEventListener.scala
#	src/main/scala/edu/ie3/simona/ontology/messages/services/ServiceMessage.scala
#	src/main/scala/edu/ie3/simona/service/ev/ExtEvDataService.scala
#	src/main/scala/edu/ie3/simona/service/primary/PrimaryServiceProxy.scala
#	src/main/scala/edu/ie3/simona/sim/SimonaSim.scala
#	src/main/scala/edu/ie3/simona/sim/setup/SimonaSetup.scala
#	src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala
#	src/test/scala/edu/ie3/simona/service/primary/PrimaryServiceProxySpec.scala
#	src/test/scala/edu/ie3/simona/service/primary/PrimaryServiceProxySqlIT.scala
#	src/test/scala/edu/ie3/simona/sim/SimonaSimFailSpec.scala
#	src/test/scala/edu/ie3/simona/sim/setup/SimonaSetupSpec.scala
  • Loading branch information
jo-bao committed Feb 21, 2024
2 parents 16c485c + 1e443bf commit 223c8a2
Show file tree
Hide file tree
Showing 319 changed files with 15,375 additions and 8,659 deletions.
4 changes: 4 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = 3.7.3
runner.dialect = scala213

rewrite.trailingCommas.style = multiple
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Instantiation of Heat Pump Agents [#253](https://github.com/ie3-institute/simona/issues/253)
- Output of accompanying thermal result models
- Added JDK installation, Scala Plugin + SDK in usersguide [#324](https://github.com/ie3-institute/simona/issues/324)
- Squants scalatest matchers [#715](https://github.com/ie3-institute/simona/issues/715)
- Energy Management capabilities:
- Added capability of SystemParticipants to handle flexibility [#308](https://github.com/ie3-institute/simona/issues/308)
- Added smart charging logic [#31](https://github.com/ie3-institute/simona/issues/31) and flex calculation in `EvcsAgent` [#332](https://github.com/ie3-institute/simona/issues/332)
- Enhance output quotes of `RunSimona` [#743](https://github.com/ie3-institute/simona/issues/743)

### Changed
- Adapted to changed data source in PSDM [#435](https://github.com/ie3-institute/simona/issues/435)
Expand All @@ -26,13 +31,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adapting to simonaAPI 0.3.0 (adapted message protocol)
- Schedule lock [#651](https://github.com/ie3-institute/simona/issues/651)
- New scheduling protocol [#650](https://github.com/ie3-institute/simona/issues/650)
- Small improvements to the code [#696](https://github.com/ie3-institute/simona/issues/696)
- Replaced akka with pekko [#641](https://github.com/ie3-institute/simona/issues/641)
- Use `ThermalGrid` to calculate thermal environment of a heat pump [#315](https://github.com/ie3-institute/simona/issues/315)
- Enable windows path as config parameters [#549](https://github.com/ie3-institute/simona/issues/549)
- Unified consideration of scaling factor when simulating system participants [#81](https://github.com/ie3-institute/simona/issues/81)
- Small improvements in `ResultEventListener` [#738](https://github.com/ie3-institute/simona/issues/738)

### Fixed
- Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658)
- Removed version number "2.0" from the logo printed to console [#642](https://github.com/ie3-institute/simona/issues/642)
- Fixed PV Model documentation [#684](https://github.com/ie3-institute/simona/issues/684), [#686](https://github.com/ie3-institute/simona/issues/686)
- Removed `CsvDataSourceAdapter` workaround [#702](https://github.com/ie3-institute/simona/issues/702)
- Logging wrong duration in the first simulation hour [#705](https://github.com/ie3-institute/simona/issues/705)
- Fixed some compiler warnings [#657](https://github.com/ie3-institute/simona/issues/657)
- Fixing false negative in ref system voltage validation [#706](https://github.com/ie3-institute/simona/issues/706)
- Fixing randomly failing test in `RuntimeEventListenerSpec` etc. [#709](https://github.com/ie3-institute/simona/issues/709)

## [3.0.0] - 2023-08-07

Expand Down
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ 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.24.0'// code format
id "com.github.ben-manes.versions" version '0.50.0'
id 'com.diffplug.spotless' version '6.25.0'// code format
id "com.github.ben-manes.versions" version '0.51.0'
id "de.undercouch.download" version "5.5.0" // downloads plugin
id "kr.motd.sphinx" version "2.10.1" // documentation generation
id "com.github.johnrengelman.shadow" version "8.1.1" // fat jar
Expand All @@ -28,10 +28,10 @@ ext {
pekkoVersion = '1.0.1'
jtsVersion = '1.19.0'
confluentKafkaVersion = '7.4.0'
tscfgVersion = '1.0.2'
tscfgVersion = '1.0.0'
scapegoatVersion = '2.1.3'

testContainerVersion = '0.41.0'
testContainerVersion = '0.41.3'

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

/* logging */
implementation "com.typesafe.scala-logging:scala-logging_${scalaVersion}:3.9.5" // pekko scala logging
implementation "ch.qos.logback:logback-classic:1.4.14"
implementation "ch.qos.logback:logback-classic:1.5.0"

/* testing */
testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
testImplementation 'org.scalatestplus:mockito-3-4_2.13:3.2.10.0'
testImplementation 'org.mockito:mockito-core:5.9.0' // mocking framework
testImplementation "org.scalatest:scalatest_${scalaVersion}:3.2.17"
testImplementation 'org.mockito:mockito-core:5.10.0' // mocking framework
testImplementation "org.scalatest:scalatest_${scalaVersion}:3.2.18"
testRuntimeOnly 'com.vladsch.flexmark:flexmark-all:0.64.8' //scalatest html output
testImplementation group: 'org.pegdown', name: 'pegdown', version: '1.6.0'
testImplementation "org.apache.pekko:pekko-testkit_${scalaVersion}:${pekkoVersion}" // pekko testkit
Expand Down Expand Up @@ -147,7 +147,7 @@ dependencies {
/* Kafka */
implementation "org.apache.kafka:kafka-clients:${confluentKafkaVersion}-ccs"
implementation "io.confluent:kafka-streams-avro-serde:${confluentKafkaVersion}"
implementation "com.sksamuel.avro4s:avro4s-core_${scalaVersion}:4.1.1"
implementation "com.sksamuel.avro4s:avro4s-core_${scalaVersion}:4.1.2"

implementation 'org.apache.commons:commons-math3:3.6.1' // apache commons math3
implementation 'org.apache.poi:poi-ooxml:5.2.5' // used for FilenameUtils
Expand Down
4 changes: 2 additions & 2 deletions docs/readthedocs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Sphinx==7.2.6
sphinx-rtd-theme==2.0.0
sphinxcontrib-plantuml==0.27
sphinxcontrib-plantuml==0.28
myst-parser==2.0.0
markdown-it-py==3.0.0
sphinx-hoverxref==1.3.0
sphinxcontrib-bibtex==2.6.1
sphinxcontrib-bibtex==2.6.2
2 changes: 1 addition & 1 deletion gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spotless {

//sets a license header, removes unused imports and formats conforming to the scala fmt formatter
scala {
scalafmt()
scalafmt().configFile(".scalafmt.conf")
licenseHeader ie3LicHead, "package.*\\n"
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config/config-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ WecRuntimeConfig {
EvcsRuntimeConfig {
baseRuntimeConfig: BaseRuntimeConfig # this entry is ignored by the config generator,
# but cannot removed bc otherwise EvcsRuntimeConfig is handled as String
chargingStrategy: String | "maxPower" # can be one of maxPower, constantPower, gridOrientedScheduling or marketOrientedScheduling
lowestEvSoc: Double | 0.2 # Defines the lowest possible state of charge (SoC) that an EV is allowed to uncharge in vehicle to grid (V2G) mode
}

#@define extends BaseRuntimeConfig
Expand Down Expand Up @@ -111,6 +113,7 @@ SimpleOutputConfig {
ParticipantBaseOutputConfig {
base: BaseOutputConfig
powerRequestReply: boolean # Inform listeners about power request replies
flexResult: boolean | false
}

#@define
Expand Down Expand Up @@ -257,6 +260,7 @@ simona.output.thermal = {
defaultConfig = SimpleOutputConfig
individualConfigs = [SimpleOutputConfig]
}
simona.output.flex = Boolean | false

##################################################################
# Runtime Configuration // todo refactor as this naming is misleading
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/ie3/simona/actor/ActorUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.apache.pekko.actor.typed.scaladsl.{ActorContext, Behaviors}
object ActorUtil {
def stopOnError[M](
ctx: ActorContext[M],
msg: String
msg: String,
): Behavior[M] = {
ctx.log.error(s"$msg. Stopping.")
Behaviors.stopped
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/ie3/simona/agent/EnvironmentRefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ final case class EnvironmentRefs(
runtimeEventListener: ActorRef,
primaryServiceProxy: ActorRef,
weather: ActorRef,
evDataService: Option[ActorRef]
evDataService: Option[ActorRef],
)
2 changes: 1 addition & 1 deletion src/main/scala/edu/ie3/simona/agent/SimonaAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait SimonaAgent[D]
case Event(Status.Failure(ex), _) =>
log.error(
ex,
"Received a failure status message with following exception."
"Received a failure status message with following exception.",
)
self ! PoisonPill
stay()
Expand Down
71 changes: 48 additions & 23 deletions src/main/scala/edu/ie3/simona/agent/ValueStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package edu.ie3.simona.agent
import edu.ie3.simona.util.SimonaConstants
import squants.Dimensionless

import scala.collection.SortedMap

/** Represents a value store to hold data of former ticks
*
* @param maxTickSpan
Expand All @@ -20,7 +22,7 @@ import squants.Dimensionless
*/
final case class ValueStore[+D](
maxTickSpan: Long,
private val store: Map[Long, D] = Map.empty[Long, D]
private val store: SortedMap[Long, D] = SortedMap.empty[Long, D],
) {

/** Determine the lastly known data tick, if available. Includes the given
Expand All @@ -42,17 +44,35 @@ final case class ValueStore[+D](
* An Option to the last entry
*/
def last(requestedTick: Long): Option[(Long, D)] =
store
.filter(_._1 <= requestedTick)
.maxByOption(_._1)
store.rangeTo(requestedTick).lastOption

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

/** Optionally returns the entry for given tick
* @param tick
* The tick
* @return
* The data for the tick if it exists, otherwise [[None]]
*/
def get(tick: Long): Option[D] =
store.get(tick)

/** Returns the data associated with a tick, or a default value if no data
* exists for the tick.
* @param tick
* The tick
* @return
* the data associated with `tick` if it exists, otherwise the result of
* the `default` function.
*/
def getOrElse[D2 >: D](tick: Long, default: => D2): D2 =
store.getOrElse(tick, default)

/** Acquires the stored information within the specified tick window
*
Expand All @@ -65,20 +85,13 @@ final case class ValueStore[+D](
* in the value store
*/
def get(requestStart: Long, requestEnd: Long): Map[Long, D] =
store.filter(entry => entry._1 >= requestStart && entry._1 <= requestEnd)
store.rangeFrom(requestStart).rangeTo(requestEnd).toMap

/** Checks, if all needed ticks are available in the given value store
*
* @param neededTicks
* An Array of needed ticks
* @return
* true, if everything is there
*/
def allTicksAvailable(neededTicks: Array[Long]): Boolean =
store.keySet.toSeq.sorted.containsSlice(neededTicks.toSeq.sorted)
def asMap: Map[Long, D] =
store.toMap
}

case object ValueStore {
object ValueStore {

/** Create a default "empty" voltage value store which requires an initial
* voltage value to be set for tick 0
Expand All @@ -92,11 +105,11 @@ case object ValueStore {
*/
def forVoltage(
maxTickSpan: Long,
initialPerUnit: Dimensionless
initialPerUnit: Dimensionless,
): ValueStore[Dimensionless] =
new ValueStore(
maxTickSpan,
Map(SimonaConstants.FIRST_TICK_IN_SIMULATION -> initialPerUnit)
SortedMap(SimonaConstants.FIRST_TICK_IN_SIMULATION -> initialPerUnit),
)

/** Create a value store for result values. A result value store requires a
Expand Down Expand Up @@ -131,9 +144,21 @@ case object ValueStore {
def updateValueStore[D](
valueStore: ValueStore[D],
tick: Long,
newEntry: D
): ValueStore[D] = valueStore.copy(
store = (valueStore.store + (tick -> newEntry))
.filter(pair => pair._1 > tick - valueStore.maxTickSpan)
)
newEntry: D,
): ValueStore[D] = {
val updatedStore = valueStore.store ++ SortedMap(tick -> newEntry)

// always keep at least 3 entries
val minKeep = 3

valueStore.copy(
store = if (updatedStore.size > minKeep) {
val (rest, keep) = updatedStore.splitAt(updatedStore.size - minKeep)
val restPruned = rest.rangeFrom(tick - valueStore.maxTickSpan + 1L)

restPruned ++ keep
} else
updatedStore
)
}
}
Loading

0 comments on commit 223c8a2

Please sign in to comment.