Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/controllers/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ async def get_rocketpy_environment_binary(
Raises:
HTTP 404 Not Found: If the env is not found in the database.
"""
env_retrieved = await self.get_environment_by_id(env_id)
env_service = EnvironmentService.from_env_model(
env_retrieved.environment
)
env = await self.get_environment_by_id(env_id)
env_service = EnvironmentService.from_env_model(env.environment)
return env_service.get_environment_binary()

@controller_exception_handler
Expand All @@ -58,8 +56,6 @@ async def get_environment_simulation(
Raises:
HTTP 404 Not Found: If the env does not exist in the database.
"""
env_retrieved = await self.get_environment_by_id(env_id)
env_service = EnvironmentService.from_env_model(
env_retrieved.environment
)
env = await self.get_environment_by_id(env_id)
env_service = EnvironmentService.from_env_model(env.environment)
return env_service.get_environment_simulation()
12 changes: 4 additions & 8 deletions src/controllers/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ async def get_rocketpy_flight_binary(
Raises:
HTTP 404 Not Found: If the flight is not found in the database.
"""
flight_retrieved = await self.get_flight_by_id(flight_id)
flight_service = FlightService.from_flight_model(
flight_retrieved.flight
)
flight = await self.get_flight_by_id(flight_id)
flight_service = FlightService.from_flight_model(flight.flight)
return flight_service.get_flight_binary()

@controller_exception_handler
Expand All @@ -105,8 +103,6 @@ async def get_flight_simulation(
Raises:
HTTP 404 Not Found: If the flight does not exist in the database.
"""
flight_retrieved = await self.get_flight_by_id(flight_id=flight_id)
flight_service = FlightService.from_flight_model(
flight_retrieved.flight
)
flight = await self.get_flight_by_id(flight_id)
flight_service = FlightService.from_flight_model(flight.flight)
return flight_service.get_flight_simulation()
8 changes: 4 additions & 4 deletions src/controllers/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ async def get_rocketpy_motor_binary(
Raises:
HTTP 404 Not Found: If the motor is not found in the database.
"""
motor_retrieved = await self.get_motor_by_id(motor_id)
motor_service = MotorService.from_motor_model(motor_retrieved.motor)
motor = await self.get_motor_by_id(motor_id)
motor_service = MotorService.from_motor_model(motor.motor)
return motor_service.get_motor_binary()

@controller_exception_handler
Expand All @@ -54,6 +54,6 @@ async def get_motor_simulation(self, motor_id: str) -> MotorSimulation:
Raises:
HTTP 404 Not Found: If the motor does not exist in the database.
"""
motor_retrieved = await self.get_motor_by_id(motor_id)
motor_service = MotorService.from_motor_model(motor_retrieved.motor)
motor = await self.get_motor_by_id(motor_id)
motor_service = MotorService.from_motor_model(motor.motor)
return motor_service.get_motor_simulation()
12 changes: 4 additions & 8 deletions src/controllers/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ async def get_rocketpy_rocket_binary(self, rocket_id: str) -> bytes:
Raises:
HTTP 404 Not Found: If the rocket is not found in the database.
"""
rocket_retrieved = await self.get_rocket_by_id(rocket_id)
rocket_service = RocketService.from_rocket_model(
rocket_retrieved.rocket
)
rocket = await self.get_rocket_by_id(rocket_id)
rocket_service = RocketService.from_rocket_model(rocket.rocket)
return rocket_service.get_rocket_binary()

@controller_exception_handler
Expand All @@ -56,8 +54,6 @@ async def get_rocket_simulation(
Raises:
HTTP 404 Not Found: If the rocket does not exist in the database.
"""
rocket_retrieved = await self.get_rocket_by_id(rocket_id)
rocket_service = RocketService.from_rocket_model(
rocket_retrieved.rocket
)
rocket = await self.get_rocket_by_id(rocket_id)
rocket_service = RocketService.from_rocket_model(rocket.rocket)
return rocket_service.get_rocket_simulation()
1 change: 1 addition & 0 deletions src/models/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def get_additional_parameters(self):
if value is not None
and key
not in [
"flight_id",
"name",
"environment",
"rocket",
Expand Down
9 changes: 8 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def to_python_primitive(v: Any) -> Any:

Args:
v: Any value, particularly those with a 'source' attribute
containing numpy arrays or generic types.
containing numpy arrays or generic types.

Returns:
The primitive representation of the input value.
Expand All @@ -29,6 +29,13 @@ def to_python_primitive(v: Any) -> Any:
return v.source.item()

return str(v.source)

if isinstance(v, (np.generic,)):
return v.item()

if isinstance(v, (np.ndarray,)):
return v.tolist()

return str(v)


Expand Down