-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
243 lines (183 loc) · 8.78 KB
/
app.py
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
from os import name, read
import numpy as np
import pandas as pd
import streamlit as st
from streamlit.elements.arrow import Data
from streamlit.type_util import data_frame_to_bytes
import app_functions as appf
import calculation_functions as cf
###############################################################################
# Initial Page Config
st.set_page_config(
page_title='Race Time Calculator',
layout="wide",
initial_sidebar_state="expanded",
)
###############################################################################
# Sidebar
#Header
st.sidebar.header('Race Time Calculator')
#---------------------------------------
#File upload
help_input_csv = """Please upload a CSV File with the required parameters"""
#Upload CSV File
uploaded_file = st.sidebar.file_uploader(
label='Upload Race Time Data', help=help_input_csv)
#---------------------------------------
#Given inputs
#car_mass
car_mass = st.sidebar.number_input(
label='Car Mass', help="The Car Mass should be the weight of the car in grams")
#friction_u or friction coeffe (subject to change as experiments improve)
friction_u = st.sidebar.number_input(
label='Friction Coeff', help="The friction Coeffecient should be Kinetic")
#drag_force (subject to change as experiment improve)
# drag_force = st.sidebar.number_input(
# label='drag_force', help=help_input)
###############################################################################
# Main body
#---------------------------------------
#Introduction
introduction = st.empty()
with introduction.container():
st.title("Roosevelt Racer's Race Time Calculator")
st.header("Quick Start")
st.write("""
To use this calculator you must have a csv to input. The csv should include
the columns: Time (s), Force (N), CO2 Mass (Mco2), Drag (FD). You may use the
example csv which can be dowloaded below. NOTE* You can run the CSV too
""")
example_csv = st.download_button(
label="Download Example CSV",
data=appf.example_csv(),
file_name="RTC_example_data.csv",
mime="text/csv"
)
st.write("""
After you have obtained your CSV file with the required data please also input
your car's mass and your car's friction coeffecient (Kinetic coeff for simplicity).
By using these parameters the calculator will to spit out a race time for
your car model. This will streamline your manufacturing/development process
because you would "know" your car time before even manufacturing!
""")
st.header("Purpose")
st.write("""
This is the Roosevelts Racer's Race Time Calculator created by the
team's R&D team. The goal of the R&D team is to improve and
accelerate the proccess of creating our dragster. The purpose of the
race time calculator is the evaluate if a dragster model is worthy
enough to be manufactured by calculating its race time.
We used the Vernier force sensor to measure the thrust created by CO2 cartridge. Combining
it with the friction data acquired from friction experiment, mass data generated by
Computer-Aided Design (CAD) tool, and drag data gained from Computational Fluid Dynamics
(CFD) simulation, we will be able to create a motion model based on empirical data.
""")
st.graphviz_chart('''
digraph {
FrictionData -> RaceTimeCalculator
ThrustData -> RaceTimeCalculator
MassData -> RaceTimeCalculator
DragData -> RaceTimeCalculator
RaceTimeCalculator -> RaceTimePrediction
}
''')
# st.header("Understanding Thrust")
# st.write("""
# We used a Vernier force sensor, microphone, computer interface, a full CO2 cartridge, a rope, a
# Balsa plank, a race system, a lunch pod, and a laptop to measure the thrust of the CO2 cartridge.
# """)
# st.markdown("![Alt Text]ehttps://media.giphy.com/media/SCuZ1vPVJXdi2e95Hc/giphy.gif)")
# uploaded_file is not None
try:
if st.sidebar.button("Generate"):
introduction.empty()
st.title("Calculations")
#---------------------------------------
# Calculations
dataframe = pd.read_csv(uploaded_file)
#Talkes in all the data and outputs only Time, Total Mass, and Fnet
dva_dataframe = cf.dataframe_to_dva(dataframe, car_mass, friction_u)
#Calculate accerlation (here cause it can be done in one line)
dva_dataframe['Acceleration (a)'] = (dva_dataframe['Fnet']/dva_dataframe['Total Mass'])*1000
#Find Continuous
dva_dataframe = cf.find_continuous_time(dva_dataframe)
#Calculate speed change
dva_dataframe = cf.cal_speed_change(dva_dataframe)
#Caluculate speed
dva_dataframe = cf.cal_speed(dva_dataframe)
#Calculate distance change
dva_dataframe = cf.cal_distance_change(dva_dataframe)
#Caluculate distance
dva_dataframe = cf.cal_distance(dva_dataframe)
#DVA Columns Only
dva_dataframe = dva_dataframe[['Continuous Time', 'Acceleration (a)', 'Speed (v)', 'Distance (d)']]
#Calculating End Time
dva_dataframe = dva_dataframe[dva_dataframe['Distance (d)'] <= 20]
#---------------------------------------
# Metric
top_speed = (dva_dataframe['Speed (v)'].max())*(18/5)
end_time = dva_dataframe['Continuous Time'].values[-1]
metric_col1, metric_col2 = st.columns(2)
metric_col1.metric("Top Speed (km/hr)", round(top_speed, 4))
metric_col2.metric("End time (sec)", round(end_time, 4))
# metric_col3.metric("Efficiency", "86%", "4%")
#---------------------------------------
#Graphs
#Acceleration Graph
acc_dataframe = dva_dataframe[['Continuous Time', 'Acceleration (a)']]
st.header('Acceleration Over Time')
acc_col1, acc_col2 = st.columns([3, 1])
acc_col1.subheader('Acceleration Over Time Chart')
acc_col1.line_chart(acc_dataframe.rename(columns={'Continuous Time':'index'}).set_index('index'))
acc_col2.subheader('Acceleration DataFrame')
acc_col2.write(acc_dataframe)
#Acceleration Expander
acc_expander = st.expander('What did we do?')
acc_expander.write("We did these calculation:")
acc_expander.latex(r'''F_{net} = F_{CO2} – F_{D} – F{f} = (m_{car} + m_{CO2}) a''')
#Velocity Graph
v_dataframe = dva_dataframe[['Continuous Time', 'Speed (v)']]
st.header('Velocity Over Time')
v_col1, v_col2 = st.columns([3, 1])
v_col1.subheader('Velocity Over Time Chart')
v_col1.line_chart(v_dataframe.rename(columns={'Continuous Time':'index'}).set_index('index'))
v_col2.subheader('Velocity DataFrame')
v_col2.write(v_dataframe)
#Velocity Expander
v_expander = st.expander('What did we do?')
v_expander.write("We did these calculation:")
v_expander.latex(r'''
v_{n}=\sum_{0}^{n} \frac{\left[a\left(t_{n}\right)+a\left(t_{n+1}\right)\right]}{2} \bullet\left(t_{n+1}-t_{n}\right)
''')
#Distance Graph
d_dataframe = dva_dataframe[['Continuous Time', 'Distance (d)']]
st.header('Distance Over Time')
d_col1, d_col2 = st.columns([3, 1])
d_col1.subheader('Distance Over Time Chart')
d_col1.line_chart(d_dataframe.rename(columns={'Continuous Time':'index'}).set_index('index'))
d_col2.subheader('Distance DataFrame')
d_col2.write(d_dataframe)
d_expander = st.expander('What did we do?')
d_expander.write("We did these calculation:")
d_expander.latex(r'''
d_{n}=\sum_{0}^{n} \frac{\left[v\left(t_{n}\right)+v\left(t_{n+1}\right)\right]}{2} \bullet\left(t_{n+1}-t_{n}\right)
''')
dva_dataframe
dva_csv = dva_dataframe.to_csv().encode('utf-8')
st.download_button(
label="Download DVA data as CSV",
data=dva_csv,
file_name='dva_data.csv',
mime='text/csv',)
#Thrust Graph This is wrong reason down below however thrust doesnt need to be graphed cause
#its always canstant anyways... this can go in our introduciton
# thrust_dataframe = dva_dataframe[['Continuous Time', 'Fnet']]#Fnet is wrong its supposed to be Fn
# st.header('Thrust Over Time')
# thrust_col1, thrust_col2 = st.columns([3, 1])
# thrust_col1.subheader('Thrust Over Time Chart')
# thrust_col1.line_chart(thrusttdataframe.rename(columns={'Continuous Time':'index'}).set_index('index'))
# thrust_col2.subheader('DVA DataFrame')
# thrust_col2.write(acc_dataframe)
except:
st.sidebar.error('Please input all your information including Car Mass and Friction')
###################################################################