Skip to content

Commit 8f45cd1

Browse files
Merge branch 'yaramo2' into operations
# Conflicts: # yaramo/topology.py
2 parents e389d6d + bc9edae commit 8f45cd1

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

yaramo/geo_node.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ def __init__(self, x, y, **kwargs):
1919

2020
@abstractmethod
2121
def get_distance_to_other_geo_node(self, geo_node_b: "GeoNode"):
22+
"""Returns to distance to the given other GeoNode."""
2223
pass
2324

24-
def to_serializable(self):
25-
return self.__dict__, {}
26-
2725
@abstractmethod
28-
def to_wgs84(self):
26+
def to_wgs84(self) -> "Wgs84GeoNode":
2927
pass
3028

3129
@abstractmethod
32-
def to_dbref(self):
30+
def to_dbref(self) -> "DbrefGeoNode":
3331
pass
3432

33+
def to_serializable(self):
34+
return self.__dict__, {}
35+
3536

3637
class Wgs84GeoNode(GeoNode):
3738
def get_distance_to_other_geo_node(self, geo_node_b: "Wgs84GeoNode"):

yaramo/topology.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from collections import defaultdict
12
from datetime import datetime
3+
from enum import Enum
24
from typing import List
35

46
import simplejson as json
@@ -12,10 +14,28 @@
1214
from yaramo.vacancy_section import VacancySection
1315

1416

17+
class PlanningState(Enum):
18+
erstellt = 1
19+
qualitaetsgeprueft = 2
20+
plangeprueft = 3
21+
freigegeben = 4
22+
genehmigt = 5
23+
abgenommen = 6
24+
uebernommen = 7
25+
gleichgestellt = 8
26+
sonstige = 9
27+
28+
def __str__(self):
29+
return self.name
30+
31+
1532
class Topology(BaseElement):
1633
"""The Topology is a collection of all track elements comprising that topology.
1734
1835
Elements like Signals, Nodes, Edges, Routes and Vacancy Sections can be accessed by their uuid in their respective dictionary.
36+
37+
The status_information provides additional information for each PlanningState, with the keys of the inner dict
38+
being based on the PlanPro Akteur_Zuordnung class.
1939
"""
2040

2141
def __init__(self, **kwargs):
@@ -25,6 +45,8 @@ def __init__(self, **kwargs):
2545
self.signals: dict[str, Signal] = {}
2646
self.routes: dict[str, Route] = {}
2747
self.vacancy_sections: dict[str, VacancySection] = {}
48+
self.current_status: PlanningState = PlanningState.erstellt
49+
self.status_information: dict[PlanningState, dict[str, str]] = defaultdict(dict)
2850

2951
self.created_at: datetime = datetime.now()
3052
self.created_with: str = "unknown"
@@ -76,6 +98,15 @@ def get_edge_by_nodes(self, node_a: Node, node_b: Node):
7698
return edge
7799
return None
78100

101+
def get_route_by_signal_names(self, start_signal_name, end_signal_name):
102+
for route_uuid in self.routes:
103+
route = self.routes[route_uuid]
104+
if (
105+
route.start_signal.name == start_signal_name
106+
and route.end_signal.name == end_signal_name
107+
):
108+
return route
109+
79110
def to_serializable(self):
80111
"""See the description in the BaseElement class.
81112
@@ -104,12 +135,16 @@ def to_serializable(self):
104135
"routes": routes,
105136
"objects": objects,
106137
"vacany_sections": vacancy_sections,
138+
"current_status": self.current_status.value,
139+
"status_information": self.status_information,
107140
}, {}
108141

109142
@classmethod
110143
def from_json(cls, json_str: str):
111144
obj = json.loads(json_str)
112145
topology = cls()
146+
topology.current_status = PlanningState(obj.get("current_status", PlanningState.erstellt))
147+
topology.status_information = obj.get("status_information", defaultdict(dict))
113148
for node in obj["nodes"]:
114149
node_obj = Node(**node)
115150
topology.add_node(node_obj)

0 commit comments

Comments
 (0)