1+ from collections import defaultdict
12from datetime import datetime
3+ from enum import Enum
24from typing import List
35
46import simplejson as json
1214from 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+
1532class 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