-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathenvironment.py
More file actions
61 lines (49 loc) · 1.62 KB
/
environment.py
File metadata and controls
61 lines (49 loc) · 1.62 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
from src.controllers.interface import (
ControllerBase,
controller_exception_handler,
)
from src.views.environment import EnvironmentSimulation
from src.models.environment import EnvironmentModel
from src.services.environment import EnvironmentService
class EnvironmentController(ControllerBase):
"""
Controller for the Environment model.
Enables:
- Simulation of a RocketPy Environment.
- CRUD for Environment BaseApiModel.
"""
def __init__(self):
super().__init__(models=[EnvironmentModel])
@controller_exception_handler
async def get_rocketpy_environment_binary(
self,
env_id: str,
) -> bytes:
"""
Get rocketpy.Environmnet dill binary.
Args:
env_id: str
Returns:
bytes
Raises:
HTTP 404 Not Found: If the env is not found in the database.
"""
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
async def get_environment_simulation(
self, env_id: str
) -> EnvironmentSimulation:
"""
Simulate a rocket environment.
Args:
env_id: str.
Returns:
EnvironmentSimulation
Raises:
HTTP 404 Not Found: If the env does not exist in the database.
"""
env = await self.get_environment_by_id(env_id)
env_service = EnvironmentService.from_env_model(env.environment)
return env_service.get_environment_simulation()