-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.py
More file actions
258 lines (237 loc) · 9.92 KB
/
Copy pathGUI.py
File metadata and controls
258 lines (237 loc) · 9.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import streamlit as st
import requests
import json
import time
import copy
from pandas import *
class objectview(object):
def __init__(self, d):
self.__dict__ = d
class SpaceVehicle():
Mass = int()
AngleBelowHorizontal = float()
AngleOfAttack = float()
Height = int()
Radius = float()
Velocity = float()
TimeFrame = int()
VehicleType = int()
def __iter__(self):
yield 'Mass', self.Mass
yield 'AngleBelowHorizontal', self.AngleBelowHorizontal
yield 'AngleOfAttack', self.AngleOfAttack
yield 'Height', self.Height
yield 'Radius', self.Radius
yield 'Velocity', self.Velocity
yield 'TimeFrame', self.TimeFrame
yield 'VehicleType', self.VehicleType
class UpdatedShuttle():
Time = int()
shuttle = SpaceVehicle()
def __init__(self,shuttle):
self.shuttle = shuttle
def rnd(object):
return str(round(object,2))
def convert(obj):
arrDict = {}
timeList = list()
for key in obj[0]["vehicleState"]:
arrDict[key] = list()
for tf in obj:
timeList.append(tf["timeElapsed"])
for key in tf["vehicleState"]:
if key=="angleBelowHorizontal":
arrDict[key].append(tf["vehicleState"][key]*-1)
else:
arrDict[key].append(tf["vehicleState"][key])
df = dict()
df["time"] = timeList
# Acceleraion df
df["acc"] = DataFrame({
"absAcc":arrDict["absoluteAcceleration"],
"dccLoad":arrDict["decelerationLoad"]
})
# Angle df
df["angle"] = DataFrame({
"angBelowHor":arrDict["angleBelowHorizontal"],
"angAttack":arrDict["angleOfAttack"],
})
# Temperature df
df["temp"] = DataFrame({
"curTemp":arrDict["currentTemperature"],
"maxTemp":arrDict["maxTemperature"],
})
# Displacement df
df["disp"] = DataFrame({
"disp":arrDict["displacement"],
"dispEarth":arrDict["displacementAroundEarth"],
})
# Drag df
df["drag"] = DataFrame({
"dragCoeff":arrDict["dragCoeff"],
"liftToDrag":arrDict["liftToDrag"]
})
# Height df
df["hgt"] = DataFrame({
"height":arrDict["height"]
})
# Velocity df
df["vec"] = DataFrame({
"velocity":arrDict["velocity"]
})
df["nerdView"] = DataFrame({
"time": timeList,
"absAcc": arrDict["absoluteAcceleration"],
"dccLoad": arrDict["decelerationLoad"],
"angBelowHor": arrDict["angleBelowHorizontal"],
"angAttack": arrDict["angleOfAttack"],
"curTemp": arrDict["currentTemperature"],
"maxTemp": arrDict["maxTemperature"],
"disp": arrDict["displacement"],
"dispEarth": arrDict["displacementAroundEarth"],
"dragCoeff": arrDict["dragCoeff"],
"liftToDrag": arrDict["liftToDrag"],
"height": arrDict["height"],
"velocity": arrDict["velocity"]
})
detail = st.checkbox("Reload Details for Nerds")
if detail:
st.write(df["nerdView"])
return objectview(df)
def sideBarInput():
preset = st.sidebar.selectbox("Select you vehicle here", ("SpaceShuttle", "SpaceCraft"))
shuttle = SpaceVehicle()
shuttle.Velocity = st.sidebar.slider("InitialVelocity", 5000.0, 20000.0, 10000.0)
shuttle.AngleOfAttack = st.sidebar.slider("AttackAngle", 0.0, 90.0, 40.0)
shuttle.Height = st.sidebar.slider("StartingAlitude", 10000, 100000, 80000)
shuttle.AngleBelowHorizontal = st.sidebar.slider("AngleBelowHorizontal",0.0,90.0,6.0)
shuttle.Mass = st.sidebar.slider("Mass",50000,100000,78000)
shuttle.Radius = st.sidebar.slider("Radius",5.0,10.0,6.0)
shuttle.TimeFrame = st.sidebar.slider("TimeInterval",1,5,1)
if preset == "SpaceShuttle": shuttle.VehicleType = 0
else: shuttle.VehicleType = 1
updatedshuttle = None
if st.sidebar.checkbox("updateAngle"):
UpdatedAngleBelowHorizontal = st.sidebar.slider("NewAngleBelowHorizontal",0.0,90.0,6.0)
UpdatedAngleOfAttack = st.sidebar.slider("NewAngleOfAttack",0.0,90.0,6.0)
updatedshuttle = UpdatedShuttle(copy.deepcopy(shuttle))
updatedshuttle.Time = st.sidebar.slider("Applied TimeFrame",0,100,1)
updatedshuttle.shuttle.AngleBelowHorizontal = UpdatedAngleBelowHorizontal
updatedshuttle.shuttle.AngleOfAttack = UpdatedAngleOfAttack
return [shuttle,updatedshuttle]
def autoSimulation(o):
SimulationSpeed = st.slider("Select Simulation Speed", 1, 10, 1)
spTimePmt = st.empty()
spTfPmt = st.empty()
spSpdPmt = st.empty()
spSpeed = st.empty()
spAccPmt = st.empty()
spAccRefPmt = st.empty()
spAcc = st.empty()
spAngPmt = st.empty()
spAng = st.empty()
spAltPmt = st.empty()
spAlt = st.empty()
spDispPmt = st.empty()
spDispEarthPmt = st.empty()
spDisp = st.empty()
spTmpPmt = st.empty()
spGtmpPmt = st.empty()
spTmp = st.empty()
spDragPmt = st.empty()
spDragLiftPmt = st.empty()
spDrag = st.empty()
for i in range(0, len(o.time)):
spTimePmt.markdown("Current Time Elapsed **" + rnd(o.time[i])+"**")
spTfPmt.markdown("Curent TimeFrame **" + str(i) + "**")
spSpdPmt.markdown("The current velocity is **" + rnd(o.vec["velocity"][i])+"**")
spSpeed.line_chart(o.vec[0:i], height=100)
spAccPmt.markdown("Current Absolute Acceleration **" + rnd(o.acc["absAcc"][i]) + "**")
spAcc.line_chart(o.acc[0:i], height=100)
spAngPmt.markdown("Current Angle below Horizontal **" + rnd(-o.angle["angBelowHor"][i]) + "**")
spAng.line_chart(o.angle["angBelowHor"][0:i], height=100)
spAltPmt.markdown("Current Height **" + rnd(o.hgt["height"][i]) + "**")
spAlt.area_chart(o.hgt[0:i], height=100)
spDispPmt.markdown("Current Displacement is **" + rnd(o.disp["disp"][i]) + "**")
spDispEarthPmt.markdown("Current Displacement around Earth **" + rnd(o.disp["dispEarth"][i]) + "**")
spDisp.area_chart(o.disp[0:i], height=100)
spTmpPmt.markdown("The current temp is **" + rnd(o.temp["curTemp"][i]) + "**")
spGtmpPmt.markdown("The maximum temp is **" + rnd(o.temp["maxTemp"][i]) + "**")
spTmp.area_chart(o.temp[0:i], height=100)
spDragPmt.markdown("Current Drag Coefficient **" + rnd(o.drag["dragCoeff"][i]) + "**")
spDragLiftPmt.markdown("Current Lift to Drag **" + rnd(o.drag["liftToDrag"][i]) + "**")
spDrag.line_chart(o.drag[0:i], height=100)
time.sleep(1.0 / SimulationSpeed)
def manualSimulation(o):
i = st.slider("Current TimeFrame", 0, len(o.time)-1)
st.markdown("**Please drag TimeFrame slider slowly**")
st.markdown("Current Time Elapsed **" + rnd(o.time[i]) + "**")
st.markdown("Curent TimeFrame **" + str(i) + "**")
st.markdown("The current velocity is **" + rnd(o.vec["velocity"][i]) + "**")
st.line_chart(o.vec[0:i], height=100)
st.markdown("Current Absolute Acceleration **" + rnd(o.acc["absAcc"][i]) + "**")
st.line_chart(o.acc[0:i], height=100)
st.markdown("Current Angle below Horizontal **"+rnd(-o.angle["angBelowHor"][i])+"**")
st.line_chart(o.angle["angBelowHor"][0:i], height=100)
st.markdown("Current Height **" + rnd(o.hgt["height"][i]) + "**")
st.area_chart(o.hgt[0:i], height=100)
st.markdown("Current Displacement is **" + rnd(o.disp["disp"][i]) + "**")
st.markdown("Current Displacement around Earth **" + rnd(o.disp["dispEarth"][i]) + "**")
st.area_chart(o.disp[0:i], height=100)
st.markdown("The current temp is **" + rnd(o.temp["curTemp"][i]) + "**")
st.markdown("The maximum temp is **" + rnd(o.temp["maxTemp"][i]) + "**")
st.area_chart(o.temp[0:i], height=100)
st.markdown("Current Drag Coefficient **" + rnd(o.drag["dragCoeff"][i]) + "**")
st.markdown("Current Lift to Drag **" + rnd(o.drag["liftToDrag"][i]) + "**")
st.line_chart(o.drag[0:i], height=100)
def fetch(shuttle):
url = "http://localhost:5000/run"
res = None
res = requests.post(url,json=dict(shuttle))
return res.json()
def fetchupdate(shuttle):
url = "http://localhost:5000/updated_run"
res = None
post = dict(shuttle.shuttle)
post['Time'] = shuttle.Time
res = requests.post(url,json=post)
return res.json()
@st.cache()
def fetchcombined(sideInput):
shuttle = sideInput[0]
updatedShuttle = sideInput[1]
if updatedShuttle == None:
with st.spinner("Performing Calculations Please Wait"):
return fetch(shuttle)
else:
with st.spinner("Performing Calculations Please Wait"):
return (fetch(shuttle)[0:updatedShuttle.Time] + fetchupdate(updatedShuttle)[updatedShuttle.Time:] )
def startApp():
st.markdown("# Spacecraft Landing Simulator UI")
start = st.sidebar.selectbox("Select Page",("Introduction","Manual Simulation","Automated Simulation"))
if start == "Manual Simulation":
manualSimulation(convert(fetchcombined(sideBarInput())))
elif start == "Introduction":
st.empty()
st.markdown("""
## Instructions:
Adjust the parameters of the simulation from the side bar \n
Select the Simulation Type \n
**Automated**:The simulation data will be updated real-time \n
**Manual**: Manually adjust the current time \n
---
## Development Team
Follow the link below for Public Github Repositories\n
German Nikolishin - [BackEnd Simulation API](https://github.com/SkymanOne/SpaceShuttleSimulator)\n
Tony Zhang - [Frontend User Interface](https://github.com/N0ne1eft/SimulationInterface)\n
Will Cliffe - Trojectory Research\n
Mattie Lousada Blaazer - Ballisitic Coefficient Research \n
---
## **[Miro Board](https://miro.com/app/board/o9J_kqejVvE=/)**
This is the board where we brainstorm and sort out how properties are related \n
(Registeration may be required to view the public board)
""")
elif start == "Automated Simulation":
autoSimulation(convert(fetchcombined(sideBarInput())))
if __name__ == '__main__':
startApp()