Source code for flatland.integrations.interactiveai.event_api.models.metadata_schema_railway
# coding: utf-8
"""
APIFlask
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
The version of the OpenAPI document: 0.1.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import json
import pprint
import re # noqa: F401
from typing import Any, ClassVar, Dict, List, Union
from typing import Optional, Set
from pydantic import BaseModel, ConfigDict, StrictFloat, StrictInt, StrictStr
from typing_extensions import Self
[docs]
class MetadataSchemaRailway(BaseModel):
"""
MetadataSchemaRailway
""" # noqa: E501
agent_id: Optional[StrictStr]
agent_position: Optional[List[Optional[StrictInt]]] = None
delay: StrictInt
event_type: StrictStr
id_train: Optional[StrictStr]
latitude: Optional[Union[StrictFloat, StrictInt]] = None
longitude: Optional[Union[StrictFloat, StrictInt]] = None
malfunction_stop_position: Optional[List[Optional[StrictInt]]] = None
num_rame: Optional[StrictStr] = None
simulation_name: Optional[StrictStr] = None
tmp_rame: Optional[StrictStr] = None
travel_plan: Optional[List[Dict[str, Any]]] = None
__properties: ClassVar[List[str]] = ["agent_id", "agent_position", "delay", "event_type", "id_train", "latitude", "longitude", "malfunction_stop_position",
"num_rame", "simulation_name", "tmp_rame", "travel_plan"]
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
[docs]
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
[docs]
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
[docs]
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of MetadataSchemaRailway from a JSON string"""
return cls.from_dict(json.loads(json_str))
[docs]
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# set to None if agent_id (nullable) is None
# and model_fields_set contains the field
if self.agent_id is None and "agent_id" in self.model_fields_set:
_dict['agent_id'] = None
# set to None if agent_position (nullable) is None
# and model_fields_set contains the field
if self.agent_position is None and "agent_position" in self.model_fields_set:
_dict['agent_position'] = None
# set to None if id_train (nullable) is None
# and model_fields_set contains the field
if self.id_train is None and "id_train" in self.model_fields_set:
_dict['id_train'] = None
# set to None if latitude (nullable) is None
# and model_fields_set contains the field
if self.latitude is None and "latitude" in self.model_fields_set:
_dict['latitude'] = None
# set to None if longitude (nullable) is None
# and model_fields_set contains the field
if self.longitude is None and "longitude" in self.model_fields_set:
_dict['longitude'] = None
# set to None if malfunction_stop_position (nullable) is None
# and model_fields_set contains the field
if self.malfunction_stop_position is None and "malfunction_stop_position" in self.model_fields_set:
_dict['malfunction_stop_position'] = None
# set to None if num_rame (nullable) is None
# and model_fields_set contains the field
if self.num_rame is None and "num_rame" in self.model_fields_set:
_dict['num_rame'] = None
# set to None if simulation_name (nullable) is None
# and model_fields_set contains the field
if self.simulation_name is None and "simulation_name" in self.model_fields_set:
_dict['simulation_name'] = None
# set to None if tmp_rame (nullable) is None
# and model_fields_set contains the field
if self.tmp_rame is None and "tmp_rame" in self.model_fields_set:
_dict['tmp_rame'] = None
# set to None if travel_plan (nullable) is None
# and model_fields_set contains the field
if self.travel_plan is None and "travel_plan" in self.model_fields_set:
_dict['travel_plan'] = None
return _dict
[docs]
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of MetadataSchemaRailway from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"agent_id": obj.get("agent_id"),
"agent_position": obj.get("agent_position"),
"delay": obj.get("delay"),
"event_type": obj.get("event_type"),
"id_train": obj.get("id_train"),
"latitude": obj.get("latitude"),
"longitude": obj.get("longitude"),
"malfunction_stop_position": obj.get("malfunction_stop_position"),
"num_rame": obj.get("num_rame"),
"simulation_name": obj.get("simulation_name"),
"tmp_rame": obj.get("tmp_rame"),
"travel_plan": obj.get("travel_plan")
})
return _obj