Skip to content

Commit 77ee262

Browse files
authored
Merge pull request #8 from adamzev/6-import-style
chore: fix import styles (avoid import *)
2 parents b02909b + 313c35b commit 77ee262

12 files changed

+141
-203
lines changed

src/rocket/calc.py

+126-158
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,145 @@
1-
from generalEquations import *
2-
from libs.spec_creator import *
3-
from libs.rocketEngine import *
4-
from libs.stage import *
5-
import libs.vehicle
6-
import libs.vehicleFactory
7-
import libs.velocity
1+
import generalEquations as equ
2+
from libs.spec_manager import create_specs, get_json_file_data
3+
from libs.rocketEngine import RocketEngine
4+
from libs.stage import Stage
5+
from libs.vehicleFactory import VehicleFactory
6+
from libs import velocity
87
from libs.query import Query as q
98
import numpy as np
9+
from colorama import Fore, Style
1010

1111

1212
def prompt_thrust_at_alt():
13-
print "Thrust at alt Calculator"
14-
alt = float(raw_input("Alt? "))
15-
engines = libs.vehicleFactory.VehicleFactory.load_available_engines()
16-
engine_list = []
17-
n = 1
18-
for key, value in engines.items():
19-
engine_list.append(value)
20-
print("{}) {}".format(n, key))
21-
n += 1
22-
23-
engine_num = q.query_int("Select an engine number: ", None, 1, n-1)
24-
selected_engine = engine_list[engine_num-1]
25-
engine_num = q.query_int("How many? ", None, 1, 100)
26-
selected_engine["engine_count"] = engine_num
27-
engine = libs.rocketEngine.RocketEngine.factory(selected_engine)
28-
throt = q.query_min_max("Throttle? ")
29-
engine.setThrottleOverride(throt)
30-
engine.setThrottleOverride(throt)
31-
print engine.thrustAtAlt(alt)
13+
print("Thrust at alt Calculator")
14+
alt = float(input("Alt? "))
15+
engines = VehicleFactory.load_available_engines()
16+
engine_list = []
17+
n = 1
18+
for key, value in engines.items():
19+
engine_list.append(value)
20+
print("{}) {}".format(n, key))
21+
n += 1
22+
23+
engine_num = q.query_int("Select an engine number: ", None, 1, n - 1)
24+
selected_engine = engine_list[engine_num - 1]
25+
engine_num = q.query_int("How many? ", None, 1, 100)
26+
selected_engine["engine_count"] = engine_num
27+
engine = RocketEngine.factory(selected_engine)
28+
throt = q.query_min_max("Throttle? ")
29+
engine.setThrottleOverride(throt)
30+
engine.setThrottleOverride(throt)
31+
print(engine.thrustAtAlt(alt))
3232

3333

3434
def prompt_PATM():
35-
print "Percent of Atm Pressure Calculator"
36-
alt = float(raw_input("Alt? "))
37-
print percentOfAtmosphericPressure(alt)
35+
print("Percent of Atm Pressure Calculator")
36+
alt = float(input("Alt? "))
37+
print(equ.percentOfAtmosphericPressure(alt))
38+
3839

3940
def prompt_vac():
40-
print "Percent of Atm Vac Calculator"
41-
alt = float(raw_input("Alt? "))
42-
print percentOfVac(alt)
41+
print("Percent of Atm Vac Calculator")
42+
alt = float(input("Alt? "))
43+
print(equ.percentOfVac(alt))
44+
4345

4446
def prompt_big_G():
45-
print "Big G Calculator"
46-
V_h = float(raw_input("Horizontal Velocity? "))
47-
alt = float(raw_input("Alt? "))
48-
print bigG(V_h, velocity.Velocity.get_orbital(alt))
47+
print("Big G Calculator")
48+
V_h = float(input("Horizontal Velocity? "))
49+
alt = float(input("Alt? "))
50+
print(equ.bigG(V_h, velocity.Velocity.get_orbital(alt)))
51+
4952

5053
def prompt_ADC():
51-
print "ADC Calculator"
52-
V_as = float(raw_input("Air Speed Velocity? "))
53-
alt = float(raw_input("Alt? "))
54-
adc_K = float(raw_input("ADC K? "))
55-
print ADC(V_as, alt, adc_K)
54+
print("ADC Calculator")
55+
V_as = float(input("Air Speed Velocity? "))
56+
alt = float(input("Alt? "))
57+
adc_K = float(input("ADC K? "))
58+
print(equ.ADC(V_as, alt, adc_K))
5659

5760

5861
def prompt_row():
59-
first_row = {
60-
"alt" :
61-
[
62-
{"type" : "float"},
63-
{"promt": "Enter alt: "}
64-
],
65-
"prior_alt":
66-
[
67-
{"type" : "float"},
68-
{"prompt" : "Enter the prior alt: "}
69-
],
70-
"time_inc":
71-
[
72-
{"type" : "float"},
73-
{"prompt" : "Enter the time increment: "}
74-
],
75-
"adc_guess":
76-
[
77-
{"type" : "float"},
78-
{"prompt" : "Guess the ADC: "}
79-
],
80-
"thrust":
81-
[
82-
{"type" : "float"},
83-
{"prompt" : "Enter the thrust: "}
84-
],
85-
"weight":
86-
[
87-
{"type" : "float"},
88-
{"prompt" : "Enter the weight: "}
89-
],
90-
"error":
91-
[
92-
{"type" : "float"},
93-
{"prompt" : "Enter the prior error: "}
94-
],
95-
"A_v":
96-
[
97-
{"type" : "string"},
98-
{"prompt" : "Assign the A_v or enter \"a\" to assign all A to A_V: "}
99-
],
100-
"A_h_prior":
101-
[
102-
{"type" : "float"},
103-
{"prompt" : "Enter the prior A_h: "}
104-
],
105-
"V_h_prior":
106-
[
107-
{"type" : "float"},
108-
{"prompt" : "Enter the prior V_h: "}
109-
],
110-
"V_v_prior":
111-
[
112-
{"type" : "float"},
113-
{"prompt" : "Enter the prior V_v: "}
114-
]
115-
}
116-
loop_rows = {
117-
"time_inc":
118-
[
119-
{"type" : "float"},
120-
{"prompt" : "Enter the time increment: "}
121-
],
122-
"adc_guess":
123-
[
124-
{"type" : "float"},
125-
{"prompt" : "Guess the ADC: "}
126-
],
127-
"thrust":
128-
[
129-
{"type" : "float"},
130-
{"prompt" : "Enter the thrust: "}
131-
],
132-
"weight":
133-
[
134-
{"type" : "float"},
135-
{"prompt" : "Enter the weight: "}
136-
],
137-
"A_v":
138-
[
139-
{"type" : "string"},
140-
{"prompt" : "Assign the A_v or enter \"a\" to assign all A to A_V: "}
141-
]
142-
}
62+
first_row = {
63+
"alt": [{"type": "float"}, {"promt": "Enter alt: "}],
64+
"prior_alt": [{"type": "float"}, {"prompt": "Enter the prior alt: "}],
65+
"time_inc": [{"type": "float"}, {"prompt": "Enter the time increment: "}],
66+
"adc_guess": [{"type": "float"}, {"prompt": "Guess the ADC: "}],
67+
"thrust": [{"type": "float"}, {"prompt": "Enter the thrust: "}],
68+
"weight": [{"type": "float"}, {"prompt": "Enter the weight: "}],
69+
"error": [{"type": "float"}, {"prompt": "Enter the prior error: "}],
70+
"A_v": [
71+
{"type": "string"},
72+
{"prompt": 'Assign the A_v or enter "a" to assign all A to A_V: '},
73+
],
74+
"A_h_prior": [{"type": "float"}, {"prompt": "Enter the prior A_h: "}],
75+
"V_h_prior": [{"type": "float"}, {"prompt": "Enter the prior V_h: "}],
76+
"V_v_prior": [{"type": "float"}, {"prompt": "Enter the prior V_v: "}],
77+
}
78+
loop_rows = {
79+
"time_inc": [{"type": "float"}, {"prompt": "Enter the time increment: "}],
80+
"adc_guess": [{"type": "float"}, {"prompt": "Guess the ADC: "}],
81+
"thrust": [{"type": "float"}, {"prompt": "Enter the thrust: "}],
82+
"weight": [{"type": "float"}, {"prompt": "Enter the weight: "}],
83+
"A_v": [
84+
{"type": "string"},
85+
{"prompt": 'Assign the A_v or enter "a" to assign all A to A_V: '},
86+
],
87+
}
88+
14389

14490
def prompt_preburn():
145-
spec_data = get_json_file_data("specs", "spec", create_specs)
146-
alt = q.query_float("What is the alt for the preburn? ")
147-
preburn = Stage({})
148-
engines = []
149-
engine_rows = VehicleFactory.load_engine_data(spec_data["engines"])
150-
for engine_row in engine_rows:
151-
engine = RocketEngine.factory(engine_row)
152-
engine.set_fuel_source(preburn)
153-
engines.append(engine)
154-
start_time = q.query_float("What is the {}'s start time (positive start times will be ignored for preburn)? ".format(engine.name))
155-
if start_time < 0:
156-
start_throt = q.query_min_max("What is the starting throttle for {}".format(engine.name))
157-
target_throt = q.query_min_max("What is the target throttle for {}".format(engine.name))
158-
# set each weight twice to set average weight
159-
engine.setThrottleOverride(start_throt)
160-
if engine.type == "Solid":
161-
start_thrust = q.query_min_max("What is the starting " + Fore.RED + "thrust for {}".format(engine.name) + Style.RESET_ALL, 0, float("inf"))
162-
start_thrust = q.query_min_max("What is the target " + Fore.RED + "thrust for {}".format(engine.name) + Style.RESET_ALL, 0, float("inf"))
163-
engine.set_assigned_thrust_per_engine(start_thrust)
164-
165-
time_inc = 0.01
166-
for i in np.arange(0, abs(start_time), time_inc):
167-
for engine in engines:
168-
engine.burn_fuel(time_inc, alt)
169-
engine.setThrottle(target_throt, time_inc)
170-
171-
total_burned = 0.0
172-
print preburn.fuel_used
173-
# select config file or select engines
174-
# ask for engine start times
175-
# for each engine preburn until time 0
176-
# report amount burned per engine group
177-
# report total burned
91+
spec_data = get_json_file_data("specs", "spec", create_specs)
92+
alt = q.query_float("What is the alt for the preburn? ")
93+
preburn = Stage({})
94+
engines = []
95+
engine_rows = VehicleFactory.load_engine_data(spec_data["engines"])
96+
for engine_row in engine_rows:
97+
engine = RocketEngine.factory(engine_row)
98+
engine.set_fuel_source(preburn)
99+
engines.append(engine)
100+
start_time = q.query_float(
101+
"What is the {}'s start time (positive start times will be ignored for preburn)? ".format(
102+
engine.name
103+
)
104+
)
105+
if start_time < 0:
106+
start_throt = q.query_min_max(
107+
"What is the starting throttle for {}".format(engine.name)
108+
)
109+
target_throt = q.query_min_max(
110+
"What is the target throttle for {}".format(engine.name)
111+
)
112+
# set each weight twice to set average weight
113+
engine.setThrottleOverride(start_throt)
114+
if engine.type == "Solid":
115+
start_thrust = q.query_min_max(
116+
"What is the starting "
117+
+ Fore.RED
118+
+ "thrust for {}".format(engine.name)
119+
+ Style.RESET_ALL,
120+
0,
121+
float("inf"),
122+
)
123+
start_thrust = q.query_min_max(
124+
"What is the target "
125+
+ Fore.RED
126+
+ "thrust for {}".format(engine.name)
127+
+ Style.RESET_ALL,
128+
0,
129+
float("inf"),
130+
)
131+
engine.set_assigned_thrust_per_engine(start_thrust)
132+
133+
time_inc = 0.01
134+
for i in np.arange(0, abs(start_time), time_inc):
135+
for engine in engines:
136+
engine.burn_fuel(time_inc, alt)
137+
engine.setThrottle(target_throt, time_inc)
138+
139+
total_burned = 0.0
140+
print(preburn.fuel_used)
141+
# select config file or select engines
142+
# ask for engine start times
143+
# for each engine preburn until time 0
144+
# report amount burned per engine group
145+
# report total burned

src/rocket/engineBurnSim.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from rocketEngine import *
2-
from util import *
1+
from libs.rocketEngine import RocketEngine
2+
from util.func import current
33

44
RD171M_data = {
55
"name": "RD-171M",

src/rocket/libs/acceleration.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import sys
2-
sys.path.append('/home/tutordelphia/www/rocket/')
3-
41
from libs.twoD import TwoD
52

6-
from util import *
3+
74
class Acceleration(TwoD):
85
def __init__(self, horiz, vert):
96
TwoD.__init__(self, horiz, vert)

src/rocket/libs/edit_json.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
''' edit an existing json file '''
2-
3-
import json
4-
import sys
5-
sys.path.append('/home/tutordelphia/www/rocket/')
1+
""" edit an existing json file """
62

73
import libs.fileManager as fileMan
84
from libs.query import Query as q
9-
import util.func as func
10-
11-
125

136

147
def edit_list(list_to_edit):

src/rocket/libs/physicalStatus.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import sys
2-
sys.path.append('/home/tutordelphia/www/rocket/')
3-
4-
from util import *
51
from libs.acceleration import Acceleration
62
from libs.velocity import Velocity
73
import generalEquations as equ
84

5+
96
class PhysicalStatus(object):
107
def __init__(self, A_horiz = 0.0, A_vert = 0.0, V_horiz = 0.0, V_vert = 0.0, alt = 0.0, force = 0.0, earth_rotation_mph = 912.67):
118
self._A = Acceleration(A_horiz, A_vert)

src/rocket/libs/query.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import sys
2-
3-
sys.path.append('/home/tutordelphia/www/')
4-
52
from rocket.util import func
63

4+
75
class Query(object):
86
''' query the user for multiple datatypes in a testable manner '''
97
try:

src/rocket/libs/vehicle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from math import sqrt
2-
import copy
32

43
from colorama import Fore, Style
54

@@ -12,6 +11,7 @@
1211
import util.func as func
1312
import mode
1413

14+
1515
class Vehicle(object):
1616

1717
def __init__(self, specs, stages, engines):

src/rocket/libs/vehicleFactory.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
''' query for flight profile and spec information '''
1+
""" query for flight profile and spec information """
2+
23
from datetime import date
34
import time
4-
from math import sqrt
55
import copy
6-
import sys
76

87
from colorama import Fore, Back, Style
98

10-
sys.path.append('/home/tutordelphia/www/rocket/')
11-
129
from libs.stage import Stage
1310
from libs.rocketEngine import RocketEngine, LiquidRocketEngine
1411

15-
import util.func as func
16-
1712
from libs.vehicle import Vehicle
1813

1914
from libs.query import Query as q

0 commit comments

Comments
 (0)