30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
from pydantic import BaseModel, Field, field_validator
|
|
from typing import Optional
|
|
|
|
class Eckrad(BaseModel):
|
|
teileid: str
|
|
drehung: Optional [float] = Field(default=0.0,description="Rotation des Elements")
|
|
hoehe: Optional [float] = Field(default=0.0,description="Hoehe des Elements")
|
|
drehrichtung: Optional [str] =Field(default=None,description="Richtung des Eckrads")
|
|
|
|
@classmethod
|
|
def from_merkmale(cls, teileid: str, x: float, y: float, merkmale: dict) -> 'Eckrad':
|
|
try:
|
|
hoehe = float(merkmale.get("Höhe in Meter")) * 1000
|
|
except Exception as e:
|
|
hoehe = 0.0
|
|
try:
|
|
drehung = float(merkmale.get("Drehung"))
|
|
except Exception as e:
|
|
drehung = 0.0
|
|
try:
|
|
drehrichtung = merkmale.get("Drehrichtung")
|
|
except Exception as e:
|
|
drehrichtung = None
|
|
return cls(
|
|
teileid = teileid,
|
|
x = x,
|
|
y = y,
|
|
hoehe = hoehe,
|
|
drehrichtung = drehrichtung
|
|
) |