File size: 1,251 Bytes
a2d3266
 
e742cfd
25c55c2
962c2a7
a2d3266
7eaac64
e742cfd
 
04643f1
e742cfd
04643f1
0563fc2
04643f1
e742cfd
 
1ff7960
4cc9fb2
a2d3266
 
 
 
6fb9c3c
 
 
 
 
3390fa2
6fb9c3c
 
4cc9fb2
98d2e95
 
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
import fastf1
import pandas as pd
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import os

app = FastAPI()


@app.get("/", response_model=None)
async def root():
    return HTMLResponse(
        content="""<iframe src="https://tracinginsights-f1-analysis.hf.space" frameborder="0" style="width:100%; height:100%;" scrolling="yes" allowfullscreen:"yes"></iframe>""",
        status_code=200)

@app.get("/{year}/{race}/{session}", response_model=None)
async def get_data(year: int, race: int | str, session: str) -> any:    
    
    f1session = fastf1.get_session(year, race, session)
    f1session.load(telemetry=False, weather=False, messages=False)
    # Load all laps with telemetry
    laps = f1session.laps
    laps['Sector1Time'] = laps['Sector1Time'].dt.total_seconds()
    laps['Sector2Time'] = laps['Sector2Time'].dt.total_seconds()
    laps['Sector3Time'] = laps['Sector3Time'].dt.total_seconds()
    laps['LapTime_in_seconds'] = laps['LapTime'].dt.total_seconds()
    laps['laptime_sum_sectortimes'] = laps.Sector1Time + laps.Sector2Time + laps.Sector3Time 
    laps = laps.fillna("")

    
    
    # return {"laps": laps.to_dict(orient='records')}
    return HTMLResponse(content=laps.to_html(), status_code=200)