Skip to content

Commit

Permalink
Merge pull request #505 from OpenTrafficCam/feature/4897-add-metadata…
Browse files Browse the repository at this point in the history
…-needed-for-format-of-appendix-7

feature/4897-add-metadata-needed-for-format-of-appendix-7
  • Loading branch information
randy-seng authored Apr 26, 2024
2 parents fd5e9df + 15c5203 commit c7b4f02
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 56 deletions.
17 changes: 16 additions & 1 deletion OTAnalytics/adapter_ui/ui_texts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
from OTAnalytics.application.project import DirectionOfStationing, WeatherType
from OTAnalytics.application.project import (
CountingDayType,
DirectionOfStationing,
WeatherType,
)

DIRECTIONS_OF_STATIONING = {
DirectionOfStationing.IN_DIRECTION: "In Stationierungsrichtung",
DirectionOfStationing.OPPOSITE_DIRECTION: "Gegen Stationierungsrichtung",
}

COUNTING_DAY_TYPES = {
CountingDayType.NOW_1: "1. NoW",
CountingDayType.NOW_2: "2. NoW",
CountingDayType.FR_1: "1. Fr",
CountingDayType.FR_2: "2. Fr",
CountingDayType.SO_1: "1. So",
CountingDayType.SO_2: "2. So",
CountingDayType.FEW_1: "1. FeW",
CountingDayType.FEW_2: "2. FeW",
}

WEATHER_TYPES = {
WeatherType.SUN: "sonnig",
WeatherType.CLOUD: "bewölkt",
Expand Down
4 changes: 4 additions & 0 deletions OTAnalytics/adapter_ui/view_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ def update_svz_metadata(self, metadata: dict) -> None:
def get_directions_of_stationing(self) -> ColumnResources:
raise NotImplementedError

@abstractmethod
def get_counting_day_types(self) -> ColumnResources:
raise NotImplementedError

@abstractmethod
def get_weather_types(self) -> ColumnResources:
raise NotImplementedError
Expand Down
54 changes: 54 additions & 0 deletions OTAnalytics/application/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
TK_NUMBER: str = "tk_number"
COUNTING_LOCATION_NUMBER: str = "counting_location_number"
DIRECTION: str = "direction"
DIRECTION_DESCRIPTION: str = "direction_description"
HAS_BICYCLE_LANE: str = "has_bicycle_lane"
IS_BICYCLE_COUNTING: str = "is_bicycle_counting"
COUNTING_DAY: str = "counting_day"
WEATHER: str = "weather"
REMARK: str = "remark"
COORDINATE_X: str = "coordinate_x"
Expand Down Expand Up @@ -39,6 +43,42 @@ def parse(direction: str) -> "DirectionOfStationing":
)


class CountingDayTypeParseError(Exception):
pass


class CountingDayType(Enum):
NOW_1 = "1"
NOW_2 = "2"
FR_1 = "3"
FR_2 = "4"
SO_1 = "5"
SO_2 = "6"
FEW_1 = "7"
FEW_2 = "8"

def serialize(self) -> str:
return self.value

@staticmethod
def parse(counting_day_type: str) -> "CountingDayType":
for type in [
CountingDayType.NOW_1,
CountingDayType.NOW_2,
CountingDayType.FR_1,
CountingDayType.FR_2,
CountingDayType.SO_1,
CountingDayType.SO_2,
CountingDayType.FEW_1,
CountingDayType.FEW_2,
]:
if type.value == counting_day_type:
return type
raise CountingDayTypeParseError(
f"Unable to parse not existing counting day type '{counting_day_type}'"
)


class WeatherTypeParseError(Exception):
pass

Expand Down Expand Up @@ -74,6 +114,10 @@ class SvzMetadata:
tk_number: str | None
counting_location_number: str | None
direction: DirectionOfStationing | None
direction_description: str | None
has_bicycle_lane: bool | None
is_bicycle_counting: bool | None
counting_day: CountingDayType | None
weather: WeatherType | None
remark: str | None
coordinate_x: str | None
Expand All @@ -86,6 +130,16 @@ def to_dict(self) -> dict:
self.counting_location_number if self.counting_location_number else None
),
DIRECTION: self.direction.serialize() if self.direction else None,
DIRECTION_DESCRIPTION: (
self.direction_description if self.direction_description else None
),
HAS_BICYCLE_LANE: (
self.has_bicycle_lane if self.has_bicycle_lane else False
),
IS_BICYCLE_COUNTING: (
self.is_bicycle_counting if self.is_bicycle_counting else False
),
COUNTING_DAY: self.counting_day.serialize() if self.counting_day else None,
WEATHER: self.weather.serialize() if self.weather else None,
REMARK: self.remark if self.remark else None,
COORDINATE_X: self.coordinate_x if self.coordinate_x else None,
Expand Down
21 changes: 19 additions & 2 deletions OTAnalytics/plugin_parser/otconfig_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
from OTAnalytics.application.project import (
COORDINATE_X,
COORDINATE_Y,
COUNTING_DAY,
COUNTING_LOCATION_NUMBER,
DIRECTION,
DIRECTION_DESCRIPTION,
HAS_BICYCLE_LANE,
IS_BICYCLE_COUNTING,
REMARK,
TK_NUMBER,
WEATHER,
CountingDayType,
DirectionOfStationing,
Project,
SvzMetadata,
Expand Down Expand Up @@ -139,15 +144,27 @@ def _parse_project(self, data: dict) -> Project:
def _parse_svz_metadata(self, data: dict) -> SvzMetadata:
tk_number = data[TK_NUMBER]
counting_location_number = data[COUNTING_LOCATION_NUMBER]
direction = DirectionOfStationing.parse(data[DIRECTION])
weather = WeatherType.parse(data[WEATHER])
direction = (
DirectionOfStationing.parse(data[DIRECTION]) if data[DIRECTION] else None
)
direction_description = data[DIRECTION_DESCRIPTION]
has_bicycle_lane = data[HAS_BICYCLE_LANE]
is_bicycle_counting = data[IS_BICYCLE_COUNTING]
counting_day = (
CountingDayType.parse(data[COUNTING_DAY]) if data[COUNTING_DAY] else None
)
weather = WeatherType.parse(data[WEATHER]) if data[WEATHER] else None
remark = data[REMARK]
coordinate_x = data[COORDINATE_X]
coordinate_y = data[COORDINATE_Y]
return SvzMetadata(
tk_number=tk_number,
counting_location_number=counting_location_number,
direction=direction,
direction_description=direction_description,
has_bicycle_lane=has_bicycle_lane,
is_bicycle_counting=is_bicycle_counting,
counting_day=counting_day,
weather=weather,
remark=remark,
coordinate_x=coordinate_x,
Expand Down
27 changes: 26 additions & 1 deletion OTAnalytics/plugin_ui/customtkinter_gui/dummy_viewmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
ColumnResource,
ColumnResources,
)
from OTAnalytics.adapter_ui.ui_texts import DIRECTIONS_OF_STATIONING, WEATHER_TYPES
from OTAnalytics.adapter_ui.ui_texts import (
COUNTING_DAY_TYPES,
DIRECTIONS_OF_STATIONING,
WEATHER_TYPES,
)
from OTAnalytics.adapter_ui.view_model import (
MetadataProvider,
MissingCoordinate,
Expand All @@ -64,11 +68,16 @@
from OTAnalytics.application.project import (
COORDINATE_X,
COORDINATE_Y,
COUNTING_DAY,
COUNTING_LOCATION_NUMBER,
DIRECTION,
DIRECTION_DESCRIPTION,
HAS_BICYCLE_LANE,
IS_BICYCLE_COUNTING,
REMARK,
TK_NUMBER,
WEATHER,
CountingDayType,
DirectionOfStationing,
SvzMetadata,
WeatherType,
Expand Down Expand Up @@ -1770,6 +1779,14 @@ def update_svz_metadata(self, metadata: dict) -> None:
if metadata[DIRECTION]
else None
),
direction_description=metadata[DIRECTION_DESCRIPTION],
has_bicycle_lane=metadata[HAS_BICYCLE_LANE],
is_bicycle_counting=metadata[IS_BICYCLE_COUNTING],
counting_day=(
CountingDayType.parse(metadata[COUNTING_DAY])
if metadata[COUNTING_DAY]
else None
),
weather=(
WeatherType.parse(metadata[WEATHER]) if metadata[WEATHER] else None
),
Expand All @@ -1787,6 +1804,14 @@ def get_directions_of_stationing(self) -> ColumnResources:
]
)

def get_counting_day_types(self) -> ColumnResources:
return ColumnResources(
[
ColumnResource(id=key.serialize(), values={COLUMN_NAME: value})
for key, value in COUNTING_DAY_TYPES.items()
]
)

def get_weather_types(self) -> ColumnResources:
return ColumnResources(
[
Expand Down
Loading

0 comments on commit c7b4f02

Please sign in to comment.