Giter VIP home page Giter VIP logo

f1datar's People

Contributors

pbulsink avatar scasanova avatar wizviz 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

Watchers

 avatar  avatar

f1datar's Issues

[CRAN Comment] License File

I quote

 License components with restrictions and base license permitting such:
    MIT + file LICENSE
  File 'LICENSE':
    # MIT License

    Copyright (c) 2023 f1dataR authors

    Permission is ...

Please only ship the CRAN template for the MIT license.

It doesn´t load package name

When trying to install, it can´t load package name. This message appears: Error: package or namespace load failed for 'f1dataR'. Path argument is considered not valid. Could you help with this?
Thank you!

Verify session.load() is done?

Periodically we get build failures with this message:

fastf1.core.DataNotLoadedError: The data you are trying to access has not been loaded yet. See `Session.load`
Run `reticulate::py_last_error()` for details.

This happens in vignette building or testing, and isn't specific to ff1 version nor system architecture.

Trivial modifications to prompt rebuild passes the test.

Can't install the package

The installation throws this error message:

C:\Users\pbous\AppData\Local\Temp\RtmpukBwfm\R.INSTALL5d4c3eab76a9\f1dataR>CALL "C:\Users\pbous\AppData\Local\r-miniconda\condabin\activate.bat" "C:\Users\pbous\AppData\Local\r-miniconda\envs\r-reticulate" 

C:\Users\pbous\AppData\Local\Temp\RtmpukBwfm\R.INSTALL5d4c3eab76a9\f1dataR>conda.bat activate "C:\Users\pbous\AppData\Local\r-miniconda\envs\r-reticulate" 

(r-reticulate) C:\Users\pbous\AppData\Local\Temp\RtmpukBwfm\R.INSTALL5d4c3eab76a9\f1dataR>"C:/Users/pbous/AppData/Local/r-miniconda/envs/r-reticulate/python.exe" -m pip install --upgrade --no-user "fastf1" 
ERROR: Could not find a version that satisfies the requirement fastf1 (from versions: none)
ERROR: No matching distribution found for fastf1
Warning in shell(fi, intern = intern) :
  'C:\Users\pbous\AppData\Local\Temp\RtmpCeWrYh\file4cc2c815d57.bat' execution failed with error code 1
Error: package or namespace load failed for 'f1dataR':
 .onLoad failed in loadNamespace() for 'f1dataR', details:
  call: NULL
  error: Error installing package(s): "\"fastf1\""
Error: loading failed
Execution halted
*** arch - x64
Warning: package 'reticulate' was built under R version 4.1.3

C:\Users\pbous\AppData\Local\Temp\RtmpukBwfm\R.INSTALL5d4c3eab76a9\f1dataR>CALL "C:\Users\pbous\AppData\Local\r-miniconda\condabin\activate.bat" "C:\Users\pbous\AppData\Local\r-miniconda\envs\r-reticulate" 

C:\Users\pbous\AppData\Local\Temp\RtmpukBwfm\R.INSTALL5d4c3eab76a9\f1dataR>conda.bat activate "C:\Users\pbous\AppData\Local\r-miniconda\envs\r-reticulate" 

(r-reticulate) C:\Users\pbous\AppData\Local\Temp\RtmpukBwfm\R.INSTALL5d4c3eab76a9\f1dataR>"C:/Users/pbous/AppData/Local/r-miniconda/envs/r-reticulate/python.exe" -m pip install --upgrade --no-user "fastf1" 
ERROR: Could not find a version that satisfies the requirement fastf1 (from versions: none)
ERROR: No matching distribution found for fastf1
Warning in shell(fi, intern = intern) :
  'C:\Users\pbous\AppData\Local\Temp\RtmpiE9bfg\file14089924066.bat' execution failed with error code 1
Error: package or namespace load failed for 'f1dataR':
 .onLoad failed in loadNamespace() for 'f1dataR', details:
  call: NULL
  error: Error installing package(s): "\"fastf1\""
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing 'C:/Users/pbous/Documents/R/win-library/4.1/f1dataR'
Warning message:
In i.p(...) :
  installation of package ‘C:/Users/pbous/AppData/Local/Temp/RtmpIJLFhX/file42c82d701385/f1dataR_0.3.8.tar.gz’ had non-zero exit status

Force fixed aspect ratio in plot_fastest?

I noticed that the aspect ratio for plots are not fixed, this makes some tracks look really weird:
image

I tried to use ggplot2::coord_fixed() but that messes with the rest of the plotting properties, and looks bad with white bars on the plot edges and text not showing up right:
image

I'm not a great ggplot user, so my fixes would be very clumsy. See some suggestions at https://stackoverflow.com/questions/23349181/how-to-color-entire-background-in-ggplot2-when-using-coord-fixed

[ENH] Ergast Use HTTP/HTTPS & connection settings

With Ergast down over the past few days I've been digging around. I think usually the code uses http: connections to Ergast, but this should likely be changed to https: to protect our users. Likewise, we should centralize assignment of the url (i.e. http[s]://ergast.com/api/f1) to make it easy to try a fall back to http: if https: is down (as was the case earlier this week).

[ENH] Standardize Parameters and Returns

We should standardize parameter names and return types across the package.

This will end up being a breaking change unfortunately, but would likely be required if you ever plan to submit to CRAN.

For example of parameters, the two functions below should have the same input parameter names:

pitstops <- load_pitstops(season = season, race = race)
quali <- load_quali(season = season, round = race)

For example of returns, load_session_laps() returns a data.frame, while the Ergast calling functions return tibbles.

Finally, functions don't have a constant column name style: load_results() and others return columns with both camelCaseNames and snake_case_names. The FastF1 functions return columns with CamelCase (leading capital letter). Having one explicit style would be best.

Code styling could follow https://style.tidyverse.org/index.html, where it suggests names follow snake_case.

Before I start looking at these changes I'd love your feedback, @SCasanova!

Make constructorId available somewhere (either via load_results or joined in load_drivers?)

Maybe you already have the constructorId somewhere in a function, but either I'm too blind or that isn't the case ;)

It'd be awesome to have the Constructor list matched to drivers...
I'm wondering if the easiest way is to get both lists via load_results() instead of scraping the https://ergast.com/api/f1/2022/constructors.json (because via URL there's no driver ID to match...

Thx & regards
Christian

Show if round is sprint weekend

Ergast has a column in their schedule output that shows when the sprint race occurs (and therefore, if it's a sprint weekend). But load_schedule doesn't pass that information on. Either provide the sprint date/time or a TRUE/FALSE result to be able to more accurately understand the points producing events.

Screenshot 2023-07-19 at 6 41 23 AM

## [Codecov] Report

As per below suggestion from #41, suggest integrating codecov for test coverage purposes.

         ## [Codecov](https://app.codecov.io/gh/SCasanova/f1dataR/pull/41?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report

❗ No coverage uploaded for pull request base (master@08a12a2). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 4671abd differs from pull request most recent head 01965e4. Consider uploading reports for the commit 01965e4 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff            @@
##             master      #41   +/-   ##
=========================================
  Coverage          ?   93.54%           
=========================================
  Files             ?       16           
  Lines             ?      341           
  Branches          ?        0           
=========================================
  Hits              ?      319           
  Misses            ?       22           
  Partials          ?        0           

Originally posted by @codecov-commenter in #41 (comment)

Error to get telemetry data

Hey team! I've been trying to pull telemetry data from the package but I'm getting the following error, could you help me out?

test <- get_driver_telemetry(2022, 4, driver = 'PER')

Error:
! All columns in a tibble must be vectors.
✖ Column `DriverAhead` is a `numpy.ndarray/python.builtin.object` object.
✖ Column `DistanceToDriverAhead` is a `numpy.ndarray/python.builtin.object` object.
✖ Column `RPM` is a `numpy.ndarray/python.builtin.object` object.
✖ Column `Speed` is a `numpy.ndarray/python.builtin.object` object.
✖ Column `nGear` is a `numpy.ndarray/python.builtin.object` object.
✖ … and 10 more problems.
---
Backtrace:
    ▆
 1. ├─f1dataR::get_driver_telemetry(2022, 4, driver = "PER")
 2. │ └─f1dataR:::py_tel_to_tibble(tel)
 3. │   └─f1dataR:::py_tel_to_tibble(object)
 4. │     └─py_tel_object$tel %>% tibble::as_tibble()
 5. ├─tibble::as_tibble(.)
 6. └─tibble:::as_tibble.data.frame(.)
 7.   └─tibble:::lst_to_tibble(unclass(x), .rows, .name_repair)
 8.     └─tibble:::check_valid_cols(x)
 9.       └─rlang::cnd_signal(...)
> 

Handle Ergast Errors Better

Ergast has had stability issues over the past few weeks. I'll add better error handling code to provide more useful notification to users when ergast is down, so they don't think the package is broken or their code has issue.

Object to convert is not a Python object

Hi,

I was trying to use the get_driver_telemetry() function but I obtain the following output:

> get_driver_telemetry(2022, 4, driver = 'PER')
The first time a session is loaded, some time is required. Please be patient. Subsequent times will be faster

core           INFO 	Loading data for Emilia Romagna Grand Prix - Race [v2.3.0]
api            INFO 	Using cached data for driver_info
api            INFO 	Using cached data for timing_data
api            INFO 	Using cached data for timing_app_data
core           INFO 	Processing timing data...
api            INFO 	Using cached data for session_status_data
api            INFO 	Using cached data for track_status_data
api            INFO 	Using cached data for car_data
api            INFO 	Using cached data for position_data
api            INFO 	Using cached data for weather_data
api            INFO 	Using cached data for race_control_messages
core           INFO 	Finished loading data for 20 drivers: ['1', '11', '4', '63', '77', '16', '22', '5', '20', '18', '23', '10', '44', '31', '24', '6', '47', '3', '14', '55']
Error in py_to_r.default(.) : Object to convert is not a Python object

I took a look at the function, and I think the error raises because in line 14 the first command (tel %>% reticulate::py_to_r())$tel already returns a data.frame, and then you try to convert it again with reticulate::py_to_r(). I have removed this part of the code and seems that it works.

Package Tests+

Hi @SCasanova

I might add some tests for various package functions to verify that any changes being suggested don't break anything. Unfortunately, Ergast seems to be down at this time, but i'll get the tests written and posted once Ergast is back up and running.

Once I get them added, would you be interested/able to add CI to run package tests for pull requests and also Code Coverage reports? Let me know if you want a hand with setting that up.

Thanks for a great package!

load_result() column name error

Hi!
Just tried to build a new result data frame for all years and got the following error:

library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.0.5
#> Warning: package 'tidyr' was built under R version 4.0.5
#> Warning: package 'readr' was built under R version 4.0.5
#> Warning: package 'forcats' was built under R version 4.0.5
season <- 2022
round <- 11

res <-  httr::GET(glue::glue('http://ergast.com/api/f1/{season}/{round}/results.json?limit=40', season = season, round = round))
data <- jsonlite::fromJSON(rawToChar(res$content))

data$MRData$RaceTable$Races$Results[[1]] %>%
      tidyr::unnest(cols = c(Driver, Time, FastestLap)) %>%
      dplyr::select(driverId, points,position, grid:AverageSpeed) %>%
      tidyr::unnest(cols = c(Time, AverageSpeed),
                    names_repair = 'universal') %>%
      suppressWarnings() %>%
      suppressMessages() %>%
      dplyr::select(
        driverId:status,
        gap = `time...6`,
        fastest_rank =  rank,
        laps,
        fastest = `time...9`,
        top_speed_kph = speed
      ) %>%
      dplyr::mutate(time_sec = time_to_sec(fastest)) %>%
      tibble::as_tibble()
#> Error in `dplyr::select()`:
#> ! Can't subset columns that don't exist.
#> x Column `time...6` doesn't exist.

Created on 2022-07-17 by the reprex package (v2.0.1)

The error lies within the column names. As you can see there's no 'time...6' but a 'time...8':

library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.0.5
#> Warning: package 'tidyr' was built under R version 4.0.5
#> Warning: package 'readr' was built under R version 4.0.5
#> Warning: package 'forcats' was built under R version 4.0.5
season <- 2022
round <- 11

res <-  httr::GET(glue::glue('http://ergast.com/api/f1/{season}/{round}/results.json?limit=40', season = season, round = round))
data <- jsonlite::fromJSON(rawToChar(res$content))

data$MRData$RaceTable$Races$Results[[1]] %>%
      tidyr::unnest(cols = c(Driver, Time, FastestLap)) %>%
      dplyr::select(driverId, points,position, grid:AverageSpeed) %>%
      tidyr::unnest(cols = c(Time, AverageSpeed),
                    names_repair = 'universal') %>%
      suppressWarnings() %>%
      suppressMessages()
#> # A tibble: 20 x 13
#>    driverId       points position grid  laps  status millis time...8 rank  lap  
#>    <chr>          <chr>  <chr>    <chr> <chr> <chr>  <chr>  <chr>    <chr> <chr>
#>  1 leclerc        25     1        2     71    Finis~ 50643~ 1:24:24~ 2     62   
#>  2 max_verstappen 19     2        1     71    Finis~ 50658~ +1.532   1     62   
#>  3 hamilton       15     3        8     71    Finis~ 51055~ +41.217  5     63   
#>  4 russell        12     4        4     71    Finis~ 51232~ +58.972  6     61   
#>  5 ocon           10     5        6     71    Finis~ 51327~ +1:08.4~ 10    62   
#>  6 mick_schumach~ 8      6        9     70    +1 Lap <NA>   <NA>     11    50   
#>  7 norris         6      7        10    70    +1 Lap <NA>   <NA>     8     62   
#>  8 kevin_magnuss~ 4      8        7     70    +1 Lap <NA>   <NA>     14    61   
#>  9 ricciardo      2      9        11    70    +1 Lap <NA>   <NA>     13    61   
#> 10 alonso         1      10       19    70    +1 Lap <NA>   <NA>     3     62   
#> 11 bottas         0      11       0     70    +1 Lap <NA>   <NA>     7     61   
#> 12 albon          0      12       15    70    +1 Lap <NA>   <NA>     12    60   
#> 13 stroll         0      13       12    70    +1 Lap <NA>   <NA>     17    64   
#> 14 zhou           0      14       13    70    +1 Lap <NA>   <NA>     9     50   
#> 15 gasly          0      15       14    70    +1 Lap <NA>   <NA>     18    61   
#> 16 tsunoda        0      16       16    70    +1 Lap <NA>   <NA>     16    62   
#> 17 vettel         0      17       18    70    +1 Lap <NA>   <NA>     15    62   
#> 18 sainz          0      18       3     56    Power~ <NA>   <NA>     4     55   
#> 19 latifi         0      19       17    48    Under~ <NA>   <NA>     19    14   
#> 20 perez          0      20       5     24    Colli~ <NA>   <NA>     20    5    
#> # ... with 3 more variables: time...11 <chr>, units <chr>, speed <chr>

Created on 2022-07-17 by the reprex package (v2.0.1)

Best regards,
Christian (this Templer guy from Discord)

Clarify License

Currently project has a barebones license statement. Should clarify to a common Open Source license (MIT/GPL etc.)

Check for & create fastf1 cache dir

fastf1 functions fail if cache dir doesn't exist. Check for and create cache dir if it doesn't exist before running in load_race_session().

Add reticulate/virtualenv advice to short vignette

You can cause reticulate to use a virtual environment by running (change the first argument to name the venv whatever you want):

reticulate::virtualenv_create('f1dataRenv', packages = 'fastf1')
reticulate::use_virtualenv('f1dataRenv')

You might need to restart the R session to get reticulate to use the venv. If so, run that second line before calling library(fastf1)

Originally posted by @pbulsink in #39 (comment)

Telemetry error

I get the following error when using the get_driver_telemetry() function:

Error: ModuleNotFoundError: No module named 'fastf1'

Additional Examples Vignette

Based on the style of the Introduction vignette, some examples showing manipulations of data might be useful. I liked the plots you tweeted to celebrate the 1.0 release, so you could demonstrate those?

Update Docs per CRAN

  • Please add a web reference for the API in the form https:..... to the description of the DESCRIPTION file with no space after 'https:' and angle brackets for auto-linking.

  • Please add \value to .Rd files regarding exported methods and explain the functions results in the documentation. Please write about the structure of the output (class) and also what the output means. (If a function does not return a value, please document that too, e.g. \value{No return value, called for side effects} or similar)

Missing Rd-tags:

  • clear_f1_cache.Rd: \value
  • setup_fastf1.Rd: \value

Error in load_results(2021, 12)

Running f1dataR::load_results(2021, 12) returns an error: "Column FastestLap doesn't exist."

Traceback points to f1dataR/R/load_results.R:32 as the line in question.

This is the 2021 Belgian Grand Prix - the results may be different because the race was always under safety car.

Ergast does have this race in the results (see http://ergast.com/api/f1/2021/12/results) so it's a matter of handling the formatting correctly.

driver_constructor_data for past seasons

Hi,

either I'm blind again or this dataframe only works for current drivers.
Is it possible to create a df for past seasons?

Imo a static df would be ok for this and I'd love to help / provide the df for past seasons.

Best regards,
Christian

memoise onLoad to avoid build-time dependency

Hallo! Stumbled back here after seeing @pbulsink post about it on bluesky 😀

Noticed that the package memoises at build time, i.e. directly inside the R/ source code files. This can cause some unexpected issues, e.g. the function body changing after a different package version is loaded/installed but still returning the previous one, or causing issues while being built on CRAN.

package guidance suggests memoising onLoad which would help resolve this - nflreadr does it like this https://github.com/nflverse/nflreadr/blob/main/R/zzz.R

Format R code to standard

Consider formatting R code with formatR, styler and/or lintr- could do automatically at merge with a Github action.

@SCasanova feel free to assign to me if you think it's a good idea, or close if you'd rather not do that.

[CRAN Comment] Tarball size

I quote

Size of tarball: 58191530 bytes

This is way beyond the CRAN threshold of 5 MB.
The title says " Access Formula 1 Data " but apparently data is
included? Please host suc [sic] huge data elsewhere.

GGSci dependancy

GGSci should be moved to recommended (and handled) or the colour sequence from scale_color_nejm should be recreated to reduce over-reliance on other packages.

Move to httr2

httr2 allows for simple retry, rate limits, and better test interfaces - maybe migrate to build in ergast auto-retries & prevent hitting their server too hard during testing

Reach out to Ergast

Ergast has a list of (mostly python) tools that folks can use to access their data/api.

http://ergast.com/mrd/development-tools/

Maybe @SCasanova could reach out to them after CRAN submission and a) let them know of our project for them to share on their site (likely via CRAN - install.package('f1dataR')) and b) that our hits to their db using our package will have a 'f1dataR/X.X.X' useragent (with the version number for X.X.X).

Use of `:::` within package code

CRAN doesn't love the use of unexported functions: Unexported object imported by a ':::' call: ‘reticulate:::conda_installed’.
The comment is as follows:

It is typically a design mistake to use ::: in your code since the corresponding object has probably 
been kept internal for a good reason. 
Consider contacting the package [maintainer](http://127.0.0.1:39801/help/library/base/help/maintainer) 
if you feel the need to access the object for anything but mere inspection.

I will submit regardless but we might need to find alternatives if they reject us for this

Release f1dataR 1.2.1.9000

First release:

Prepare for release:

  • git pull
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push

Missing Time variable

I don't know if this is a problem on my machine but it seems that time variables are all NA for telemetry data

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.