Skip to content

Commit a6f2531

Browse files
Fixes runtime errors
1 parent 74733c0 commit a6f2531

File tree

9 files changed

+33
-30
lines changed

9 files changed

+33
-30
lines changed

lib/controllers/environment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ControllerInterface,
33
controller_exception_handler,
44
)
5-
from lib.views.environment import EnvSummary
5+
from lib.views.environment import EnvironmentSummary
66
from lib.models.environment import EnvironmentModel
77
from lib.services.environment import EnvironmentService
88

@@ -43,15 +43,15 @@ async def get_rocketpy_env_binary(
4343
@controller_exception_handler
4444
async def simulate_env(
4545
self, env_id: str
46-
) -> EnvSummary:
46+
) -> EnvironmentSummary:
4747
"""
4848
Simulate a rocket environment.
4949
5050
Args:
5151
env_id: str.
5252
5353
Returns:
54-
EnvSummary
54+
EnvironmentSummary
5555
5656
Raises:
5757
HTTP 404 Not Found: If the env does not exist in the database.

lib/models/motor.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
from enum import Enum
12
from typing import Optional, Tuple, List, Union, Self, ClassVar
23
from pydantic import PrivateAttr, model_validator
34

45
from lib.models.interface import ApiBaseModel
5-
from lib.models.sub.tanks import MotorTank, TankFluids, TankKinds, InterpolationMethods, TankCoordinateSystemOrientation, MotorKinds, MotorTank
6+
from lib.models.sub.tanks import MotorTank, TankFluids, TankKinds, InterpolationMethods, TankCoordinateSystemOrientation, MotorTank
7+
8+
9+
class MotorKinds(str, Enum):
10+
HYBRID: str = "HYBRID"
11+
SOLID: str = "SOLID"
12+
GENERIC: str = "GENERIC"
13+
LIQUID: str = "LIQUID"
614

715

816
class MotorModel(ApiBaseModel):

lib/models/sub/tanks.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
from pydantic import BaseModel
44

55

6-
class MotorKinds(str, Enum):
7-
HYBRID: str = "HYBRID"
8-
SOLID: str = "SOLID"
9-
GENERIC: str = "GENERIC"
10-
LIQUID: str = "LIQUID"
11-
12-
136
class TankKinds(str, Enum):
147
LEVEL: str = "LEVEL"
158
MASS: str = "MASS"

lib/routes/flight.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
FlightUpdated,
1313
FlightDeleted,
1414
)
15-
from lib.models.environment import Env
15+
from lib.models.environment import EnvironmentModel
1616
from lib.models.flight import FlightModel
17-
from lib.models.rocket import Rocket
17+
from lib.models.rocket import RocketModel
1818
from lib.models.motor import MotorKinds
1919
from lib.controllers.flight import FlightController
2020

@@ -121,7 +121,7 @@ async def read_rocketpy_flight(flight_id: str):
121121

122122

123123
@router.put("/{flight_id}/env")
124-
async def update_flight_env(flight_id: str, env: Env) -> FlightUpdated:
124+
async def update_flight_env(flight_id: str, env: EnvironmentModel) -> FlightUpdated:
125125
"""
126126
Updates flight environment
127127
@@ -141,7 +141,7 @@ async def update_flight_env(flight_id: str, env: Env) -> FlightUpdated:
141141
@router.put("/{flight_id}/rocket")
142142
async def update_flight_rocket(
143143
flight_id: str,
144-
rocket: Rocket,
144+
rocket: RocketModel,
145145
motor_kind: MotorKinds,
146146
) -> FlightUpdated:
147147
"""
@@ -150,7 +150,7 @@ async def update_flight_rocket(
150150
## Args
151151
```
152152
flight_id: Flight ID
153-
rocket: Rocket object as JSON
153+
rocket: RocketModel object as JSON
154154
```
155155
"""
156156
with tracer.start_as_current_span("update_flight_rocket"):

lib/services/environment.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from rocketpy.environment.environment import Environment as RocketPyEnvironment
66
from rocketpy.utilities import get_instance_attributes
7-
from lib.models.environment import Env
8-
from lib.views.environment import EnvSummary
7+
from lib.models.environment import EnvironmentModel
8+
from lib.views.environment import EnvironmentSummary
99

1010

1111
class EnvironmentService:
@@ -15,7 +15,7 @@ def __init__(self, environment: RocketPyEnvironment = None):
1515
self._environment = environment
1616

1717
@classmethod
18-
def from_env_model(cls, env: Env) -> Self:
18+
def from_env_model(cls, env: EnvironmentModel) -> Self:
1919
"""
2020
Get the rocketpy env object.
2121
@@ -42,16 +42,16 @@ def environment(self) -> RocketPyEnvironment:
4242
def environment(self, environment: RocketPyEnvironment):
4343
self._environment = environment
4444

45-
def get_env_summary(self) -> EnvSummary:
45+
def get_env_summary(self) -> EnvironmentSummary:
4646
"""
4747
Get the summary of the environment.
4848
4949
Returns:
50-
EnvSummary
50+
EnvironmentSummary
5151
"""
5252

5353
attributes = get_instance_attributes(self.environment)
54-
env_summary = EnvSummary(**attributes)
54+
env_summary = EnvironmentSummary(**attributes)
5555
return env_summary
5656

5757
def get_env_binary(self) -> bytes:

lib/views/environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional, Any
22
from datetime import datetime, timedelta
3-
from pydantic import ApiBaseView, ConfigDict
3+
from pydantic import ConfigDict
4+
from lib.views.interface import ApiBaseView
45
from lib.models.environment import AtmosphericModelTypes, EnvironmentModel
56
from lib.utils import to_python_primitive
67

lib/views/flight.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from lib.models.flight import FlightModel
44
from lib.views.interface import ApiBaseView
55
from lib.views.rocket import RocketView, RocketSummary
6-
from lib.views.environment import EnvSummary
6+
from lib.views.environment import EnvironmentSummary
77
from lib.utils import to_python_primitive
88

99

10-
class FlightSummary(RocketSummary, EnvSummary):
10+
class FlightSummary(RocketSummary, EnvironmentSummary):
1111
name: Optional[str] = None
1212
max_time: Optional[int] = None
1313
min_time_step: Optional[int] = None

lib/views/motor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import List, Any, Optional
22
from pydantic import BaseModel, ConfigDict
33
from lib.views.interface import ApiBaseView
4-
from lib.models.sub.motor import MotorModel, MotorKinds, MotorCoordinateSystemOrientation
4+
from lib.models.sub.tanks import TankCoordinateSystemOrientation
5+
from lib.models.motor import MotorModel, MotorKinds
56
from lib.utils import to_python_primitive
67

78

@@ -12,7 +13,7 @@ class MotorSummary(BaseModel):
1213
burn_start_time: Optional[float] = None
1314
center_of_dry_mass_position: Optional[float] = None
1415
coordinate_system_orientation: str = (
15-
MotorCoordinateSystemOrientation.NOZZLE_TO_COMBUSTION_CHAMBER.value
16+
TankCoordinateSystemOrientation.NOZZLE_TO_COMBUSTION_CHAMBER.value
1617
)
1718
dry_I_11: Optional[float] = None
1819
dry_I_12: Optional[float] = None

tests/test_routes/test_environments_route.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
EnvCreated,
1010
EnvUpdated,
1111
EnvDeleted,
12-
EnvSummary,
12+
EnvironmentSummary,
1313
)
1414
from lib import app
1515

@@ -18,7 +18,7 @@
1818

1919
@pytest.fixture
2020
def stub_env_summary():
21-
env_summary = EnvSummary()
21+
env_summary = EnvironmentSummary()
2222
env_summary_json = env_summary.model_dump_json()
2323
return json.loads(env_summary_json)
2424

@@ -190,7 +190,7 @@ def test_simulate_env(stub_env_summary):
190190
with patch.object(
191191
EnvController,
192192
'simulate_env',
193-
return_value=EnvSummary(**stub_env_summary),
193+
return_value=EnvironmentSummary(**stub_env_summary),
194194
) as mock_simulate_env:
195195
response = client.get('/environments/123/summary')
196196
assert response.status_code == 200

0 commit comments

Comments
 (0)