Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
91dc6ca
Cherrypicking changes from ck/#90
sebastian-peter Jan 29, 2022
56fc4e1
Transferring boundary extraction and data division from old LvCoordin…
sebastian-peter Jan 30, 2022
0916a8b
Enabling scala 3 syntax
sebastian-peter Jan 30, 2022
3efa430
Implementing recursive division
sebastian-peter Jan 30, 2022
7b5a938
Using the pool for recursion
sebastian-peter Jan 30, 2022
15f7de4
Merge branch 'dev' into sp/#137-LvRegionCoordinator
ckittl Feb 14, 2022
7bd0546
Slight improvements
sebastian-peter Feb 17, 2022
cc7482f
Merge branch 'dev' into sp/#137-LvRegionCoordinator
sebastian-peter Mar 28, 2022
07fec94
Adapting to input data provider
sebastian-peter Mar 30, 2022
d0bae97
Cleaning up imports
sebastian-peter Mar 30, 2022
acef002
Merge branch 'dev' into sp/#137-LvRegionCoordinator
sebastian-peter Mar 30, 2022
c863cb7
More import cleanup
sebastian-peter Mar 30, 2022
331c801
Introduced tests for corrupt input data
sebastian-peter Mar 31, 2022
3136362
Fixing and improving boundary polygon creation
sebastian-peter Apr 8, 2022
5f86da5
Merge branch 'dev' into sp/#137-LvRegionCoordinator
sebastian-peter Apr 8, 2022
6477afe
More efficient and maintainable partitioning of OsmoGridModels
sebastian-peter Apr 12, 2022
0495792
Speeding up tests with reusable test data
sebastian-peter Apr 12, 2022
02dbe15
Merge branch 'dev' into sp/#137-LvRegionCoordinator
sebastian-peter Apr 25, 2022
76ded05
Merge branch 'dev' into sp/#137-LvRegionCoordinator
sebastian-peter Apr 25, 2022
4386348
Merge branch 'dev' into sp/#137-LvRegionCoordinator
t-ober May 6, 2022
e505ec9
Apply suggestions from code review
sebastian-peter May 9, 2022
50e0558
Adding some more ScalaDoc for OsmoGridModelPartitioner
sebastian-peter May 9, 2022
75f83ef
Simplifying BoundaryFactorySpec
sebastian-peter May 9, 2022
3394ec6
ScalaDoc for message LvRegionCoordinator.Partition
sebastian-peter May 9, 2022
da9135f
Fixing code smell in BoundaryFactory
sebastian-peter May 9, 2022
03f0877
Add warning if entity is not covered by any boundary area
sebastian-peter May 9, 2022
77b97fb
Merge branch 'dev' into sp/#137-LvRegionCoordinator
sebastian-peter May 15, 2022
30e8b69
Merge branch 'dev' into sp/#137-LvRegionCoordinator
t-ober May 17, 2022
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 .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# These are explicitly windows files and should use crlf
*.bat text eol=crlf
*.pbf binary
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 @@ -23,6 +23,10 @@ generation: {
#@optional
lv: {
distinctHouseConnections: Boolean | false # If there shall be distinct lines for house connection
boundaryAdminLevel: {
starting: Int | 2
lowest: Int | 8
}
osm: {
#@optional
filter: { # filter to be applied for the LvOsmoGridModel
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/edu/ie3/osmogrid/ActorStopSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import org.slf4j.Logger

/** Support trait for executing clean up tasks with stopping an actor
*
* @tparam T
* Behavior type
* @tparam S
* StateData type. Optional, use [[Any]] if not applicable
*/
trait ActorStopSupport[T, S] {
trait ActorStopSupport[S] {

/** Function to perform cleanup tasks while shutting down
*/
protected def cleanUp(stateData: S): Unit

/** Specific stop state with clean up actions issued
* @tparam T
* Behavior type
*/
protected def stopBehavior(stateData: S): Behavior[T] =
protected def stopBehavior[T](stateData: S): Behavior[T] =
Behaviors.stopped(() => cleanUp(stateData))

final protected def terminate(log: Logger, stateData: S): Behavior[T] = {
final protected def terminate[T](log: Logger, stateData: S): Behavior[T] = {
log.info("Got request to terminate.")
stopBehavior(stateData)
}

final protected def postStopCleanUp(
final protected def postStopCleanUp[T](
log: Logger,
stateData: S
): Behavior[T] = {
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/edu/ie3/osmogrid/ActorStopSupportStateless.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ import akka.actor.typed.scaladsl.Behaviors
import org.slf4j.Logger

/** Support trait for executing clean up tasks with stopping an actor
* @tparam T
* Behavior type
*/
trait ActorStopSupportStateless[T] {
trait ActorStopSupportStateless {

/** Function to perform cleanup tasks while shutting down
*/
protected def cleanUp(): Unit

/** Specific stop state with clean up actions issued
* @tparam T
* Behavior type
*/
protected val stopBehavior: Behavior[T] = Behaviors.stopped(cleanUp)
protected def stopBehavior[T]: Behavior[T] = Behaviors.stopped(cleanUp)

final protected def terminate(log: Logger): Behavior[T] = {
final protected def terminate[T](log: Logger): Behavior[T] = {
log.info("Got request to terminate.")
stopBehavior
}

final protected def postStopCleanUp(log: Logger): Behavior[T] = {
final protected def postStopCleanUp[T](log: Logger): Behavior[T] = {
log.info("Got terminated by ActorSystem.")
stopBehavior
}
Expand Down
41 changes: 26 additions & 15 deletions src/main/scala/edu/ie3/osmogrid/cfg/ConfigFailFast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ package edu.ie3.osmogrid.cfg

import akka.actor.typed.ActorRef
import com.typesafe.scalalogging.LazyLogging
import edu.ie3.osmogrid.cfg.OsmoGridConfig.{Input, Output}
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Input.{Asset, Osm}
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Generation
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Generation.Lv
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Input.Asset.File
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Input.{Asset, Osm}
import edu.ie3.osmogrid.cfg.OsmoGridConfig.{Generation, Input, Output}
import edu.ie3.osmogrid.exception.IllegalConfigException
import edu.ie3.osmogrid.io.input.BoundaryAdminLevel
import edu.ie3.osmogrid.io.output.ResultListener

import scala.util.Try
Expand Down Expand Up @@ -47,19 +47,30 @@ object ConfigFailFast extends LazyLogging {

private def checkLvConfig(lv: OsmoGridConfig.Generation.Lv): Unit = lv match {
case Lv(
amountOfGridGenerators,
amountOfRegionCoordinators,
distinctHouseConnections,
lv.osm
Lv.BoundaryAdminLevel(
lowest,
starting
),
_,
_
) =>
if (amountOfGridGenerators < 1)
throw IllegalConfigException(
s"The amount of lv grid generation actors needs to be at least 1 (provided: $amountOfGridGenerators)."
)
if (amountOfRegionCoordinators < 1)
throw IllegalConfigException(
s"The amount of lv region coordination actors needs to be at least 1 (provided: $amountOfRegionCoordinators)."
)
(BoundaryAdminLevel(lowest), BoundaryAdminLevel(starting)) match {
case (None, _) =>
throw IllegalConfigException(
s"The lowest admin level can not be parsed (provided: $lowest)."
)
case (_, None) =>
throw IllegalConfigException(
s"The starting admin level can not be parsed (provided: $starting)."
)
case (Some(lowestParsed), Some(startingParsed))
if startingParsed > lowestParsed =>
throw IllegalConfigException(
s"The starting admin level (provided: $startingParsed) has to be higher than the lowest admin level (provided: $lowestParsed)."
)
case _ =>
// all good, do nothing
}
}

private def checkInputConfig(input: OsmoGridConfig.Input): Unit =
Expand Down
38 changes: 28 additions & 10 deletions src/main/scala/edu/ie3/osmogrid/cfg/OsmoGridConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,29 @@ object OsmoGridConfig {
)
object Generation {
final case class Lv(
amountOfGridGenerators: scala.Int,
amountOfRegionCoordinators: scala.Int,
boundaryAdminLevel: OsmoGridConfig.Generation.Lv.BoundaryAdminLevel,
distinctHouseConnections: scala.Boolean,
osm: OsmoGridConfig.Generation.Lv.Osm
)
object Lv {
final case class BoundaryAdminLevel(
lowest: scala.Int,
starting: scala.Int
)
object BoundaryAdminLevel {
def apply(
c: com.typesafe.config.Config,
parentPath: java.lang.String,
$tsCfgValidator: $TsCfgValidator
): OsmoGridConfig.Generation.Lv.BoundaryAdminLevel = {
OsmoGridConfig.Generation.Lv.BoundaryAdminLevel(
lowest = if (c.hasPathOrNull("lowest")) c.getInt("lowest") else 8,
starting =
if (c.hasPathOrNull("starting")) c.getInt("starting") else 2
)
}
}

final case class Osm(
filter: scala.Option[OsmoGridConfig.Generation.Lv.Osm.Filter]
)
Expand Down Expand Up @@ -75,14 +92,15 @@ object OsmoGridConfig {
$tsCfgValidator: $TsCfgValidator
): OsmoGridConfig.Generation.Lv = {
OsmoGridConfig.Generation.Lv(
amountOfGridGenerators =
if (c.hasPathOrNull("amountOfGridGenerators"))
c.getInt("amountOfGridGenerators")
else 10,
amountOfRegionCoordinators =
if (c.hasPathOrNull("amountOfRegionCoordinators"))
c.getInt("amountOfRegionCoordinators")
else 5,
boundaryAdminLevel = OsmoGridConfig.Generation.Lv.BoundaryAdminLevel(
if (c.hasPathOrNull("boundaryAdminLevel"))
c.getConfig("boundaryAdminLevel")
else
com.typesafe.config.ConfigFactory
.parseString("boundaryAdminLevel{}"),
parentPath + "boundaryAdminLevel.",
$tsCfgValidator
),
distinctHouseConnections = c.hasPathOrNull(
"distinctHouseConnections"
) && c.getBoolean("distinctHouseConnections"),
Expand Down
66 changes: 66 additions & 0 deletions src/main/scala/edu/ie3/osmogrid/io/input/BoundaryAdminLevel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* © 2022. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/

package edu.ie3.osmogrid.io.input

/** Represents the levels of
* [[https://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative administrative boundaries]]
* in OSM
*/
enum BoundaryAdminLevel(val osmLevel: Int) extends Ordered[BoundaryAdminLevel] {

/** National border (NUTS 0)
*/
case NationLevel extends BoundaryAdminLevel(2)

/** Federal states border (Bundesland) (NUTS 1)
*/
case FederalStateLevel extends BoundaryAdminLevel(4)

/** State-district border (Regierungsbezirk) (NUTS 2)
*/
case StateDistrictLevel extends BoundaryAdminLevel(5)

/** County borders (Landkreis / Kreis / kreisfreie Stadt / Stadtkreis) (NUTS
* 3)
*/
case CountyLevel extends BoundaryAdminLevel(6)

/** Amt (Amtsgemeinde, Verwaltungsgemeinschaft) (LAU 1/NUTS 4)
*/
case AmtLevel extends BoundaryAdminLevel(7)

/** Towns, Municipalities / City-districts (Stadt, Gemeinde) (LAU 2/NUTS 5)
*/
case MunicipalityLevel extends BoundaryAdminLevel(8)

/** Parts of a municipality with parish councils / self government
* (Stadtbezirk/Gemeindeteil mit Selbstverwaltung)
*/
case Suburb1Level extends BoundaryAdminLevel(9)

/** Parts of a municipality without parish councils / self government
* (Stadtteil/Gemeindeteil ohne Selbstverwaltung)
*/
case Suburb2Level extends BoundaryAdminLevel(10)

/** Neighbourhoods, statistical or historical (Stadtviertel etc.)
*/
case Suburb3Level extends BoundaryAdminLevel(11)

def compare(other: BoundaryAdminLevel): Int =
osmLevel compareTo other.osmLevel
}

object BoundaryAdminLevel {
def apply(osmLevel: Int): Option[BoundaryAdminLevel] =
BoundaryAdminLevel.values.find(_.osmLevel == osmLevel)

def nextLowerLevel(
boundaryAdminLevel: BoundaryAdminLevel
): Option[BoundaryAdminLevel] =
BoundaryAdminLevel.values.filter(_ > boundaryAdminLevel).minOption
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import scala.collection.mutable.ListBuffer
import scala.util.{Failure, Success, Try, Using}
import java.util.UUID

object InputDataProvider
extends ActorStopSupport[InputDataEvent, ProviderData] {
object InputDataProvider extends ActorStopSupport[ProviderData] {

// external requests
sealed trait Request
Expand Down
Loading