Skip to content

Commit b3f052d

Browse files
authored
Merge pull request #138 from ie3-institute/sp/#137-LvRegionCoordinator
Implementing `LvRegionCoordinator`, osm splitting
2 parents 5a64bf5 + 30e8b69 commit b3f052d

35 files changed

+1251
-163
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# These are explicitly windows files and should use crlf
22
*.bat text eol=crlf
3+
*.pbf binary

src/main/resources/config/config-template.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ generation: {
2323
#@optional
2424
lv: {
2525
distinctHouseConnections: Boolean | false # If there shall be distinct lines for house connection
26+
boundaryAdminLevel: {
27+
starting: Int | 2
28+
lowest: Int | 8
29+
}
2630
osm: {
2731
#@optional
2832
filter: { # filter to be applied for the LvOsmoGridModel

src/main/scala/edu/ie3/osmogrid/ActorStopSupport.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ import org.slf4j.Logger
1212

1313
/** Support trait for executing clean up tasks with stopping an actor
1414
*
15-
* @tparam T
16-
* Behavior type
1715
* @tparam S
1816
* StateData type. Optional, use [[Any]] if not applicable
1917
*/
20-
trait ActorStopSupport[T, S] {
18+
trait ActorStopSupport[S] {
2119

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

2624
/** Specific stop state with clean up actions issued
25+
* @tparam T
26+
* Behavior type
2727
*/
28-
protected def stopBehavior(stateData: S): Behavior[T] =
28+
protected def stopBehavior[T](stateData: S): Behavior[T] =
2929
Behaviors.stopped(() => cleanUp(stateData))
3030

31-
final protected def terminate(log: Logger, stateData: S): Behavior[T] = {
31+
final protected def terminate[T](log: Logger, stateData: S): Behavior[T] = {
3232
log.info("Got request to terminate.")
3333
stopBehavior(stateData)
3434
}
3535

36-
final protected def postStopCleanUp(
36+
final protected def postStopCleanUp[T](
3737
log: Logger,
3838
stateData: S
3939
): Behavior[T] = {

src/main/scala/edu/ie3/osmogrid/ActorStopSupportStateless.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ import akka.actor.typed.scaladsl.Behaviors
1111
import org.slf4j.Logger
1212

1313
/** Support trait for executing clean up tasks with stopping an actor
14-
* @tparam T
15-
* Behavior type
1614
*/
17-
trait ActorStopSupportStateless[T] {
15+
trait ActorStopSupportStateless {
1816

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

2321
/** Specific stop state with clean up actions issued
22+
* @tparam T
23+
* Behavior type
2424
*/
25-
protected val stopBehavior: Behavior[T] = Behaviors.stopped(cleanUp)
25+
protected def stopBehavior[T]: Behavior[T] = Behaviors.stopped(cleanUp)
2626

27-
final protected def terminate(log: Logger): Behavior[T] = {
27+
final protected def terminate[T](log: Logger): Behavior[T] = {
2828
log.info("Got request to terminate.")
2929
stopBehavior
3030
}
3131

32-
final protected def postStopCleanUp(log: Logger): Behavior[T] = {
32+
final protected def postStopCleanUp[T](log: Logger): Behavior[T] = {
3333
log.info("Got terminated by ActorSystem.")
3434
stopBehavior
3535
}

src/main/scala/edu/ie3/osmogrid/cfg/ConfigFailFast.scala

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ package edu.ie3.osmogrid.cfg
88

99
import akka.actor.typed.ActorRef
1010
import com.typesafe.scalalogging.LazyLogging
11-
import edu.ie3.osmogrid.cfg.OsmoGridConfig.{Input, Output}
12-
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Input.{Asset, Osm}
13-
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Generation
1411
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Generation.Lv
1512
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Input.Asset.File
13+
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Input.{Asset, Osm}
14+
import edu.ie3.osmogrid.cfg.OsmoGridConfig.{Generation, Input, Output}
1615
import edu.ie3.osmogrid.exception.IllegalConfigException
16+
import edu.ie3.osmogrid.io.input.BoundaryAdminLevel
1717
import edu.ie3.osmogrid.io.output.ResultListener
1818

1919
import scala.util.Try
@@ -47,19 +47,30 @@ object ConfigFailFast extends LazyLogging {
4747

4848
private def checkLvConfig(lv: OsmoGridConfig.Generation.Lv): Unit = lv match {
4949
case Lv(
50-
amountOfGridGenerators,
51-
amountOfRegionCoordinators,
52-
distinctHouseConnections,
53-
lv.osm
50+
Lv.BoundaryAdminLevel(
51+
lowest,
52+
starting
53+
),
54+
_,
55+
_
5456
) =>
55-
if (amountOfGridGenerators < 1)
56-
throw IllegalConfigException(
57-
s"The amount of lv grid generation actors needs to be at least 1 (provided: $amountOfGridGenerators)."
58-
)
59-
if (amountOfRegionCoordinators < 1)
60-
throw IllegalConfigException(
61-
s"The amount of lv region coordination actors needs to be at least 1 (provided: $amountOfRegionCoordinators)."
62-
)
57+
(BoundaryAdminLevel(lowest), BoundaryAdminLevel(starting)) match {
58+
case (None, _) =>
59+
throw IllegalConfigException(
60+
s"The lowest admin level can not be parsed (provided: $lowest)."
61+
)
62+
case (_, None) =>
63+
throw IllegalConfigException(
64+
s"The starting admin level can not be parsed (provided: $starting)."
65+
)
66+
case (Some(lowestParsed), Some(startingParsed))
67+
if startingParsed > lowestParsed =>
68+
throw IllegalConfigException(
69+
s"The starting admin level (provided: $startingParsed) has to be higher than the lowest admin level (provided: $lowestParsed)."
70+
)
71+
case _ =>
72+
// all good, do nothing
73+
}
6374
}
6475

6576
private def checkInputConfig(input: OsmoGridConfig.Input): Unit =

src/main/scala/edu/ie3/osmogrid/cfg/OsmoGridConfig.scala

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,29 @@ object OsmoGridConfig {
1717
)
1818
object Generation {
1919
final case class Lv(
20-
amountOfGridGenerators: scala.Int,
21-
amountOfRegionCoordinators: scala.Int,
20+
boundaryAdminLevel: OsmoGridConfig.Generation.Lv.BoundaryAdminLevel,
2221
distinctHouseConnections: scala.Boolean,
2322
osm: OsmoGridConfig.Generation.Lv.Osm
2423
)
2524
object Lv {
25+
final case class BoundaryAdminLevel(
26+
lowest: scala.Int,
27+
starting: scala.Int
28+
)
29+
object BoundaryAdminLevel {
30+
def apply(
31+
c: com.typesafe.config.Config,
32+
parentPath: java.lang.String,
33+
$tsCfgValidator: $TsCfgValidator
34+
): OsmoGridConfig.Generation.Lv.BoundaryAdminLevel = {
35+
OsmoGridConfig.Generation.Lv.BoundaryAdminLevel(
36+
lowest = if (c.hasPathOrNull("lowest")) c.getInt("lowest") else 8,
37+
starting =
38+
if (c.hasPathOrNull("starting")) c.getInt("starting") else 2
39+
)
40+
}
41+
}
42+
2643
final case class Osm(
2744
filter: scala.Option[OsmoGridConfig.Generation.Lv.Osm.Filter]
2845
)
@@ -75,14 +92,15 @@ object OsmoGridConfig {
7592
$tsCfgValidator: $TsCfgValidator
7693
): OsmoGridConfig.Generation.Lv = {
7794
OsmoGridConfig.Generation.Lv(
78-
amountOfGridGenerators =
79-
if (c.hasPathOrNull("amountOfGridGenerators"))
80-
c.getInt("amountOfGridGenerators")
81-
else 10,
82-
amountOfRegionCoordinators =
83-
if (c.hasPathOrNull("amountOfRegionCoordinators"))
84-
c.getInt("amountOfRegionCoordinators")
85-
else 5,
95+
boundaryAdminLevel = OsmoGridConfig.Generation.Lv.BoundaryAdminLevel(
96+
if (c.hasPathOrNull("boundaryAdminLevel"))
97+
c.getConfig("boundaryAdminLevel")
98+
else
99+
com.typesafe.config.ConfigFactory
100+
.parseString("boundaryAdminLevel{}"),
101+
parentPath + "boundaryAdminLevel.",
102+
$tsCfgValidator
103+
),
86104
distinctHouseConnections = c.hasPathOrNull(
87105
"distinctHouseConnections"
88106
) && c.getBoolean("distinctHouseConnections"),
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* © 2022. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
7+
package edu.ie3.osmogrid.io.input
8+
9+
/** Represents the levels of
10+
* [[https://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative administrative boundaries]]
11+
* in OSM
12+
*/
13+
enum BoundaryAdminLevel(val osmLevel: Int) extends Ordered[BoundaryAdminLevel] {
14+
15+
/** National border (NUTS 0)
16+
*/
17+
case NationLevel extends BoundaryAdminLevel(2)
18+
19+
/** Federal states border (Bundesland) (NUTS 1)
20+
*/
21+
case FederalStateLevel extends BoundaryAdminLevel(4)
22+
23+
/** State-district border (Regierungsbezirk) (NUTS 2)
24+
*/
25+
case StateDistrictLevel extends BoundaryAdminLevel(5)
26+
27+
/** County borders (Landkreis / Kreis / kreisfreie Stadt / Stadtkreis) (NUTS
28+
* 3)
29+
*/
30+
case CountyLevel extends BoundaryAdminLevel(6)
31+
32+
/** Amt (Amtsgemeinde, Verwaltungsgemeinschaft) (LAU 1/NUTS 4)
33+
*/
34+
case AmtLevel extends BoundaryAdminLevel(7)
35+
36+
/** Towns, Municipalities / City-districts (Stadt, Gemeinde) (LAU 2/NUTS 5)
37+
*/
38+
case MunicipalityLevel extends BoundaryAdminLevel(8)
39+
40+
/** Parts of a municipality with parish councils / self government
41+
* (Stadtbezirk/Gemeindeteil mit Selbstverwaltung)
42+
*/
43+
case Suburb1Level extends BoundaryAdminLevel(9)
44+
45+
/** Parts of a municipality without parish councils / self government
46+
* (Stadtteil/Gemeindeteil ohne Selbstverwaltung)
47+
*/
48+
case Suburb2Level extends BoundaryAdminLevel(10)
49+
50+
/** Neighbourhoods, statistical or historical (Stadtviertel etc.)
51+
*/
52+
case Suburb3Level extends BoundaryAdminLevel(11)
53+
54+
def compare(other: BoundaryAdminLevel): Int =
55+
osmLevel compareTo other.osmLevel
56+
}
57+
58+
object BoundaryAdminLevel {
59+
def apply(osmLevel: Int): Option[BoundaryAdminLevel] =
60+
BoundaryAdminLevel.values.find(_.osmLevel == osmLevel)
61+
62+
def nextLowerLevel(
63+
boundaryAdminLevel: BoundaryAdminLevel
64+
): Option[BoundaryAdminLevel] =
65+
BoundaryAdminLevel.values.filter(_ > boundaryAdminLevel).minOption
66+
}

src/main/scala/edu/ie3/osmogrid/io/input/InputDataProvider.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ import scala.collection.mutable.ListBuffer
3737
import scala.util.{Failure, Success, Try, Using}
3838
import java.util.UUID
3939

40-
object InputDataProvider
41-
extends ActorStopSupport[InputDataEvent, ProviderData] {
40+
object InputDataProvider extends ActorStopSupport[ProviderData] {
4241

4342
// external requests
4443
sealed trait Request

0 commit comments

Comments
 (0)