tracinginsights commited on
Commit
3c52234
·
1 Parent(s): 8aeb6da

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -6
main.py CHANGED
@@ -1,6 +1,6 @@
1
  import datetime
2
  import os
3
-
4
  import fastf1
5
  import pandas as pd
6
  from fastapi import FastAPI
@@ -20,12 +20,14 @@ app.add_middleware(
20
  allow_headers=["*"],
21
  )
22
 
 
23
  @app.get("/", response_model=None)
24
  async def root():
25
  return HTMLResponse(
26
  content="""<iframe src="https://tracinginsights-f1-analysis.hf.space" frameborder="0" style="width:100%; height:100%;" scrolling="yes" allowfullscreen:"yes"></iframe>""",
27
  status_code=200)
28
 
 
29
  @app.get("/years", response_model=None)
30
  def years_available() -> any:
31
  # make a list from 2018 to current year
@@ -39,7 +41,7 @@ def years_available() -> any:
39
 
40
  # format for events {"events":[{"label":"Saudi Arabian Grand Prix","value":2},{"label":"Bahrain Grand Prix","value":1},{"label":"Pre-Season Testing","value":"t1"}]}
41
 
42
-
43
  @app.get("/{year}", response_model=None)
44
  def events_available(year: int) -> any:
45
  # get events available for a given year
@@ -52,7 +54,7 @@ def events_available(year: int) -> any:
52
 
53
  # format for sessions {"sessions":[{"label":"FP1","value":"FP1"},{"label":"FP2","value":"FP2"},{"label":"FP3","value":"FP3"},{"label":"Qualifying","value":"Q"},{"label":"Race","value":"R"}]}
54
 
55
-
56
  @app.get("/{year}/{event}", response_model=None)
57
  def sessions_available(year: int, event: str | int) -> any:
58
  # get sessions available for a given year and event
@@ -64,7 +66,7 @@ def sessions_available(year: int, event: str | int) -> any:
64
 
65
  # 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"}]}
66
 
67
-
68
  @app.get("/{year}/{event}/{session}", response_model=None)
69
  def session_drivers(year: int, event: str | int, session: str) -> any:
70
  # get drivers available for a given year, event and session
@@ -89,7 +91,7 @@ def session_drivers(year: int, event: str | int, session: str) -> any:
89
  # "lapnumber":2
90
  # },{"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}]}
91
 
92
-
93
  @app.get("/{year}/{event}/{session}/{driver}", response_model=None)
94
  def laps_data(year: int, event: str | int, session: str, driver: str) -> any:
95
 
@@ -132,7 +134,7 @@ def laps_data(year: int, event: str | int, session: str, driver: str) -> any:
132
 
133
  return {"chartData": driver_laps_data}
134
 
135
-
136
  @app.get("/{year}/{event}/{session}/{driver}/{lap_number}", response_model=None)
137
  def telemetry_data(year: int, event: str | int, session: str, driver: str, lap_number: int) -> any:
138
 
 
1
  import datetime
2
  import os
3
+ import streamlit as st
4
  import fastf1
5
  import pandas as pd
6
  from fastapi import FastAPI
 
20
  allow_headers=["*"],
21
  )
22
 
23
+ @st.cache(ttl=3600,suppress_st_warning=True)
24
  @app.get("/", response_model=None)
25
  async def root():
26
  return HTMLResponse(
27
  content="""<iframe src="https://tracinginsights-f1-analysis.hf.space" frameborder="0" style="width:100%; height:100%;" scrolling="yes" allowfullscreen:"yes"></iframe>""",
28
  status_code=200)
29
 
30
+ @st.cache(ttl=3600,suppress_st_warning=True)
31
  @app.get("/years", response_model=None)
32
  def years_available() -> any:
33
  # make a list from 2018 to current year
 
41
 
42
  # format for events {"events":[{"label":"Saudi Arabian Grand Prix","value":2},{"label":"Bahrain Grand Prix","value":1},{"label":"Pre-Season Testing","value":"t1"}]}
43
 
44
+ @st.cache(ttl=3600,suppress_st_warning=True)
45
  @app.get("/{year}", response_model=None)
46
  def events_available(year: int) -> any:
47
  # get events available for a given year
 
54
 
55
  # format for sessions {"sessions":[{"label":"FP1","value":"FP1"},{"label":"FP2","value":"FP2"},{"label":"FP3","value":"FP3"},{"label":"Qualifying","value":"Q"},{"label":"Race","value":"R"}]}
56
 
57
+ @st.cache(ttl=3600,suppress_st_warning=True)
58
  @app.get("/{year}/{event}", response_model=None)
59
  def sessions_available(year: int, event: str | int) -> any:
60
  # get sessions available for a given year and event
 
66
 
67
  # 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"}]}
68
 
69
+ @st.cache(ttl=3600,suppress_st_warning=True)
70
  @app.get("/{year}/{event}/{session}", response_model=None)
71
  def session_drivers(year: int, event: str | int, session: str) -> any:
72
  # get drivers available for a given year, event and session
 
91
  # "lapnumber":2
92
  # },{"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}]}
93
 
94
+ @st.cache(ttl=3600,suppress_st_warning=True)
95
  @app.get("/{year}/{event}/{session}/{driver}", response_model=None)
96
  def laps_data(year: int, event: str | int, session: str, driver: str) -> any:
97
 
 
134
 
135
  return {"chartData": driver_laps_data}
136
 
137
+ @st.cache(ttl=3600,suppress_st_warning=True)
138
  @app.get("/{year}/{event}/{session}/{driver}/{lap_number}", response_model=None)
139
  def telemetry_data(year: int, event: str | int, session: str, driver: str, lap_number: int) -> any:
140