Skip to content

Commit

Permalink
Merge pull request #242 from pbulsink/current_season
Browse files Browse the repository at this point in the history
Removed Ergast check from `get_current_season()` closes #227
  • Loading branch information
SCasanova committed Mar 11, 2024
2 parents ba7f1cf + 9cc2bcd commit 4bc2143
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Added (very soft) deprecation warning to Ergast functions in advance of the Ergast API being defunct in less than 12 months.
* Deprecated support for FastF1 v < 3.1.0. Older FastF1 versions do not support all of the functions in use and may return different values from some data retrieval or calculation functions. Forcing use of up-to-date FastF1 allows for simpler bugfixes and code updates. (#198)
* Removed Ergast check for `get_current_season()` (#227)
* Improved messaging to users regarding updating FastF1 (#226)
* Named items in list returned by `load_circuit_details()`
* Changed the way that `correct_track_ratio()` works. Visually the results are the same, but now any labels/annotations added to the ggplot should be kept in the right spot.
Expand Down
23 changes: 8 additions & 15 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' This function willbe replaced with a new data-source when one is made available.
#'
#' @param url the Ergast URL tail to get from the API (for example,
#' `"current.json?limit=30"` is called from `get_current_season()`).
#' `"{season}/circuits.json?limit=40"` is called from `load_circuits()`).
#' @keywords internal
#' @return the result of `jsonlite::fromJSON` called on Ergast's return content.
#' Further processing is performed by specific functions
Expand Down Expand Up @@ -92,25 +92,18 @@ get_ergast_content <- function(url) {
return(jsonlite::fromJSON(httr2::resp_body_string(ergast_res)))
}


#' Get Current Season
#'
#' @description Looks up current season from ergast, fallback to manual determination
#' @description Determines current season by System Date. Note returns the season prior to the current year
#' in January and February
#' @export
#' @return Year (four digit number) representation of current season, as numeric.
get_current_season <- function() {
url <- "current.json?limit=30"
data <- get_ergast_content(url)

if (is.null(data)) {
cli::cli_alert_info("Falling back to manually determined 'current' season")
current_season <- ifelse(as.numeric(strftime(Sys.Date(), "%m")) < 3,
as.numeric(strftime(Sys.Date(), "%Y")) - 1,
as.numeric(strftime(Sys.Date(), "%Y"))
)
} else {
current_season <- as.numeric(data$MRData$RaceTable$season)
}
return(current_season)
return(ifelse(as.numeric(strftime(Sys.Date(), "%m")) < 3,
as.numeric(strftime(Sys.Date(), "%Y")) - 1,
as.numeric(strftime(Sys.Date(), "%Y"))
))
}


Expand Down
6 changes: 0 additions & 6 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ test_that("Utility Functions work without internet", {
# a byproduct of the without_internet call
suppressWarnings({
suppressMessages({
# Test internet failures for get_current_season
httptest2::without_internet({
expect_message(get_current_season(), "f1dataR: Error getting data from Ergast")
expect_gte(get_current_season(), 2022)
})

httptest2::without_internet((
expect_false(check_ff1_network_connection("/static/2024/2024-03-02_Bahrain_Grand_Prix/2024-03-02_Race/"))
))
Expand Down

0 comments on commit 4bc2143

Please sign in to comment.