Getpositions angepasst, sodass Jsons geschrieben werden. Ausserdem Anpassung, sodass Leichen (=Bloecke ohne pos) nicht erfasst werden

This commit is contained in:
2025-05-07 12:29:35 +02:00
parent c370fab036
commit 58195eebfa
8 changed files with 248 additions and 64 deletions
+27 -19
View File
@@ -3,30 +3,36 @@ from dacite import from_dict
from typing import List
import json
@dataclass
class Sensor:
id: str
class Punkt:
x: float
y: float
@dataclass
class Aktor:
class Ziel:
#Sensor oder Aktor
id: str
x: float
y: float
pos: Punkt
@dataclass
class Quelle:
#Unterverteiler
id: str
pos: Punkt
@dataclass
class Pritsche:
id: str
x: float
y: float
cords: List[Punkt]
@dataclass
class Anlage:
name: str
sensoren: List[Sensor]
aktoren: List[Aktor]
sensoren: List[Ziel]
aktoren: List[Ziel]
unterverteiler: List[Quelle]
kabelpritschen: List[Pritsche]
def to_json(self, pretty: bool = True) -> str:
@@ -41,20 +47,22 @@ class Anlage:
return result
if __name__ == '__main__':
if __name__ == '__main__':
json_string = '''{
"name": "H&M",
"sensoren": [
{"id": "AP4321", "x": 14, "y": 50},
{"id": "AP4322", "x": 22, "y": 100}
],
{"id": "S1", "pos": {"x": 3, "y": 5}}
],
"aktoren": [
{"id": "AP4321", "x": 14, "y": 50},
{"id": "AP4322", "x": 22, "y": 100}
],
{"id": "A1", "pos": {"x": 3, "y": 5}}
],
"unterverteiler": [
{"id": "U1", "pos": {"x": 3, "y": 5}}
],
"kabelpritschen": [
{"id": "p1", "x": 1, "y": 0},
{"id": "p2", "x": 22, "y": 10}
{"id": "p1", "cords": [{"x": 3, "y": 5},{"x": 3, "y": 5}]},
{"id": "p2", "cords": [{"x": 3, "y": 5},{"x": 3, "y": 5}]}
]
}
'''