Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cbbdata::cbd_torvik_game_prediction #8

Open
barjehkopaxum opened this issue Jan 10, 2024 · 1 comment
Open

cbbdata::cbd_torvik_game_prediction #8

barjehkopaxum opened this issue Jan 10, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@barjehkopaxum
Copy link

Hi! I can't make out if it is possible to output predictions for the game by date, and not by entering individual commands? It would be cool if you could enter "20240111" into the "cbbdata::cbd_torvik_game_prediction" function and get a prediction of the games for all the games of all the teams for that day.

@andreweatherman andreweatherman added the enhancement New feature or request label Jan 10, 2024
@andreweatherman andreweatherman self-assigned this Jan 10, 2024
@mykzaun
Copy link

mykzaun commented Feb 23, 2024

@barjehkopaxum not that difficult to put together some basic script that will achieve this for you, for example you could run:

# Load required library or install it if it's not available
if (!requireNamespace("cbbdata", quietly = TRUE)) {
  install.packages("cbbdata")
}

# Generate predictions for today's games
# Load the future games schedule
schedule <- cbd_torvik_season_schedule(year = 2024)

# Convert the 'date' column to Date class and filter for future games
todays_games <- schedule %>%
  dplyr::mutate(date = as.Date(date)) %>%
  filter(date == Sys.Date())

todays_predictions <- list()

for (i in seq_len(nrow(todays_games))) {
  game <- todays_games[i, ]
  game_location <- if (game$neutral) "N" else "H"
  # Format the date to the required format YYYYMMDD
  game_date <- format(as.Date(game$date), "%Y%m%d")

  tryCatch({
    prediction <- cbd_torvik_game_prediction(
      team = game$home,
      opp = game$away,
      date = game_date,
      location = game_location
    )

    # Add the game_id to the prediction tibble/df
    prediction$game_id <- game$game_id

    todays_predictions[[i]] <- prediction
  }, error=function(e) {
    cat("Error in processing prediction for game_id", game$game_id, ":", e$message, "\n")
  })
}

# Combine predictions into a single data frame
todays_predictions <- do.call(rbind, todays_predictions)

# Order the predictions by game_id if needed
todays_predictions <- todays_predictions[order(todays_predictions$game_id), ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants