# College Football Data API
#
# This is an API for accessing all sorts of college football data. It currently has a wide array of data ranging from play by play to player statistics to game scores and more.
#
# OpenAPI spec version: 2.3.5
# Contact: admin@collegefootballdata.com
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#' @title Metrics operations
#' @description swagger.Metrics
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' get_game_ppa Team Predicated Points Added (PPA/EPA) by game
#'
#'
#' get_player_game_ppa Player Predicated Points Added (PPA/EPA) broken down by game
#'
#'
#' get_player_season_ppa Player Predicated Points Added (PPA/EPA) broken down by season
#'
#'
#' get_predicted_points Predicted Points (i.e. Expected Points or EP)
#'
#'
#' get_pregame_win_probabilities Pregame win probability data
#'
#'
#' get_team_ppa Predicted Points Added (PPA/EPA) data by team
#'
#'
#' get_win_probability_data Win probability chart data
#'
#' }
#'
#' @export
MetricsApi <- R6::R6Class(
'MetricsApi',
public = list(
userAgent = "Swagger-Codegen/1.0.0/r",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
get_game_ppa = function(year, week, team, conference, exclude_garbage_time, season_type, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`year`)) {
queryParams['year'] <- year
}
if (!missing(`week`)) {
queryParams['week'] <- week
}
if (!missing(`team`)) {
queryParams['team'] <- team
}
if (!missing(`conference`)) {
queryParams['conference'] <- conference
}
if (!missing(`exclude_garbage_time`)) {
queryParams['excludeGarbageTime'] <- exclude_garbage_time
}
if (!missing(`season_type`)) {
queryParams['seasonType'] <- season_type
}
urlPath <- "/ppa/games"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- GamePPA$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}
},
get_player_game_ppa = function(year, week, team, position, player_id, threshold, exclude_garbage_time, season_type, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`year`)) {
queryParams['year'] <- year
}
if (!missing(`week`)) {
queryParams['week'] <- week
}
if (!missing(`team`)) {
queryParams['team'] <- team
}
if (!missing(`position`)) {
queryParams['position'] <- position
}
if (!missing(`player_id`)) {
queryParams['playerId'] <- player_id
}
if (!missing(`threshold`)) {
queryParams['threshold'] <- threshold
}
if (!missing(`exclude_garbage_time`)) {
queryParams['excludeGarbageTime'] <- exclude_garbage_time
}
if (!missing(`season_type`)) {
queryParams['seasonType'] <- season_type
}
urlPath <- "/ppa/players/games"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- PlayerGamePPA$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}
},
get_player_season_ppa = function(year, team, conference, position, player_id, threshold, exclude_garbage_time, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`year`)) {
queryParams['year'] <- year
}
if (!missing(`team`)) {
queryParams['team'] <- team
}
if (!missing(`conference`)) {
queryParams['conference'] <- conference
}
if (!missing(`position`)) {
queryParams['position'] <- position
}
if (!missing(`player_id`)) {
queryParams['playerId'] <- player_id
}
if (!missing(`threshold`)) {
queryParams['threshold'] <- threshold
}
if (!missing(`exclude_garbage_time`)) {
queryParams['excludeGarbageTime'] <- exclude_garbage_time
}
urlPath <- "/ppa/players/season"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- PlayerSeasonPPA$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}
},
get_predicted_points = function(down, distance, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`down`)) {
queryParams['down'] <- down
}
if (!missing(`distance`)) {
queryParams['distance'] <- distance
}
urlPath <- "/ppa/predicted"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- PredictedPoints$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}
},
get_pregame_win_probabilities = function(year, week, team, season_type, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`year`)) {
queryParams['year'] <- year
}
if (!missing(`week`)) {
queryParams['week'] <- week
}
if (!missing(`team`)) {
queryParams['team'] <- team
}
if (!missing(`season_type`)) {
queryParams['seasonType'] <- season_type
}
urlPath <- "/metrics/wp/pregame"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- PregameWP$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}
},
get_team_ppa = function(year, team, conference, exclude_garbage_time, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`year`)) {
queryParams['year'] <- year
}
if (!missing(`team`)) {
queryParams['team'] <- team
}
if (!missing(`conference`)) {
queryParams['conference'] <- conference
}
if (!missing(`exclude_garbage_time`)) {
queryParams['excludeGarbageTime'] <- exclude_garbage_time
}
urlPath <- "/ppa/teams"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- TeamPPA$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}
},
get_win_probability_data = function(game_id, ...){
args <- list(...)
queryParams <- list()
headerParams <- character()
if (!missing(`game_id`)) {
queryParams['gameId'] <- game_id
}
urlPath <- "/metrics/wp"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
returnObject <- PlayWP$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp)
}
}
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.