From e516fd614f9d6eec4b293265c7497778ec261eda Mon Sep 17 00:00:00 2001 From: GabrielBarberini Date: Mon, 20 May 2024 23:49:29 -0300 Subject: [PATCH] refactors models --- lib/models/environment.py | 4 ++++ lib/models/flight.py | 4 ++++ lib/models/motor.py | 28 ++++++++++++++++------------ lib/models/rocket.py | 8 ++++++-- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/models/environment.py b/lib/models/environment.py index cd2b9ab..4074fde 100644 --- a/lib/models/environment.py +++ b/lib/models/environment.py @@ -14,3 +14,7 @@ class Env(BaseModel, frozen=True): date: Optional[datetime.datetime] = ( datetime.datetime.today() + datetime.timedelta(days=1) ) + + @property + def env_id(self) -> str: + return str(hash(self)) diff --git a/lib/models/flight.py b/lib/models/flight.py index 61343cc..ab945ec 100644 --- a/lib/models/flight.py +++ b/lib/models/flight.py @@ -9,3 +9,7 @@ class Flight(BaseModel, frozen=True): inclination: int = 85 heading: int = 0 rail_length: float = 5.2 + + @property + def flight_id(self) -> str: + return str(hash(self)) diff --git a/lib/models/motor.py b/lib/models/motor.py index 950f6cd..22a9af2 100644 --- a/lib/models/motor.py +++ b/lib/models/motor.py @@ -11,25 +11,25 @@ class MotorKinds(str, Enum): - hybrid: str = "Hybrid" - solid: str = "Solid" - liquid: str = "Liquid" + HYBRID: str = "HYBRID" + SOLID: str = "SOLID" + LIQUID: str = "LIQUID" class MotorEngines(str, Enum): - cesaroni: str = "Cesaroni_M1670" - custom: str = "Custom" + CESARONI: str = "CESARONI_M1670" + CUSTOM: str = "CUSTOM" class TankKinds(str, Enum): - level: str = "Level" - mass: str = "Mass" - mass_flow: str = "MassFlow" - ullage: str = "Ullage" + LEVEL: str = "LEVEL" + MASS: str = "MASS" + MASS_FLOW: str = "MASSFlOW" + ULLAGE: str = "ULLAGE" class TankFluids(BaseModel, frozen=True): - name: str = "FluidName" + name: str = "FLUIDNAME" density: float = 100.0 @@ -39,7 +39,7 @@ class MotorTank(BaseModel, frozen=True): ((0, 5), 1), ((5, 10), 2), ] - tank_kind: TankKinds = TankKinds.mass_flow + tank_kind: TankKinds = TankKinds.MASS_FLOW gas: TankFluids = TankFluids() liquid: TankFluids = TankFluids() name: str = "Tank" @@ -81,7 +81,7 @@ def __init__(self, **kwargs): liquid_mass=self.liquid_mass, gas_mass=self.gas_mass, ) - case TankKinds.mass_flow: + case TankKinds.MASS_FLOW: tank = MassFlowRateBasedTank( **tank_core, gas_mass_flow_rate_in=self.gas_mass_flow_rate_in, @@ -136,6 +136,10 @@ def __init__(self, motor_kind=MotorKinds.solid, **kwargs): def motor_kind(self) -> MotorKinds: return self._motor_kind + @property + def motor_id(self) -> str: + return str(hash(self)) + def __hash__(self): temp = vars(self) temp = str(temp) diff --git a/lib/models/rocket.py b/lib/models/rocket.py index b3fba5f..b78e1b6 100644 --- a/lib/models/rocket.py +++ b/lib/models/rocket.py @@ -7,8 +7,8 @@ class RocketOptions(str, Enum): - CALISTO: str = "Calisto" - CUSTOM: str = "Custom" + CALISTO: str = "CALISTO" + CUSTOM: str = "CUSTOM" class Rocket(BaseModel, frozen=True): @@ -48,6 +48,10 @@ def __init__(self, rocket_option=RocketOptions.CALISTO, **kwargs): def rocket_option(self) -> RocketOptions: return self._rocket_option + @property + def rocket_id(self) -> str: + return str(hash(self)) + def __hash__(self): temp = vars(self) temp = str(temp)