Skip to content

Commit f36f866

Browse files
Merge pull request #324 from RocketPy-Team/maint/extract-logic-prints
ENH: Parachute.info() method created
2 parents 32e8af6 + 801d22e commit f36f866

4 files changed

Lines changed: 125 additions & 23 deletions

File tree

rocketpy/Parachute.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
__author__ = "Giovani Hidalgo Ceotto, Franz Masatoshi Yuri"
1+
__author__ = "Giovani Hidalgo Ceotto, Franz Masatoshi Yuri, Guilherme Fernandes Alves"
22
__copyright__ = "Copyright 20XX, RocketPy Team"
33
__license__ = "MIT"
44

55
import numpy as np
66

77
from .Function import Function
88

9+
from .prints.parachute_prints import _ParachutePrints
10+
911

1012
class Parachute:
1113
"""Keeps parachute information.
@@ -117,4 +119,36 @@ def __init__(
117119
self.noiseFunction = lambda: alpha * self.noiseSignal[-1][
118120
1
119121
] + beta * np.random.normal(noise[0], noise[1])
122+
123+
self.prints = _ParachutePrints(self)
124+
125+
return None
126+
127+
def __str__(self):
128+
"""Returns a string representation of the Parachute class.
129+
Parameters
130+
----------
131+
None
132+
133+
Returns
134+
-------
135+
string
136+
String representation of Parachute class. It is human readable.
137+
"""
138+
return "Parachute {} with a CdS of {:.4f} m2".format(
139+
self.name.title(),
140+
self.CdS,
141+
)
142+
143+
def info(self):
144+
145+
self.prints.all()
146+
147+
return None
148+
149+
def allInfo(self):
150+
151+
self.info()
152+
# self.plots.all() # Parachutes still doesn't have plots
153+
120154
return None

rocketpy/prints/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from .flight_prints import _FlightPrints
1+
from .compare_prints import _ComparePrints
22
from .environment_prints import _EnvironmentPrints
3+
from .flight_prints import _FlightPrints
4+
from .parachute_prints import _ParachutePrints
35
from .rocket_prints import _RocketPrints
4-
from .compare_prints import _ComparePrints
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
__author__ = "Guilherme Fernandes Alves"
2+
__copyright__ = "Copyright 20XX, RocketPy Team"
3+
__license__ = "MIT"
4+
5+
6+
class _ParachutePrints:
7+
"""Class that holds prints methods for Parachute class.
8+
9+
Attributes
10+
----------
11+
_ParachutePrints.parachute : rocketpy.Parachute
12+
Parachute object that will be used for the prints.
13+
14+
"""
15+
16+
def __init__(self, parachute) -> None:
17+
"""Initializes _ParachutePrints class
18+
19+
Parameters
20+
----------
21+
parachute: rocketpy.Parachute
22+
Instance of the Parachute class.
23+
24+
Returns
25+
-------
26+
None
27+
"""
28+
self.parachute = parachute
29+
30+
return None
31+
32+
def trigger(self):
33+
"""Prints trigger information.
34+
35+
Parameters
36+
----------
37+
None
38+
39+
Return
40+
------
41+
None
42+
"""
43+
44+
if self.parachute.trigger.__name__ == "<lambda>":
45+
line = self.rocket.getsourcelines(self.parachute.trigger)[0][0]
46+
print(
47+
"Ejection signal trigger: "
48+
+ line.split("lambda ")[1].split(",")[0].split("\n")[0]
49+
)
50+
else:
51+
print("Ejection signal trigger: " + self.parachute.trigger.__name__)
52+
53+
print(f"Ejection system refresh rate: {self.parachute.samplingRate:.3f} Hz")
54+
print(
55+
f"Time between ejection signal is triggered and the parachute is fully opened: {self.parachute.lag:.1f} s\n"
56+
)
57+
58+
return None
59+
60+
def noise(self):
61+
# Not implemented yet
62+
pass
63+
64+
def all(self):
65+
"""Prints all information about the parachute.
66+
67+
Parameters
68+
----------
69+
None
70+
71+
Return
72+
------
73+
None
74+
"""
75+
76+
print("\nParachute Details\n")
77+
print(self.parachute.__str__())
78+
self.trigger()
79+
self.noise()
80+
81+
return None

rocketpy/prints/rocket_prints.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__author__ = " "
1+
__author__ = "Mateus Stano Junqueira"
22
__copyright__ = "Copyright 20XX, RocketPy Team"
33
__license__ = "MIT"
44

@@ -8,7 +8,7 @@ class _RocketPrints:
88
99
Attributes
1010
----------
11-
_RocketPrints.environment : rocket
11+
_RocketPrints.rocket : rocket
1212
Rocket object that will be used for the prints.
1313
1414
"""
@@ -18,8 +18,8 @@ def __init__(self, rocket) -> None:
1818
1919
Parameters
2020
----------
21-
environment: Environment
22-
Instance of the Environment class.
21+
rocket: rocketpy.rocket
22+
Instance of the rocket class.
2323
2424
Returns
2525
-------
@@ -158,22 +158,8 @@ def parachute_data(self):
158158
None
159159
"""
160160
for chute in self.rocket.parachutes:
161-
print("\n" + chute.name.title() + " Parachute\n")
162-
print("CdS Coefficient: " + str(chute.CdS) + " m2")
163-
if chute.trigger.__name__ == "<lambda>":
164-
line = self.rocket.getsourcelines(chute.trigger)[0][0]
165-
print(
166-
"Ejection signal trigger: "
167-
+ line.split("lambda ")[1].split(",")[0].split("\n")[0]
168-
)
169-
else:
170-
print("Ejection signal trigger: " + chute.trigger.__name__)
171-
print("Ejection system refresh rate: " + str(chute.samplingRate) + " Hz.")
172-
print(
173-
"Time between ejection signal is triggered and the "
174-
"parachute is fully opened: " + str(chute.lag) + " s"
175-
)
176-
return None
161+
chute.allInfo()
162+
return None
177163

178164
def all(self):
179165
"""Prints all print methods about the Environment.

0 commit comments

Comments
 (0)