Spaces:
Runtime error
Runtime error
tracinginsights
commited on
Commit
·
bf62d6c
1
Parent(s):
ad5d1a7
Update main.py
Browse files
main.py
CHANGED
@@ -173,7 +173,7 @@ def compute_accelerations(telemetry):
|
|
173 |
|
174 |
return np.round(lon_acc,2), np.round(lat_acc,2)
|
175 |
|
176 |
-
@st.cache_data
|
177 |
@app.get("/wdc", response_model=None)
|
178 |
def driver_standings() -> any:
|
179 |
YEAR = 2023 #datetime.datetime.now().year
|
@@ -199,14 +199,14 @@ def driver_standings() -> any:
|
|
199 |
|
200 |
return {"WDC":df.to_dict("records")}
|
201 |
|
202 |
-
@st.cache_data
|
203 |
@app.get("/", response_model=None)
|
204 |
async def root():
|
205 |
return HTMLResponse(
|
206 |
content="""<iframe src="https://tracinginsights-f1-analysis.hf.space" frameborder="0" style="width:100%; height:100%;" scrolling="yes" allowfullscreen:"yes"></iframe>""",
|
207 |
status_code=200)
|
208 |
|
209 |
-
@st.cache_data
|
210 |
@app.get("/years", response_model=None)
|
211 |
def years_available() -> any:
|
212 |
# make a list from 2018 to current year
|
@@ -220,7 +220,7 @@ def years_available() -> any:
|
|
220 |
|
221 |
# format for events {"events":[{"label":"Saudi Arabian Grand Prix","value":2},{"label":"Bahrain Grand Prix","value":1},{"label":"Pre-Season Testing","value":"t1"}]}
|
222 |
|
223 |
-
@st.cache_data
|
224 |
@app.get("/{year}", response_model=None)
|
225 |
def events_available(year: int) -> any:
|
226 |
# get events available for a given year
|
@@ -233,7 +233,7 @@ def events_available(year: int) -> any:
|
|
233 |
|
234 |
# format for sessions {"sessions":[{"label":"FP1","value":"FP1"},{"label":"FP2","value":"FP2"},{"label":"FP3","value":"FP3"},{"label":"Qualifying","value":"Q"},{"label":"Race","value":"R"}]}
|
235 |
|
236 |
-
@st.cache_data
|
237 |
@app.get("/{year}/{event}", response_model=None)
|
238 |
def sessions_available(year: int, event: str | int) -> any:
|
239 |
# get sessions available for a given year and event
|
@@ -244,8 +244,9 @@ def sessions_available(year: int, event: str | int) -> any:
|
|
244 |
return {"sessions": sessions}
|
245 |
|
246 |
# format for drivers {"drivers":[{"color":"#fff500","label":"RIC","value":"RIC"},{"color":"#ff8700","label":"NOR","value":"NOR"},{"color":"#c00000","label":"VET","value":"VET"},{"color":"#0082fa","label":"LAT","value":"LAT"},{"color":"#787878","label":"GRO","value":"GRO"},{"color":"#ffffff","label":"GAS","value":"GAS"},{"color":"#f596c8","label":"STR","value":"STR"},{"color":"#787878","label":"MAG","value":"MAG"},{"color":"#0600ef","label":"ALB","value":"ALB"},{"color":"#ffffff","label":"KVY","value":"KVY"},{"color":"#fff500","label":"OCO","value":"OCO"},{"color":"#0600ef","label":"VER","value":"VER"},{"color":"#00d2be","label":"HAM","value":"HAM"},{"color":"#ff8700","label":"SAI","value":"SAI"},{"color":"#00d2be","label":"BOT","value":"BOT"},{"color":"#960000","label":"GIO","value":"GIO"}]}
|
247 |
-
|
248 |
-
@st.cache_data
|
|
|
249 |
@app.get("/{year}/{event}/{session}", response_model=None)
|
250 |
def session_drivers(year: int, event: str | int, session: str) -> any:
|
251 |
# fastf1.Cache.enable_cache('cache')
|
@@ -271,8 +272,9 @@ def session_drivers(year: int, event: str | int, session: str) -> any:
|
|
271 |
# "VER_compound_color":"#FF5733",
|
272 |
# "lapnumber":2
|
273 |
# },{"lapnumber":3},{"VER":90.494,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":4},{"lapnumber":5},{"VER":90.062,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":6},{"lapnumber":7},{"VER":89.815,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":8},{"VER":105.248,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":9},{"lapnumber":10},{"VER":89.79,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":11},{"VER":145.101,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":12},{"lapnumber":13},{"VER":89.662,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":14},{"lapnumber":15},{"VER":89.617,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":16},{"lapnumber":17},{"VER":140.717,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":18}]}
|
274 |
-
|
275 |
-
@st.cache_data
|
|
|
276 |
@app.get("/{year}/{event}/{session}/{driver}", response_model=None)
|
277 |
def laps_data(year: int, event: str | int, session: str, driver: str) -> any:
|
278 |
# fastf1.Cache.enable_cache('cache')
|
@@ -316,8 +318,9 @@ def laps_data(year: int, event: str | int, session: str, driver: str) -> any:
|
|
316 |
|
317 |
return {"chartData": driver_laps_data}
|
318 |
|
319 |
-
|
320 |
-
@st.cache_data
|
|
|
321 |
@app.get("/{year}/{event}/{session}/{driver}/{lap_number}", response_model=None)
|
322 |
def telemetry_data(year: int, event: str | int, session: str, driver: str, lap_number: int) -> any:
|
323 |
# fastf1.Cache.enable_cache('cache')
|
|
|
173 |
|
174 |
return np.round(lon_acc,2), np.round(lat_acc,2)
|
175 |
|
176 |
+
# @st.cache_data
|
177 |
@app.get("/wdc", response_model=None)
|
178 |
def driver_standings() -> any:
|
179 |
YEAR = 2023 #datetime.datetime.now().year
|
|
|
199 |
|
200 |
return {"WDC":df.to_dict("records")}
|
201 |
|
202 |
+
# @st.cache_data
|
203 |
@app.get("/", response_model=None)
|
204 |
async def root():
|
205 |
return HTMLResponse(
|
206 |
content="""<iframe src="https://tracinginsights-f1-analysis.hf.space" frameborder="0" style="width:100%; height:100%;" scrolling="yes" allowfullscreen:"yes"></iframe>""",
|
207 |
status_code=200)
|
208 |
|
209 |
+
# @st.cache_data
|
210 |
@app.get("/years", response_model=None)
|
211 |
def years_available() -> any:
|
212 |
# make a list from 2018 to current year
|
|
|
220 |
|
221 |
# format for events {"events":[{"label":"Saudi Arabian Grand Prix","value":2},{"label":"Bahrain Grand Prix","value":1},{"label":"Pre-Season Testing","value":"t1"}]}
|
222 |
|
223 |
+
# @st.cache_data
|
224 |
@app.get("/{year}", response_model=None)
|
225 |
def events_available(year: int) -> any:
|
226 |
# get events available for a given year
|
|
|
233 |
|
234 |
# format for sessions {"sessions":[{"label":"FP1","value":"FP1"},{"label":"FP2","value":"FP2"},{"label":"FP3","value":"FP3"},{"label":"Qualifying","value":"Q"},{"label":"Race","value":"R"}]}
|
235 |
|
236 |
+
# @st.cache_data
|
237 |
@app.get("/{year}/{event}", response_model=None)
|
238 |
def sessions_available(year: int, event: str | int) -> any:
|
239 |
# get sessions available for a given year and event
|
|
|
244 |
return {"sessions": sessions}
|
245 |
|
246 |
# format for drivers {"drivers":[{"color":"#fff500","label":"RIC","value":"RIC"},{"color":"#ff8700","label":"NOR","value":"NOR"},{"color":"#c00000","label":"VET","value":"VET"},{"color":"#0082fa","label":"LAT","value":"LAT"},{"color":"#787878","label":"GRO","value":"GRO"},{"color":"#ffffff","label":"GAS","value":"GAS"},{"color":"#f596c8","label":"STR","value":"STR"},{"color":"#787878","label":"MAG","value":"MAG"},{"color":"#0600ef","label":"ALB","value":"ALB"},{"color":"#ffffff","label":"KVY","value":"KVY"},{"color":"#fff500","label":"OCO","value":"OCO"},{"color":"#0600ef","label":"VER","value":"VER"},{"color":"#00d2be","label":"HAM","value":"HAM"},{"color":"#ff8700","label":"SAI","value":"SAI"},{"color":"#00d2be","label":"BOT","value":"BOT"},{"color":"#960000","label":"GIO","value":"GIO"}]}
|
247 |
+
|
248 |
+
# @st.cache_data
|
249 |
+
@functools.cache
|
250 |
@app.get("/{year}/{event}/{session}", response_model=None)
|
251 |
def session_drivers(year: int, event: str | int, session: str) -> any:
|
252 |
# fastf1.Cache.enable_cache('cache')
|
|
|
272 |
# "VER_compound_color":"#FF5733",
|
273 |
# "lapnumber":2
|
274 |
# },{"lapnumber":3},{"VER":90.494,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":4},{"lapnumber":5},{"VER":90.062,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":6},{"lapnumber":7},{"VER":89.815,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":8},{"VER":105.248,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":9},{"lapnumber":10},{"VER":89.79,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":11},{"VER":145.101,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":12},{"lapnumber":13},{"VER":89.662,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":14},{"lapnumber":15},{"VER":89.617,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":16},{"lapnumber":17},{"VER":140.717,"VER_compound":"SOFT","VER_compound_color":"#FF5733","lapnumber":18}]}
|
275 |
+
|
276 |
+
# @st.cache_data
|
277 |
+
@functools.cache
|
278 |
@app.get("/{year}/{event}/{session}/{driver}", response_model=None)
|
279 |
def laps_data(year: int, event: str | int, session: str, driver: str) -> any:
|
280 |
# fastf1.Cache.enable_cache('cache')
|
|
|
318 |
|
319 |
return {"chartData": driver_laps_data}
|
320 |
|
321 |
+
|
322 |
+
# @st.cache_data
|
323 |
+
@functools.cache
|
324 |
@app.get("/{year}/{event}/{session}/{driver}/{lap_number}", response_model=None)
|
325 |
def telemetry_data(year: int, event: str | int, session: str, driver: str, lap_number: int) -> any:
|
326 |
# fastf1.Cache.enable_cache('cache')
|