-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from Deltares/feature/268-add-enums-for-netwo…
…rk-config-settings feature: add enums for network config settings
- Loading branch information
Showing
25 changed files
with
381 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from ra2ce.configuration.ra2ce_enum_base import Ra2ceEnumBase | ||
|
||
|
||
class WeighingEnum(Ra2ceEnumBase): | ||
NONE = 0 | ||
LENGTH = 1 | ||
TIME = 2 | ||
INVALID = 99 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
|
||
|
||
class Ra2ceEnumBase(Enum): | ||
""" | ||
Base class for enums defined within Ra2ce. | ||
NONE = 0: Optional entry (config is optional and missing) | ||
INVALID = 99: Mandatory entry (config contains invalid value) | ||
""" | ||
|
||
@classmethod | ||
def get_enum(cls, input: str | None) -> Ra2ceEnumBase: | ||
""" | ||
Create an enum from a given input string. | ||
Args: | ||
input (str): Value from config. | ||
Returns: | ||
Ra2ceEnumBase: Enumeration instance. | ||
NONE: This entry is used if the config is missing. | ||
INVALID: This entry is used if the config value is invalid. | ||
""" | ||
try: | ||
if not input: | ||
return cls.NONE | ||
return cls[input.upper().strip()] | ||
except (AttributeError, KeyError): | ||
return cls.INVALID | ||
|
||
def is_valid(self) -> bool: | ||
""" | ||
Check if given value is valid. | ||
Args: | ||
key (str): Enum key (name) | ||
Returns: | ||
bool: If the given key is not a valid key | ||
""" | ||
if self.name == "INVALID": | ||
return False | ||
return True | ||
|
||
def list_valid_options(self) -> list[Ra2ceEnumBase]: | ||
""" | ||
List the enum options as allowed in the config. | ||
Returns: | ||
list[str | None]: Concatenated options, separated by ", " | ||
""" | ||
return [_enum for _enum in type(self)][:-1] | ||
|
||
@property | ||
def config_value(self) -> str | None: | ||
""" | ||
Reconstruct the name as it is known in the config. | ||
This could entail replacement of " " by "_" and lower() operations. | ||
Returns: | ||
str: Value as known in the config. | ||
""" | ||
if self.name == "NONE": | ||
return None | ||
return self.name.lower() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from ra2ce.configuration.ra2ce_enum_base import Ra2ceEnumBase | ||
|
||
|
||
class AggregateWlEnum(Ra2ceEnumBase): | ||
NONE = 0 | ||
MIN = 1 | ||
MAX = 2 | ||
MEAN = 3 | ||
INVALID = 99 |
11 changes: 11 additions & 0 deletions
11
ra2ce/graph/network_config_data/enums/network_type_enum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from ra2ce.configuration.ra2ce_enum_base import Ra2ceEnumBase | ||
|
||
|
||
class NetworkTypeEnum(Ra2ceEnumBase): | ||
NONE = 0 | ||
WALK = 1 | ||
BIKE = 2 | ||
DRIVE = 3 | ||
DRIVE_SERVICE = 4 | ||
ALL = 5 | ||
INVALID = 99 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from ra2ce.configuration.ra2ce_enum_base import Ra2ceEnumBase | ||
|
||
|
||
class RoadTypeEnum(Ra2ceEnumBase): | ||
NONE = 0 | ||
MOTORWAY = 1 | ||
MOTORWAY_LINK = 2 | ||
TRUNK = 3 | ||
TRUNK_LINK = 4 | ||
PRIMARY = 5 | ||
PRIMARY_LINK = 6 | ||
SECONDARY = 7 | ||
SECONDARY_LINK = 8 | ||
TERTIARY = 9 | ||
TERTIARY_LINK = 10 | ||
RESIDENTIAL = 11 | ||
ROAD = 12 | ||
UNCLASSIFIED = 98 | ||
INVALID = 99 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
from ra2ce.configuration.ra2ce_enum_base import Ra2ceEnumBase | ||
|
||
|
||
class SourceEnum(Ra2ceEnumBase): | ||
OSB_BPF = 1 | ||
OSM_DOWNLOAD = 2 | ||
SHAPEFILE = 3 | ||
PICKLE = 4 | ||
INVALID = 99 | ||
|
||
@classmethod | ||
def get_enum(cls, input: str) -> SourceEnum: | ||
try: | ||
return cls[input.replace(" ", "_").upper()] | ||
except KeyError: | ||
return cls.INVALID | ||
|
||
@property | ||
def config_value(self) -> str: | ||
_parts = self.name.split("_") | ||
return " ".join( | ||
[_part if len(_part) == 3 else _part.lower() for _part in _parts] | ||
) |
Oops, something went wrong.