Code Monkey home page Code Monkey logo

openf1's People

Contributors

br-g avatar brgodefroy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openf1's Issues

Special Characters Issue When Consuming API with Flutter/Dart

Issue Description

I've encountered an encoding issue when consuming the web service using the Flutter/Dart HTTP client. The client seems to default to latin1 encoding when the Content-Type header lacks a specified charset, resulting in misinterpreted special characters.

Impact

This issue impacts any client that relies on the Content-Type header to determine the correct character encoding. Since the Flutter/Dart HTTP client defaults to latin1, it incorrectly decodes responses that include special characters, assuming the absence of a charset=utf-8 in the Content-Type header.

Steps to Reproduce

  1. Consume the API endpoint using Flutter/Dart HTTP client.
  2. Notice special characters are not displayed correctly.

Proposed Solution

To resolve this issue, I suggest explicitly setting the charset in the Content-Type header for JSON responses. This can be implemented in the _process_api_query function.

from fastapi.responses import JSONResponse

# Modify the _process_api_query function to return a JSONResponse with charset=utf-8
if not use_csv:
    return JSONResponse(content=results, media_type="application/json; charset=utf-8")
else:
    # Existing CSV handling logic

By specifying charset=utf-8 in the Content-Type header, clients like Flutter/Dart should correctly interpret the response encoding as UTF-8.

Driver Table Multiple Rows For Driver, Meeting & Session

In the drivers table there seems to be two rows for the same driver_key,meeting_key & session_key with some of the information like team_name and headshot_url missing from one row but not the other.

Example

  • driver_key = 77
  • meeting_key = 1229
  • session_key = 9466

This can be seen in the CSV file

image

Aswell as the returned JSON from the endpoint https://api.openf1.org/v1/drivers?driver_number=77&meeting_key=1229&session_key=9466

image

Wrong date ISO format

Hi all,
all API responses have the wrong date format which does not comply with the ISO 8601 standard.

Now the dates are all without UTC information.
If no UTC relation information is given with a time representation, the time is assumed to be in local time.
Since dates are in UTC format, a Z should be added at the end of the time.

2024-02-29T11:30:00 would be 2024-02-29T11:30:00Z

Thanks

Driver details not showing for all sessions of latest meeting

I admit this might be a case of "garbage in, garbage out". But right now I'm getting this:

$ wget -qO - 'https://api.openf1.org/v1/drivers?driver_number=1&meeting_key=latest' | jq .
[
  {
    "session_key": 9481,
    "meeting_key": 1231,
    "broadcast_name": "M VERSTAPPEN",
    "country_code": null,
    "first_name": null,
    "full_name": "Max VERSTAPPEN",
    "headshot_url": null,
    "last_name": null,
    "driver_number": 1,
    "team_colour": null,
    "team_name": null,
    "name_acronym": "VER"
  },
  {
    "session_key": 9481,
    "meeting_key": 1231,
    "broadcast_name": "M VERSTAPPEN",
    "country_code": null,
    "first_name": null,
    "full_name": "Max VERSTAPPEN",
    "headshot_url": null,
    "last_name": null,
    "driver_number": 1,
    "team_colour": null,
    "team_name": null,
    "name_acronym": "VER"
  },
  {
    "session_key": 9482,
    "meeting_key": 1231,
    "broadcast_name": "M VERSTAPPEN",
    "country_code": null,
    "first_name": null,
    "full_name": "Max VERSTAPPEN",
    "headshot_url": null,
    "last_name": null,
    "driver_number": 1,
    "team_colour": null,
    "team_name": null,
    "name_acronym": "VER"
  },
  {
    "session_key": 9483,
    "meeting_key": 1231,
    "broadcast_name": "M VERSTAPPEN",
    "country_code": "NED",
    "first_name": "Max",
    "full_name": "Max VERSTAPPEN",
    "headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png.transform/1col/image.png",
    "last_name": "Verstappen",
    "driver_number": 1,
    "team_colour": "3671C6",
    "team_name": "Red Bull Racing",
    "name_acronym": "VER"
  },
  {
    "session_key": 9484,
    "meeting_key": 1231,
    "broadcast_name": "M VERSTAPPEN",
    "country_code": "NED",
    "first_name": "Max",
    "full_name": "Max VERSTAPPEN",
    "headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png.transform/1col/image.png",
    "last_name": "Verstappen",
    "driver_number": 1,
    "team_colour": "3671C6",
    "team_name": "Red Bull Racing",
    "name_acronym": "VER"
  },
  {
    "session_key": 9488,
    "meeting_key": 1231,
    "broadcast_name": "M VERSTAPPEN",
    "country_code": null,
    "first_name": null,
    "full_name": "Max VERSTAPPEN",
    "headshot_url": null,
    "last_name": null,
    "driver_number": 1,
    "team_colour": null,
    "team_name": null,
    "name_acronym": "VER"
  }
]

If I just did "session_key=latest" I'd get just the nulls for most of the fields.

Team Radio URL after 2024 Bahrain FP1 seems misplaced.

In the team radio api, < https://api.openf1.org/v1/team_radio?date%3E=2024-01-01 >, all the recording_url in 2024 are started with "https://livetiming.formula1.com/static/2024/2024-03-02_Bahrain_Grand_Prix/2024-02-29_Practice_1/..." rather than it's own grand prix name and session name.

(Edit: adding a side question)

Side question: There seems no Australian GP radios ( meeting_key=1231 ) here, does the data source did not provide them or there was some problem occured? Any chance to re-catch them into the api database ?

Thanks ๐Ÿ™‡

Driver team colour data type inconstency

In 2024, the data type for the team color in the drivers API has changed from string to int for some entries.

For instance, during the Bahrain Race on March 2nd, 2024, Fernando Alonso's team color is listed as an integer (229971), although other teams have their colors in hexadecimal format with letters, suggesting these should be strings.

https://api.openf1.org/v1/drivers?session_key=9472 (Bahrain Race in March 2nd, 2024)

  {
    "session_key": 9472,
    "meeting_key": 1229,
    "broadcast_name": "F ALONSO",
    "country_code": "ESP",
    "first_name": "Fernando",
    "full_name": "Fernando ALONSO",
    "headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/F/FERALO01_Fernando_Alonso/feralo01.png.transform/1col/image.png",
    "last_name": "Alonso",
    "driver_number": 14,
    "team_colour": 229971,
    "team_name": "Aston Martin",
    "name_acronym": "ALO"
  },

I would suggest serializing all team colors as strings for consistency.

JSON Parsing Error due to malformed URL on Windows

Running the ingestor on any non POSIX/Unix platform results in a malformed URL and inability to parse the returned JSON. The specific error I get is as follows:

Traceback (most recent call last):
  File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 196, in <module>
    cli()
  File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 178, in ingest_session
    asyncio.run(_ingest_session(*args, **kwargs))
  File "C:\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 149, in _ingest_session
    session_path = get_session_path(year=year, meeting_key=meeting_key, session_key=session_key)  
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
  File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 85, in get_session_path
    for meeting in _get_schedule(year)['Meetings']:
                   ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 30, in _get_schedule
    return json.loads(requests.get(url).content)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

After some debug printing, I discovered that the URL it was trying to get was https://livetiming.formula1.com/static\2023/Index.json. The backslash is because the script uses os.path.join to join the parts of the URL.

API Laps method, first lap lap_duration null

Hello,
I am trying to calculate the duration of one GP for each driver through the API Laps method summing up the "lap_duration" for each lap. However, I noticed that the "lap_duration" (and also the "duration_sector_1") is always null. Is this a bug? How can I reach the scope otherwise?
Here below an example:
{"meeting_key":1230,"session_key":9480,"driver_number":16,"i1_speed":280,"i2_speed":293,"st_speed":307,"date_start":null,"lap_duration":null,"is_pit_out_lap":false,"duration_sector_1":null,"duration_sector_2":29.838,"duration_sector_3":29.664,"segments_sector_1":[2048,2049,2049,2049,2051,2049,2051,2049,2049],"segments_sector_2":[2049,2049,2049,2049,2049,2049,2049],"segments_sector_3":[2051,2048,2048,2049,2048,2048,2048,2048,2049],"lap_number":1}

Many thanks in advance for any help.

Driver endpoint team colour invalid values

When you request the CSV from https://api.openf1.org/v1/drivers?csv=true some of the team colours are presented as 5.2e+253

I requested the raw JSON from the drivers endpoint using the following URI https://api.openf1.org/v1/drivers?driver_number=24&meeting_key=1229 and got this response

image

It looks like the data is held on the endpoint incorrectly - according to the documentation team_colour should be the six digit notation of the RGB team colour.

Missing data with JS fetch

Weird bug when querying https://api.openf1.org/v1/meetings

The next-coming or current meeting is part of the response when hitting that url with:

  • curl
  • browser get request
  • axios

However, it is missing when querying with javascript fetch. I don't remember the bug happening last time I worked on my project, so it could be related to current/ongoing meeting as JPN GP is ongoing right now.

Steps to reproduce

  1. Use JS
  2. Query meetings
const response = fetch("https://api.openf1.org/v1/meetings")`;
return response.json();
  1. Result
...
  {
    "circuit_key": 149,
    "circuit_short_name": "Jeddah",
    "meeting_key": 1230,
    "meeting_code": "KSA",
    "location": "Jeddah",
    "country_key": 153,
    "country_code": "KSA",
    "country_name": "Saudi Arabia",
    "meeting_name": "Saudi Arabian Grand Prix",
    "meeting_official_name": "FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024",
    "gmt_offset": "03:00:00",
    "date_start": "2024-03-07T13:30:00",
    "year": 2024
  },
  {
    "circuit_key": 10,
    "circuit_short_name": "Melbourne",
    "meeting_key": 1231,
    "meeting_code": "AUS",
    "location": "Melbourne",
    "country_key": 5,
    "country_code": "AUS",
    "country_name": "Australia",
    "meeting_name": "Australian Grand Prix",
    "meeting_official_name": "FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024",
    "gmt_offset": "11:00:00",
    "date_start": "2024-03-22T01:30:00",
    "year": 2024
  }
]

Expected result

...
  {
    "circuit_key": 149,
    "circuit_short_name": "Jeddah",
    "meeting_key": 1230,
    "meeting_code": "KSA",
    "location": "Jeddah",
    "country_key": 153,
    "country_code": "KSA",
    "country_name": "Saudi Arabia",
    "meeting_name": "Saudi Arabian Grand Prix",
    "meeting_official_name": "FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024",
    "gmt_offset": "03:00:00",
    "date_start": "2024-03-07T13:30:00",
    "year": 2024
  },
  {
    "circuit_key": 10,
    "circuit_short_name": "Melbourne",
    "meeting_key": 1231,
    "meeting_code": "AUS",
    "location": "Melbourne",
    "country_key": 5,
    "country_code": "AUS",
    "country_name": "Australia",
    "meeting_name": "Australian Grand Prix",
    "meeting_official_name": "FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024",
    "gmt_offset": "11:00:00",
    "date_start": "2024-03-22T01:30:00",
    "year": 2024
  },
  {
    "circuit_key": 46,
    "circuit_short_name": "Suzuka",
    "meeting_key": 1232,
    "meeting_code": "JPN",
    "location": "Suzuka",
    "country_key": 4,
    "country_code": "JPN",
    "country_name": "Japan",
    "meeting_name": "Japanese Grand Prix",
    "meeting_official_name": "FORMULA 1 MSC CRUISES JAPANESE GRAND PRIX 2024",
    "gmt_offset": "09:00:00",
    "date_start": "2024-04-05T02:30:00",
    "year": 2024
  }
]

Nearly half of driver data, interval data and pitstops not working.

Whilst trying to retrieve data for the latest race I have come to notice that team color, team name, country code, first name, last name, interval data and pitstops aren't working properly. The driver data related fields are "none" for everyone, and the other two return an empty json when called.

API method drivers NumberFormatException ๐Ÿฅบ

Field "team_colour" should be hex string, but it is '5.2e+253' in team Kick Sauber

API request like this:

https://api.openf1.org/v1/drivers?session_key=9484

Result:

{
    "session_key": 9484,
    "meeting_key": 1231,
    "broadcast_name": "G ZHOU",
    "country_code": "CHN",
    "first_name": "Guanyu",
    "full_name": "ZHOU Guanyu",
    "headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/G/GUAZHO01_Guanyu_Zhou/guazho01.png.transform/1col/image.png",
    "last_name": "Zhou",
    "driver_number": 24,
    "team_colour": 5.2e+253,
    "team_name": "Kick Sauber",
    "name_acronym": "ZHO"
}

Duplicate driver entries in last 2024 sessions

E.g.: https://api.openf1.org/v1/drivers?session_key=9473

(...)
 {
    "session_key": 9473,
    "meeting_key": 1230,
    "broadcast_name": "M VERSTAPPEN",
    "country_code": null,
    "first_name": null,
    "full_name": "Max VERSTAPPEN",
    "headshot_url": null,
    "last_name": null,
    "driver_number": 1,
    "team_colour": null,
    "team_name": null,
    "name_acronym": "VER"
  },
  {
    "session_key": 9473,
    "meeting_key": 1230,
    "broadcast_name": "M VERSTAPPEN",
    "country_code": "NED",
    "first_name": "Max",
    "full_name": "Max VERSTAPPEN",
    "headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png.transform/1col/image.png",
    "last_name": "Verstappen",
    "driver_number": 1,
    "team_colour": "3671c6",
    "team_name": "Red Bull Racing",
    "name_acronym": "VER"
  },
(...)

Driver API returning inconsistent data types for team_colour variable

Was reviewing my web application, designed to show race results for all the races in the season. I was validating the recent fixes made to the Drivers API, where some data was not coming for certain drivers and certain sessions.

I observed some inconsistencies in the team_colour variable for both Aston Martin drivers (note, I've only checked race sessions, possible there are other issues with other teams in other sessions).

If we look at Bahrain: https://api.openf1.org/v1/drivers?session_key=9472&driver_number%3E13&driver_number%3C20
and Jeddah: https://api.openf1.org/v1/drivers?session_key=9480&driver_number%3E13&driver_number%3C20

we can see that team_colour is coming as a string.

If we look at Australia and Japan
https://api.openf1.org/v1/drivers?session_key=9488&driver_number%3E13&driver_number%3C20
https://api.openf1.org/v1/drivers?session_key=9496&driver_number%3E13&driver_number%3C20

we can see that team_colour is coming as an integer.
Conveniently, due to the way I setup my filter, Charles Leclerc's data comes in and we can see his team_colour is always a string.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.