diff --git a/Dockerfile b/Dockerfile index 2111d50..074269d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,4 +16,4 @@ RUN apt-get update && \ COPY ./src /app/src -CMD ["gunicorn", "-c", "src/settings/gunicorn.py", "-w", "1", "--threads=2", "-k", "uvicorn.workers.UvicornWorker", "src.api:app", "--log-level", "Debug", "-b", "0.0.0.0:3000", "--timeout", "60", "--loop", "uvloop"] +CMD ["gunicorn", "-c", "src/settings/gunicorn.py", "-w", "1", "--threads=2", "-k", "src.settings.gunicorn.UvloopUvicornWorker", "src.api:app", "--log-level", "Debug", "-b", "0.0.0.0:3000", "--timeout", "60"] diff --git a/README.md b/README.md index 709dc50..77ec01e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Infinity-API +[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/RocketPy-Team/Infinity-API) + ## Capabilities - Performs rocket simulations and returns simulation data - Stores simulation input data in mongo-db diff --git a/src/controllers/environment.py b/src/controllers/environment.py index 3b5b075..15deb0a 100644 --- a/src/controllers/environment.py +++ b/src/controllers/environment.py @@ -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 @@ -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() diff --git a/src/controllers/flight.py b/src/controllers/flight.py index ac8624a..9b30398 100644 --- a/src/controllers/flight.py +++ b/src/controllers/flight.py @@ -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 @@ -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() diff --git a/src/controllers/motor.py b/src/controllers/motor.py index e446cef..3483c1b 100644 --- a/src/controllers/motor.py +++ b/src/controllers/motor.py @@ -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 @@ -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() diff --git a/src/controllers/rocket.py b/src/controllers/rocket.py index a7dcb4d..f586ccc 100644 --- a/src/controllers/rocket.py +++ b/src/controllers/rocket.py @@ -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 @@ -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() diff --git a/src/models/flight.py b/src/models/flight.py index 44ac16a..93d36d4 100644 --- a/src/models/flight.py +++ b/src/models/flight.py @@ -34,6 +34,7 @@ def get_additional_parameters(self): if value is not None and key not in [ + "flight_id", "name", "environment", "rocket", diff --git a/src/settings/gunicorn.py b/src/settings/gunicorn.py index f2b92cd..7d3def1 100644 --- a/src/settings/gunicorn.py +++ b/src/settings/gunicorn.py @@ -1,5 +1,6 @@ import uptrace from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor +from uvicorn.workers import UvicornWorker from src.secrets import Secrets @@ -15,3 +16,7 @@ def post_fork(server, worker): # pylint: disable=unused-argument ) FastAPIInstrumentor.instrument_app(fastapi_server) + + +class UvloopUvicornWorker(UvicornWorker): + CONFIG_KWARGS = {"loop": "uvloop"} diff --git a/src/utils.py b/src/utils.py index 0a8ba45..d31d747 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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. @@ -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)