From 618fcffdff12e7b8f48c2a5ec9d99d0b9eba914a Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 15 Mar 2025 21:57:14 -0300 Subject: [PATCH 1/6] removes broken loop call --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2111d50..ce53e71 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", "uvicorn.workers.UvicornWorker", "src.api:app", "--log-level", "Debug", "-b", "0.0.0.0:3000", "--timeout", "60"] From e9b234561ee1d676a2cb98aaf98595721e11ac8a Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 15 Mar 2025 21:44:46 -0300 Subject: [PATCH 2/6] setup uvloop uvicorn worker --- Dockerfile | 2 +- src/settings/gunicorn.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ce53e71..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"] +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/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"} From 58ccdaed1a13705aed6745583c709a22736b884d Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 5 Apr 2025 11:47:14 -0300 Subject: [PATCH 3/6] fixes flight summary retrieval --- src/controllers/environment.py | 12 ++++-------- src/controllers/flight.py | 12 ++++-------- src/controllers/motor.py | 8 ++++---- src/controllers/rocket.py | 12 ++++-------- 4 files changed, 16 insertions(+), 28 deletions(-) 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() From 58be67e83ec348cfe75d270467c24bcc755fb93b Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 5 Apr 2025 11:53:06 -0300 Subject: [PATCH 4/6] removes flight_id from additional rocketpy flight invocation parameters --- src/models/flight.py | 1 + 1 file changed, 1 insertion(+) 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", From 65538e8490c14bd746f68f270205a68e2c42a058 Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 5 Apr 2025 17:31:15 -0300 Subject: [PATCH 5/6] fix data representation for flight summary --- src/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) From b944744c4df6ab6f2efb4e32d7779c2495c5341b Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 31 May 2025 19:53:35 -0300 Subject: [PATCH 6/6] Update README.md adds deepweek badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) 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