Spaces:
Runtime error
Runtime error
| import fastf1 | |
| import pandas as pd | |
| from fastapi import FastAPI | |
| from fastapi.responses import HTMLResponse | |
| import os | |
| app = FastAPI() | |
| 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) | |
| 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) | |