-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmotor.py
More file actions
83 lines (66 loc) · 2.34 KB
/
Copy pathmotor.py
File metadata and controls
83 lines (66 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from src.controllers.interface import (
ControllerBase,
controller_exception_handler,
)
from src.views.motor import MotorSimulation, MotorDrawingGeometryView
from src.models.motor import MotorModel
from src.services.motor import MotorService
class MotorController(ControllerBase):
"""
Controller for the motor model.
Enables:
- Simulation of a RocketPy Motor.
- CRUD for Motor BaseApiModel.
"""
def __init__(self):
super().__init__(models=[MotorModel])
@controller_exception_handler
async def get_rocketpy_motor_binary(
self,
motor_id: str,
) -> bytes:
"""
Get a rocketpy.Motor object as a dill binary.
Args:
motor_id: str
Returns:
bytes
Raises:
HTTP 404 Not Found: If the motor is not found in the database.
"""
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
async def get_motor_simulation(self, motor_id: str) -> MotorSimulation:
"""
Simulate a rocketpy motor.
Args:
motor_id: str
Returns:
views.MotorSimulation
Raises:
HTTP 404 Not Found: If the motor does not exist in the database.
"""
motor = await self.get_motor_by_id(motor_id)
motor_service = MotorService.from_motor_model(motor.motor)
return motor_service.get_motor_simulation()
@controller_exception_handler
async def get_motor_drawing_geometry(
self, motor_id: str
) -> MotorDrawingGeometryView:
"""
Build the motor-only drawing-geometry payload for a persisted motor.
Renders the motor at its own coordinate origin (motor_position=0,
parent_csys=1) so the playground can show a motor in isolation.
Args:
motor_id: str
Returns:
views.MotorDrawingGeometryView
Raises:
HTTP 404 Not Found: If the motor does not exist in the database.
HTTP 422: If the motor has no drawable geometry.
"""
motor = await self.get_motor_by_id(motor_id)
motor_service = MotorService.from_motor_model(motor.motor)
return motor_service.get_drawing_geometry()