@@ -37,6 +37,93 @@ def rocketpy_encoder(obj):
3737 return json .loads (json_str )
3838
3939
40+ def collect_simulation_attributes (flight_obj , flight_simulation_class , rocket_simulation_class , motor_simulation_class , environment_simulation_class ):
41+ """
42+ Collect attributes from various simulation classes and populate them from the flight object.
43+
44+ Args:
45+ flight_obj: RocketPy Flight object
46+ flight_simulation_class: FlightSimulation class
47+ rocket_simulation_class: RocketSimulation class
48+ motor_simulation_class: MotorSimulation class
49+ environment_simulation_class: EnvironmentSimulation class
50+
51+ Returns:
52+ Dictionary with all collected attributes
53+ """
54+ attributes = rocketpy_encoder (flight_obj )
55+
56+ flight_attributes_list = [
57+ attr for attr in flight_simulation_class .__annotations__ .keys ()
58+ if attr not in ['message' , 'rocket' , 'env' ]
59+ ]
60+
61+ rocket_attributes_list = [
62+ attr for attr in rocket_simulation_class .__annotations__ .keys ()
63+ if attr not in ['message' , 'motor' ]
64+ ]
65+
66+ motor_attributes_list = [
67+ attr for attr in motor_simulation_class .__annotations__ .keys ()
68+ if attr not in ['message' ]
69+ ]
70+
71+ environment_attributes_list = [
72+ attr for attr in environment_simulation_class .__annotations__ .keys ()
73+ if attr not in ['message' ]
74+ ]
75+
76+ try :
77+ for key in flight_attributes_list :
78+ try :
79+ value = getattr (flight_obj , key )
80+ attributes [key ] = value
81+ except AttributeError as e :
82+ logger .warning (f"Flight attribute '{ key } ' not found: { e } " )
83+ except Exception as e :
84+ logger .error (f"Error getting flight attribute '{ key } ': { type (e ).__name__ } : { e } " )
85+ except Exception as e :
86+ logger .error (f"Error processing flight attributes: { type (e ).__name__ } : { e } " )
87+
88+ try :
89+ for key in rocket_attributes_list :
90+ try :
91+ value = getattr (flight_obj .rocket , key )
92+ attributes ["rocket" ][key ] = value
93+ except AttributeError as e :
94+ logger .warning (f"Rocket attribute '{ key } ' not found: { e } " )
95+ except Exception as e :
96+ logger .error (f"Error getting rocket attribute '{ key } ': { type (e ).__name__ } : { e } " )
97+ except Exception as e :
98+ logger .error (f"Error processing rocket attributes: { type (e ).__name__ } : { e } " )
99+
100+ try :
101+ for key in motor_attributes_list :
102+ try :
103+ value = getattr (flight_obj .rocket .motor , key )
104+ attributes ["rocket" ]["motor" ][key ] = value
105+ except AttributeError as e :
106+ logger .warning (f"Motor attribute '{ key } ' not found: { e } " )
107+ except Exception as e :
108+ logger .error (f"Error getting motor attribute '{ key } ': { type (e ).__name__ } : { e } " )
109+ except Exception as e :
110+ logger .error (f"Error processing motor attributes: { type (e ).__name__ } : { e } " )
111+
112+ try :
113+ for key in environment_attributes_list :
114+ try :
115+ value = getattr (flight_obj .env , key )
116+ attributes ["env" ][key ] = value
117+ except AttributeError as e :
118+ logger .warning (f"Environment attribute '{ key } ' not found: { e } " )
119+ except Exception as e :
120+ logger .error (f"Error getting environment attribute '{ key } ': { type (e ).__name__ } : { e } " )
121+ except Exception as e :
122+ logger .error (f"Error processing environment attributes: { type (e ).__name__ } : { e } " )
123+
124+ return rocketpy_encoder (attributes )
125+
126+
40127class RocketPyGZipMiddleware :
41128 def __init__ (
42129 self , app : ASGIApp , minimum_size : int = 500 , compresslevel : int = 9
0 commit comments