File size: 1,009 Bytes
a2d3266
 
e742cfd
962c2a7
a2d3266
e742cfd
 
68cfcbc
 
7eaac64
e742cfd
 
9ae94f1
e742cfd
 
 
 
 
7eaac64
68cfcbc
3f9e89e
68cfcbc
 
962c2a7
68cfcbc
4cc9fb2
a2d3266
 
 
 
4cc9fb2
 
 
 
7eaac64
4cc9fb2
7eaac64
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
import fastf1
import pandas as pd
from fastapi import FastAPI
import os





app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

@app.get("/{year}/{race}/{session}", response_model=None)
async def get_data(year: int, race: int, session: str) -> any:

    if not os.path.exists('Cache'):  
        os.makedirs('Cache')

    

    fastf1.Cache.enable_cache('Cache')
    
    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      
    
    return {"laps": laps.to_json(orient='records')}