Skip to content

Commit 655c3f2

Browse files
blackify project
1 parent f3249a8 commit 655c3f2

File tree

11 files changed

+248
-93
lines changed

11 files changed

+248
-93
lines changed

lib/api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
This is the main API file for the RocketPy API.
33
"""
4+
45
import logging
56

67
from fastapi import FastAPI, Request, status
@@ -79,7 +80,9 @@ async def __perform_healthcheck():
7980

8081
# Errors
8182
@app.exception_handler(RequestValidationError)
82-
async def validation_exception_handler(request: Request, exc: RequestValidationError):
83+
async def validation_exception_handler(
84+
request: Request, exc: RequestValidationError
85+
):
8386
exc_str = f"{exc}".replace("\n", " ").replace(" ", " ")
8487
logging.error(f"{request}: {exc_str}")
8588
content = {"status_code": 10422, "message": exc_str, "data": None}

lib/controllers/flight.py

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ class FlightController:
5151
"""
5252

5353
def __init__(
54-
self, flight: Flight, rocket_option: RocketOptions, motor_kind: MotorKinds
54+
self,
55+
flight: Flight,
56+
rocket_option: RocketOptions,
57+
motor_kind: MotorKinds,
5558
):
5659
rocketpy_rocket = RocketController(
5760
flight.rocket, rocket_option=rocket_option, motor_kind=motor_kind
@@ -110,7 +113,8 @@ async def get_flight(flight_id: int) -> "Union[Flight, HTTPException]":
110113
).get_flight()
111114
if not successfully_read_flight:
112115
raise HTTPException(
113-
status_code=status.HTTP_404_NOT_FOUND, detail="Flight not found."
116+
status_code=status.HTTP_404_NOT_FOUND,
117+
detail="Flight not found.",
114118
)
115119

116120
return successfully_read_flight
@@ -136,13 +140,18 @@ async def get_rocketpy_flight(
136140
).get_flight()
137141
if not successfully_read_flight:
138142
raise HTTPException(
139-
status_code=status.HTTP_404_NOT_FOUND, detail="Flight not found."
143+
status_code=status.HTTP_404_NOT_FOUND,
144+
detail="Flight not found.",
140145
)
141146

142147
successfully_read_rocketpy_flight = FlightController(
143148
flight=successfully_read_flight,
144-
rocket_option=RocketOptions(successfully_read_flight.rocket._rocket_option),
145-
motor_kind=MotorKinds(successfully_read_flight.rocket.motor._motor_kind),
149+
rocket_option=RocketOptions(
150+
successfully_read_flight.rocket._rocket_option
151+
),
152+
motor_kind=MotorKinds(
153+
successfully_read_flight.rocket.motor._motor_kind
154+
),
146155
).rocketpy_flight
147156

148157
return FlightPickle(
@@ -171,12 +180,15 @@ async def update_flight(
171180
).get_flight()
172181
if not successfully_read_flight:
173182
raise HTTPException(
174-
status_code=status.HTTP_404_NOT_FOUND, detail="Flight not found."
183+
status_code=status.HTTP_404_NOT_FOUND,
184+
detail="Flight not found.",
175185
)
176186

177187
successfully_updated_flight = await FlightRepository(
178188
flight=self.flight, flight_id=flight_id
179-
).update_flight(rocket_option=self.rocket_option, motor_kind=self.motor_kind)
189+
).update_flight(
190+
rocket_option=self.rocket_option, motor_kind=self.motor_kind
191+
)
180192
if not successfully_updated_flight:
181193
raise HTTPException(
182194
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
@@ -207,7 +219,8 @@ async def update_env(
207219
).get_flight()
208220
if not successfully_read_flight:
209221
raise HTTPException(
210-
status_code=status.HTTP_404_NOT_FOUND, detail="Flight not found."
222+
status_code=status.HTTP_404_NOT_FOUND,
223+
detail="Flight not found.",
211224
)
212225

213226
flight = successfully_read_flight.dict()
@@ -246,7 +259,8 @@ async def update_rocket(
246259
).get_flight()
247260
if not successfully_read_flight:
248261
raise HTTPException(
249-
status_code=status.HTTP_404_NOT_FOUND, detail="Flight not found."
262+
status_code=status.HTTP_404_NOT_FOUND,
263+
detail="Flight not found.",
250264
)
251265

252266
flight = successfully_read_flight.dict()
@@ -267,7 +281,9 @@ async def update_rocket(
267281
return FlightUpdated(new_flight_id=str(successfully_updated_flight))
268282

269283
@staticmethod
270-
async def delete_flight(flight_id: int) -> "Union[FlightDeleted, HTTPException]":
284+
async def delete_flight(
285+
flight_id: int,
286+
) -> "Union[FlightDeleted, HTTPException]":
271287
"""
272288
Delete a flight from the database.
273289
@@ -285,7 +301,8 @@ async def delete_flight(flight_id: int) -> "Union[FlightDeleted, HTTPException]"
285301
).get_flight()
286302
if not successfully_read_flight:
287303
raise HTTPException(
288-
status_code=status.HTTP_404_NOT_FOUND, detail="Flight not found."
304+
status_code=status.HTTP_404_NOT_FOUND,
305+
detail="Flight not found.",
289306
)
290307

291308
successfully_deleted_flight = await FlightRepository(
@@ -300,7 +317,9 @@ async def delete_flight(flight_id: int) -> "Union[FlightDeleted, HTTPException]"
300317
return FlightDeleted(deleted_flight_id=str(flight_id))
301318

302319
@staticmethod
303-
async def simulate(flight_id: int) -> "Union[FlightSummary, HTTPException]":
320+
async def simulate(
321+
flight_id: int,
322+
) -> "Union[FlightSummary, HTTPException]":
304323
"""
305324
Simulate a rocket flight.
306325
@@ -318,7 +337,8 @@ async def simulate(flight_id: int) -> "Union[FlightSummary, HTTPException]":
318337
).get_flight()
319338
if not successfully_read_flight:
320339
raise HTTPException(
321-
status_code=status.HTTP_404_NOT_FOUND, detail="Flight not found."
340+
status_code=status.HTTP_404_NOT_FOUND,
341+
detail="Flight not found.",
322342
)
323343

324344
try:
@@ -351,7 +371,9 @@ async def simulate(flight_id: int) -> "Union[FlightSummary, HTTPException]":
351371
)
352372

353373
_numerical_integration_settings = NumericalIntegrationSettings(
354-
max_time="Maximum Allowed Flight Time: {:f} s".format(flight.max_time),
374+
max_time="Maximum Allowed Flight Time: {:f} s".format(
375+
flight.max_time
376+
),
355377
max_time_step="Maximum Allowed Time Step: {:f} s".format(
356378
flight.max_time_step
357379
),
@@ -371,11 +393,15 @@ async def simulate(flight_id: int) -> "Union[FlightSummary, HTTPException]":
371393
)
372394

373395
_launch_rail_conditions = LaunchRailConditions(
374-
rail_length="Launch Rail Length: {:.2f} m".format(flight.rail_length),
396+
rail_length="Launch Rail Length: {:.2f} m".format(
397+
flight.rail_length
398+
),
375399
flight_inclination="Launch Rail Inclination: {:.2f}°".format(
376400
flight.inclination
377401
),
378-
flight_heading="Launch Rail Heading: {:.2f}°".format(flight.heading),
402+
flight_heading="Launch Rail Heading: {:.2f}°".format(
403+
flight.heading
404+
),
379405
)
380406

381407
_surface_wind_conditions = SurfaceWindConditions(
@@ -413,17 +439,25 @@ async def simulate(flight_id: int) -> "Union[FlightSummary, HTTPException]":
413439
flight.rocket.motor.burn_out_time
414440
),
415441
burnout_altitude="Altitude at burn out: {:.3f} m (AGL)".format(
416-
flight.z(flight.rocket.motor.burn_out_time) - flight.env.elevation
442+
flight.z(flight.rocket.motor.burn_out_time)
443+
- flight.env.elevation
417444
),
418445
burnout_rocket_velocity="Rocket velocity at burn out: {:.3f} m/s".format(
419446
flight.speed(flight.rocket.motor.burn_out_time)
420447
),
421448
burnout_freestream_velocity="Freestream velocity at burn out: {:.3f} m/s".format(
422449
(
423-
flight.stream_velocity_x(flight.rocket.motor.burn_out_time) ** 2
424-
+ flight.stream_velocity_y(flight.rocket.motor.burn_out_time)
450+
flight.stream_velocity_x(
451+
flight.rocket.motor.burn_out_time
452+
)
453+
** 2
454+
+ flight.stream_velocity_y(
455+
flight.rocket.motor.burn_out_time
456+
)
425457
** 2
426-
+ flight.stream_velocity_z(flight.rocket.motor.burn_out_time)
458+
+ flight.stream_velocity_z(
459+
flight.rocket.motor.burn_out_time
460+
)
427461
** 2
428462
)
429463
** 0.5
@@ -457,14 +491,17 @@ async def simulate(flight_id: int) -> "Union[FlightSummary, HTTPException]":
457491
flight.max_reynolds_number, flight.max_reynolds_number_time
458492
),
459493
maximum_dynamic_pressure="Maximum Dynamic Pressure: {:.3e} Pa at {:.2f} s".format(
460-
flight.max_dynamic_pressure, flight.max_dynamic_pressure_time
494+
flight.max_dynamic_pressure,
495+
flight.max_dynamic_pressure_time,
461496
),
462497
maximum_acceleration_during_motor_burn="Maximum Acceleration During Motor Burn: {:.3f} m/s² at {:.2f} s".format(
463498
flight.max_acceleration, flight.max_acceleration_time
464499
),
465500
maximum_gs_during_motor_burn="Maximum Gs During Motor Burn: {:.3f} g at {:.2f} s".format(
466501
flight.max_acceleration
467-
/ flight.env.gravity(flight.z(flight.max_acceleration_time)),
502+
/ flight.env.gravity(
503+
flight.z(flight.max_acceleration_time)
504+
),
468505
flight.max_acceleration_time,
469506
),
470507
maximum_acceleration_after_motor_burn="Maximum Acceleration After Motor Burn: {:.3f} m/s² at {:.2f} s".format(
@@ -491,17 +528,25 @@ async def simulate(flight_id: int) -> "Union[FlightSummary, HTTPException]":
491528

492529
if len(flight.impact_state) != 0:
493530
_impact_conditions = ImpactConditions(
494-
x_impact_position="X Impact: {:.3f} m".format(flight.x_impact),
495-
y_impact_position="Y Impact: {:.3f} m".format(flight.y_impact),
496-
time_of_impact="Time of Impact: {:.3f} s".format(flight.t_final),
531+
x_impact_position="X Impact: {:.3f} m".format(
532+
flight.x_impact
533+
),
534+
y_impact_position="Y Impact: {:.3f} m".format(
535+
flight.y_impact
536+
),
537+
time_of_impact="Time of Impact: {:.3f} s".format(
538+
flight.t_final
539+
),
497540
impact_velocity="Velocity at Impact: {:.3f} m/s".format(
498541
flight.impact_velocity
499542
),
500543
)
501544
elif flight.terminate_on_apogee is False:
502545
_impact_conditions = ImpactConditions(
503546
time="Time: {:.3f} s".format(flight.solution[-1][0]),
504-
altitude="Altitude: {:.3f} m".format(flight.solution[-1][3]),
547+
altitude="Altitude: {:.3f} m".format(
548+
flight.solution[-1][3]
549+
),
505550
)
506551

507552
if len(flight.parachute_events) == 0:
@@ -519,10 +564,14 @@ async def simulate(flight_id: int) -> "Union[FlightSummary, HTTPException]":
519564
name = parachute.name.title()
520565
events[name] = []
521566
events[name].append(
522-
name + " Ejection Triggered at: {:.3f} s".format(trigger_time)
567+
name
568+
+ " Ejection Triggered at: {:.3f} s".format(
569+
trigger_time
570+
)
523571
)
524572
events[name].append(
525-
name + " Parachute Inflated at: {:.3f} s".format(open_time)
573+
name
574+
+ " Parachute Inflated at: {:.3f} s".format(open_time)
526575
)
527576
events[name].append(
528577
name

lib/controllers/motor.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,21 @@ async def get_motor(motor_id: int) -> "Union[Motor, HTTPException]":
116116
Raises:
117117
HTTP 404 Not Found: If the motor is not found in the database.
118118
"""
119-
successfully_read_motor = await MotorRepository(motor_id=motor_id).get_motor()
119+
successfully_read_motor = await MotorRepository(
120+
motor_id=motor_id
121+
).get_motor()
120122
if not successfully_read_motor:
121123
raise HTTPException(
122-
status_code=status.HTTP_404_NOT_FOUND, detail="Motor not found."
124+
status_code=status.HTTP_404_NOT_FOUND,
125+
detail="Motor not found.",
123126
)
124127

125128
return successfully_read_motor
126129

127130
@staticmethod
128-
async def get_rocketpy_motor(motor_id: int) -> "Union[MotorPickle, HTTPException]":
131+
async def get_rocketpy_motor(
132+
motor_id: int,
133+
) -> "Union[MotorPickle, HTTPException]":
129134
"""
130135
Get a rocketpy motor object encoded as jsonpickle string from the database.
131136
@@ -138,10 +143,13 @@ async def get_rocketpy_motor(motor_id: int) -> "Union[MotorPickle, HTTPException
138143
Raises:
139144
HTTP 404 Not Found: If the motor is not found in the database.
140145
"""
141-
successfully_read_motor = await MotorRepository(motor_id=motor_id).get_motor()
146+
successfully_read_motor = await MotorRepository(
147+
motor_id=motor_id
148+
).get_motor()
142149
if not successfully_read_motor:
143150
raise HTTPException(
144-
status_code=status.HTTP_404_NOT_FOUND, detail="Motor not found."
151+
status_code=status.HTTP_404_NOT_FOUND,
152+
detail="Motor not found.",
145153
)
146154

147155
successfully_read_rocketpy_motor = MotorController(
@@ -155,7 +163,9 @@ async def get_rocketpy_motor(motor_id: int) -> "Union[MotorPickle, HTTPException
155163
)
156164
)
157165

158-
async def update_motor(self, motor_id: int) -> "Union[MotorUpdated, HTTPException]":
166+
async def update_motor(
167+
self, motor_id: int
168+
) -> "Union[MotorUpdated, HTTPException]":
159169
"""
160170
Update a motor in the database.
161171
@@ -168,10 +178,13 @@ async def update_motor(self, motor_id: int) -> "Union[MotorUpdated, HTTPExceptio
168178
Raises:
169179
HTTP 404 Not Found: If the motor is not found in the database.
170180
"""
171-
successfully_read_motor = await MotorRepository(motor_id=motor_id).get_motor()
181+
successfully_read_motor = await MotorRepository(
182+
motor_id=motor_id
183+
).get_motor()
172184
if not successfully_read_motor:
173185
raise HTTPException(
174-
status_code=status.HTTP_404_NOT_FOUND, detail="Motor not found."
186+
status_code=status.HTTP_404_NOT_FOUND,
187+
detail="Motor not found.",
175188
)
176189

177190
successfully_updated_motor = await MotorRepository(
@@ -186,7 +199,9 @@ async def update_motor(self, motor_id: int) -> "Union[MotorUpdated, HTTPExceptio
186199
return MotorUpdated(new_motor_id=str(successfully_updated_motor))
187200

188201
@staticmethod
189-
async def delete_motor(motor_id: int) -> "Union[MotorDeleted, HTTPException]":
202+
async def delete_motor(
203+
motor_id: int,
204+
) -> "Union[MotorDeleted, HTTPException]":
190205
"""
191206
Delete a motor from the database.
192207
@@ -199,10 +214,13 @@ async def delete_motor(motor_id: int) -> "Union[MotorDeleted, HTTPException]":
199214
Raises:
200215
HTTP 404 Not Found: If the motor is not found in the database.
201216
"""
202-
successfully_read_motor = await MotorRepository(motor_id=motor_id).get_motor()
217+
successfully_read_motor = await MotorRepository(
218+
motor_id=motor_id
219+
).get_motor()
203220
if not successfully_read_motor:
204221
raise HTTPException(
205-
status_code=status.HTTP_404_NOT_FOUND, detail="Motor not found."
222+
status_code=status.HTTP_404_NOT_FOUND,
223+
detail="Motor not found.",
206224
)
207225

208226
successfully_deleted_motor = await MotorRepository(
@@ -230,10 +248,13 @@ async def simulate(motor_id: int) -> "Union[MotorSummary, HTTPException]":
230248
Raises:
231249
HTTP 404 Not Found: If the motor does not exist in the database.
232250
"""
233-
successfully_read_motor = await MotorRepository(motor_id=motor_id).get_motor()
251+
successfully_read_motor = await MotorRepository(
252+
motor_id=motor_id
253+
).get_motor()
234254
if not successfully_read_motor:
235255
raise HTTPException(
236-
status_code=status.HTTP_404_NOT_FOUND, detail="Motor not found."
256+
status_code=status.HTTP_404_NOT_FOUND,
257+
detail="Motor not found.",
237258
)
238259

239260
try:
@@ -249,7 +270,9 @@ async def simulate(motor_id: int) -> "Union[MotorSummary, HTTPException]":
249270
+ "{:.3f}".format(motor.propellant_initial_mass)
250271
+ " kg",
251272
average_propellant_exhaust_velocity="Average Propellant Exhaust Velocity: "
252-
+ "{:.3f}".format(motor.exhaust_velocity.average(*motor.burn_time))
273+
+ "{:.3f}".format(
274+
motor.exhaust_velocity.average(*motor.burn_time)
275+
)
253276
+ " m/s",
254277
average_thrust="Average Thrust: "
255278
+ "{:.3f}".format(motor.average_thrust)

0 commit comments

Comments
 (0)