diff --git a/lib/api.py b/lib/api.py index 789c9e8..e6d0e16 100644 --- a/lib/api.py +++ b/lib/api.py @@ -14,8 +14,8 @@ from lib.views.motor import MotorSummary, MotorCreated, MotorUpdated, MotorDeleted, MotorPickle from lib.models.environment import Env from lib.models.flight import Flight -from lib.models.rocket import Rocket -from lib.models.motor import Motor +from lib.models.rocket import Rocket, RocketOptions +from lib.models.motor import Motor, MotorKinds, MotorOptions from lib.controllers.flight import FlightController from lib.controllers.environment import EnvController from lib.controllers.rocket import RocketController @@ -70,7 +70,7 @@ async def main_page(): # Flight routes @app.post("/flights/", tags=["FLIGHT"]) -async def create_flight(flight: Flight) -> "FlightCreated": +async def create_flight(flight: Flight, rocket_option: RocketOptions, motor_kind: MotorKinds, motor_options: MotorOptions) -> "FlightCreated": """ Creates a new flight. @@ -84,7 +84,7 @@ async def create_flight(flight: Flight) -> "FlightCreated": HTTP 422 Unprocessable Entity: If API is unable to parse flight data, usually happens when some parameter is invalid, please attend to API docs request specifications. HTTP 500 Internal Server Error: If API is either unable to create flight in mongoDB or valid parameter type/structure provided but content is breaking the API. """ - return await FlightController(flight).create_flight() + return await FlightController(flight).create_flight(rocket_option, motor_kind, motor_option) @app.get("/flights/{flight_id}", tags=["FLIGHT"]) async def read_flight(flight_id: int) -> "Flight": @@ -310,7 +310,7 @@ async def simulate_env(env_id: int) -> "EnvSummary": # Motor routes @app.post("/motors/", tags=["MOTOR"]) -async def create_motor(motor: Motor) -> "MotorCreated": +async def create_motor(motor: Motor, motor_kind: MotorKinds, motor_option: MotorOptions) -> "MotorCreated": """ Creates a new motor. @@ -324,7 +324,7 @@ async def create_motor(motor: Motor) -> "MotorCreated": HTTP 422 Unprocessable Entity: If API is unable to parse motor data, usually happens when some parameter is invalid, please attend to API docs request specifications. HTTP 500 Internal Server Error: If API is either unable to create motor in mongoDB or valid parameter type/structure provided but content is breaking the API. """ - return await MotorController(motor).create_motor() + return await MotorController(motor).create_motor(motor_kind, motor_option) @app.get("/motors/{motor_id}", tags=["MOTOR"]) async def read_motor(motor_id: int) -> "Motor": @@ -411,7 +411,7 @@ async def simulate_motor(motor_id: int) -> "MotorSummary": # Rocket routes @app.post("/rockets/", tags=["ROCKET"]) -async def create_rocket(rocket: Rocket) -> "RocketCreated": +async def create_rocket(rocket: Rocket, rocket_option: RocketOptions, motor_kind: MotorKinds, motor_option: MotorOptions) -> "RocketCreated": """ Creates a new rocket. @@ -425,7 +425,7 @@ async def create_rocket(rocket: Rocket) -> "RocketCreated": HTTP 422 Unprocessable Entity: If API is unable to parse rocket data, usually happens when some parameter is invalid, please attend to API docs request specifications. HTTP 500 Internal Server Error: If API is either unable to create rocket in mongoDB or valid parameter type/structure provided but content is breaking the API. """ - return await RocketController(rocket).create_rocket() + return await RocketController(rocket).create_rocket(rocket_option, motor_kind, motor_option) @app.get("/rockets/{rocket_id}", tags=["ROCKET"]) async def read_rocket(rocket_id: int) -> Rocket: diff --git a/lib/controllers/flight.py b/lib/controllers/flight.py index 2786d8c..b20395c 100644 --- a/lib/controllers/flight.py +++ b/lib/controllers/flight.py @@ -31,7 +31,7 @@ class FlightController(): - Read a RocketpyFlight object from the database. """ - def __init__(self, flight: Flight): + def __init__(self, flight: Flight, rocket_option, motor_kind, motor_option): rocketpy_rocket = RocketController(flight.rocket).rocketpy_rocket rocketpy_env = EnvController(flight.environment).rocketpy_env diff --git a/lib/controllers/motor.py b/lib/controllers/motor.py index 0219713..62950a2 100644 --- a/lib/controllers/motor.py +++ b/lib/controllers/motor.py @@ -17,7 +17,7 @@ class MotorController(): Enables: - Create a rocketpy.Motor object from a Motor model object. """ - def __init__(self, motor: Motor): + def __init__(self, motor: Motor, motor_kind, motor_option): rocketpy_motor = SolidMotor( burn_time=motor.burn_time, grain_number=motor.grain_number, diff --git a/lib/controllers/rocket.py b/lib/controllers/rocket.py index 29f870d..1107413 100644 --- a/lib/controllers/rocket.py +++ b/lib/controllers/rocket.py @@ -28,7 +28,7 @@ class RocketController(): Enables: create a RocketpyRocket object from a Rocket model object. """ - def __init__(self, rocket: Rocket): + def __init__(self, rocket: Rocket, rocket_option, motor_kind, motor_option): rocketpy_rocket = RocketpyRocket( radius=rocket.radius, mass=rocket.mass, diff --git a/lib/models/motor.py b/lib/models/motor.py index 84e2217..df91b13 100644 --- a/lib/models/motor.py +++ b/lib/models/motor.py @@ -4,7 +4,15 @@ class MotorOptions(str, Enum): cesaroni: str = "Cesaroni_M1670" - custom: str = "Custom (Coming soon)" + custom: str = "Custom" + +class MotorKinds(str, Enum): + hybrid: str = "Hybrid" + solid: str = "Solid" + liquid: str = "Liquid" + +class MotorEngine(BaseModel, frozen=True): + pass class Motor(BaseModel, frozen=True): burn_time: float = 3.9 @@ -18,7 +26,7 @@ class Motor(BaseModel, frozen=True): grain_initial_height: float = 0.12 grains_center_of_mass_position: float = -0.85704 #TBD: thrust_source must be the id of a previously uploaded .eng file and a list of "default" files must be provided in the api docs - thrust_source: MotorOptions = "Cesaroni_M1670" + thrust_source: MotorEngine = MotorEngine() grain_separation: float = 0.005 nozzle_radius: float = 0.033 throat_radius: float = 0.011 diff --git a/lib/models/rocket.py b/lib/models/rocket.py index 632b5bf..be8be80 100644 --- a/lib/models/rocket.py +++ b/lib/models/rocket.py @@ -6,16 +6,36 @@ from lib.models.parachute import Parachute class RocketOptions(str, Enum): - calisto: str = "calisto" - custom: str = "Custom (Coming soon)" + calisto: str = "Calisto" + custom: str = "Custom" class Rocket(BaseModel, frozen=True): radius: float = 0.0632 mass: float = 16.235 inertia: "Tuple[float, float, float]" = (6.321, 6.321, 0.0346) #TBD: powerOffDrag an powerOnDrag need to be the id of previously uploaded .csv files and a list of "default" files must be provided in the api docs - power_off_drag: RocketOptions = "calisto" - power_on_drag: RocketOptions = "calisto" + power_off_drag: "Tuple[Tuple[float, float]]" = ( + (0.01,0.333865758), + (0.02,0.394981721), + (0.03,0.407756063), + (0.04,0.410692705), + (0.05,0.410540353), + (0.06,0.409240293), + (0.07,0.407500874), + (0.08,0.405617853), + (0.09,0.403724114) + ) + power_on_drag: "Tuple[Tuple[float, float]]" = ( + (0.01,0.333865758), + (0.02,0.394981721), + (0.03,0.407756063), + (0.04,0.410692705), + (0.05,0.410540353), + (0.06,0.409240293), + (0.07,0.407500874), + (0.08,0.405617853), + (0.09,0.403724114) + ) center_of_mass_without_motor: int = 0 #TBD: a list of possible tailToNose values must be provided in the api docs coordinate_system_orientation: Optional[str] = "tail_to_nose"