From 44f696163196964731e8606e195cea8d3a3b16d1 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 27 Aug 2025 07:58:25 +0200 Subject: [PATCH 01/12] prepare package fro CRAN upload --- .Rbuildignore | 3 + DESCRIPTION | 4 +- NAMESPACE | 1 + R/getEvents.R | 55 ++++++------- R/getFormations.R | 46 ++++++----- R/getMatches.R | 81 ++++++++++---------- R/getPlayerIterationAverages.R | 54 ++++++++----- R/getPlayerIterationScores.R | 52 ++++++++----- R/getPlayerMatchScores.R | 39 ++++++---- R/getPlayerMatchsums.R | 34 ++++---- R/getPlayerProfileScores.R | 39 +++++----- R/getSetPieces.R | 51 +++++++----- R/getSquadIterationAverages.R | 33 ++++---- R/getSquadIterationScores.R | 35 +++++---- R/getSquadMatchScores.R | 44 ++++++----- R/getSquadMatchsums.R | 44 ++++++----- R/getSquadRatings.R | 12 +-- R/getStartingPositions.R | 56 +++++++------- R/getSubstitutions.R | 74 +++++++++--------- R/utils.R | 44 +++++------ man/{TokenBucket.Rd => TokenBucket-class.Rd} | 13 ++-- man/getPlayerMatchsums.Rd | 2 +- man/getSquadMatchsums.Rd | 2 +- 23 files changed, 450 insertions(+), 368 deletions(-) rename man/{TokenBucket.Rd => TokenBucket-class.Rd} (66%) diff --git a/.Rbuildignore b/.Rbuildignore index 82f4174..36035fb 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,6 @@ ^LICENSE\.md$ ^README\.Rmd$ ^\.github$ +^\.gitignore$ +^\.Rhistory$ +^dev$ diff --git a/DESCRIPTION b/DESCRIPTION index d236b24..483e2ad 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,9 @@ Imports: purrr, tidyr, utils, - methods + methods, + tibble, + rlang Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index ed09c9b..9c0a87f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,3 +21,4 @@ export(getSubstitutions) exportClasses(TokenBucket) importFrom(dplyr,"%>%") importFrom(methods,new) +importFrom(rlang,.data) diff --git a/R/getEvents.R b/R/getEvents.R index 3631fdb..fcfff6f 100644 --- a/R/getEvents.R +++ b/R/getEvents.R @@ -9,6 +9,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing all events and kpi values for a set of given #' match IDs #' @@ -50,18 +51,18 @@ getEvents <- function ( ) )$data ) %>% - dplyr::select(id, iterationId, lastCalculationDate) %>% + dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% base::unique() # filter for fail matches fail_matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$id) # filter for avilable matches matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$id) # raise warnings if (base::length(fail_matches) > 0) { @@ -133,7 +134,7 @@ getEvents <- function ( ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) } if (include_set_pieces) { @@ -156,8 +157,8 @@ getEvents <- function ( dplyr::mutate(matchId = ..1) %>% jsonlite::flatten() ) %>% - tidyr::unnest_longer(setPieceSubPhase) %>% - tidyr::unnest(setPieceSubPhase, names_sep = ".") %>% + tidyr::unnest_longer(.data$setPieceSubPhase) %>% + tidyr::unnest(.data$setPieceSubPhase, names_sep = ".") %>% dplyr::rename(setPiecePhaseIndex = "phaseIndex") # fix column names using regex @@ -167,7 +168,7 @@ getEvents <- function ( # merge events and set pieces events <- events %>% dplyr::left_join( - dplyr::select(set_pieces, -matchId, -squadId), + dplyr::select(set_pieces, -.data$matchId, -.data$squadId), by = c( "setPieceId" = "id", "setPieceSubPhaseId" = "setPieceSubPhaseId" @@ -177,7 +178,7 @@ getEvents <- function ( # get unique iterationIds iterations <- matchInfo %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() @@ -198,7 +199,7 @@ getEvents <- function ( ) )$data ) %>% - dplyr::select(id, commonname) %>% + dplyr::select(.data$id, .data$commonname) %>% base::unique() # get squad master data from API @@ -219,7 +220,7 @@ getEvents <- function ( )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name) %>% + dplyr::select(.data$id, .data$name) %>% base::unique() # fix column names using regex @@ -258,13 +259,15 @@ getEvents <- function ( # merge events with squads events <- events %>% - dplyr::left_join(dplyr::select(squads, squadId = id, squadName = name), - by = base::c("squadId" = "squadId")) %>% + dplyr::left_join( + dplyr::select(squads, squadId = .data$id, squadName = .data$name), + by = base::c("squadId" = "squadId") + ) %>% dplyr::left_join( dplyr::select( squads, - squadId = id, - currentAttackingSquadName = name + squadId = .data$id, + currentAttackingSquadName = .data$name ), by = base::c("currentAttackingSquadId" = "squadId") ) @@ -272,27 +275,27 @@ getEvents <- function ( # merge events with players events <- events %>% dplyr::left_join( - dplyr::select(players, id, playerName = commonname), + dplyr::select(players, .data$id, playerName = .data$commonname), by = base::c("playerId" = "id") ) %>% dplyr::left_join( - dplyr::select(players, id, pressingPlayerName = commonname), + dplyr::select(players, .data$id, pressingPlayerName = .data$commonname), by = base::c("pressingPlayerId" = "id") ) %>% dplyr::left_join( - dplyr::select(players, id, fouledPlayerName = commonname), + dplyr::select(players, .data$id, fouledPlayerName = .data$commonname), by = base::c("fouledPlayerId" = "id") ) %>% dplyr::left_join( - dplyr::select(players, id, duelPlayerName = commonname), + dplyr::select(players, .data$id, duelPlayerName = .data$commonname), by = base::c("duelPlayerId" = "id") ) %>% dplyr::left_join( - dplyr::select(players, id, passReceiverPlayerName = commonname), + dplyr::select(players, .data$id, passReceiverPlayerName = .data$commonname), by = base::c("passReceiverPlayerId" = "id") ) %>% dplyr::left_join( - dplyr::select(players, id, dribbleOpponentPlayerName = commonname), + dplyr::select(players, .data$id, dribbleOpponentPlayerName = .data$commonname), by = base::c("dribblePlayerId" = "id") ) @@ -300,25 +303,25 @@ getEvents <- function ( events <- events %>% dplyr::left_join( dplyr::select( - players, id, setPieceSubPhaseMainEventPlayerName = commonname + players, .data$id, setPieceSubPhaseMainEventPlayerName = .data$commonname ), by = base::c("setPieceSubPhaseMainEventPlayerId" = "id") ) %>% dplyr::left_join( dplyr::select( - players, id, setPieceSubPhasePassReceiverName = commonname + players, .data$id, setPieceSubPhasePassReceiverName = .data$commonname ), by = base::c("setPieceSubPhasePassReceiverId" = "id") ) %>% dplyr::left_join( dplyr::select( - players, id, setPieceSubPhaseFirstTouchPlayerName = commonname + players, .data$id, setPieceSubPhaseFirstTouchPlayerName = .data$commonname ), by = base::c("setPieceSubPhaseFirstTouchPlayerId" = "id") ) %>% dplyr::left_join( dplyr::select( - players, id, setPieceSubPhaseSecondTouchPlayerName = commonname + players, .data$id, setPieceSubPhaseSecondTouchPlayerName = .data$commonname ), by = base::c("setPieceSubPhaseSecondTouchPlayerId" = "id") ) diff --git a/R/getFormations.R b/R/getFormations.R index 471633c..27eda6d 100644 --- a/R/getFormations.R +++ b/R/getFormations.R @@ -7,6 +7,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing all starting formations for a set of given #' match IDs #' @@ -65,17 +66,17 @@ getFormations <- function ( # filter for fail matches fail_matches <- match_info %>% - dplyr::select(id, lastCalculationDate) %>% + dplyr::select(.data$id, .data$lastCalculationDate) %>% base::unique() %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$id) # filter for available matches matches <- match_info %>% - dplyr::select(id, lastCalculationDate) %>% + dplyr::select(.data$id, .data$lastCalculationDate) %>% base::unique() %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$id) # raise warnings if (base::length(fail_matches) > 0) { @@ -94,7 +95,7 @@ getFormations <- function ( # get unique iterationIds iterations <- match_info %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() # get squad master data from API @@ -115,7 +116,7 @@ getFormations <- function ( )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name) %>% + dplyr::select(.data$id, .data$name) %>% base::unique() # fix column names using regex @@ -132,48 +133,53 @@ getFormations <- function ( # extract formations formations_home <- match_info %>% dplyr::select( - id, squadId = squadHomeId, squadFormations = squadHomeFormations - ) + .data$id, + squadId = .data$squadHomeId, + squadFormations = .data$squadHomeFormations + ) formations_away <- match_info %>% dplyr::select( - id, squadId = squadAwayId, squadFormations = squadAwayFormations - ) + .data$id, + squadId = .data$squadAwayId, + squadFormations = .data$squadAwayFormations + ) # combine data frames formations <- dplyr::bind_rows(formations_home, formations_away) # unnest formations column formations <- formations %>% - tidyr::unnest_longer(squadFormations) + tidyr::unnest_longer(.data$squadFormations) # normalize the JSON structure into separate columns formations <- formations %>% - tidyr::unnest(squadFormations) + tidyr::unnest(.data$squadFormations) # start merging dfs # merge formations with squads formations <- formations %>% dplyr::left_join( - dplyr::select(squads, squadId = id, squadName = name), + dplyr::select(squads, squadId = .data$id, squadName = .data$name), by = base::c("squadId" = "squadId") ) # merge with matches info formations <- formations %>% dplyr::left_join( - dplyr::select(matchplan, id, skillCornerId, heimSpielId, wyscoutId, - matchDayIndex, matchDayName, scheduledDate, - lastCalculationDate, iterationId), + dplyr::select(matchplan, .data$id, .data$skillCornerId, .data$heimSpielId, + .data$wyscoutId, .data$matchDayIndex, .data$matchDayName, + .data$scheduledDate, .data$lastCalculationDate, + .data$iterationId), by = base::c("id" = "id") ) # merge with competition info formations <- formations %>% dplyr::left_join( - dplyr::select(iterations, id, competitionName, competitionId, - competitionType, season), + dplyr::select(iterations, .data$id, .data$competitionName, + .data$competitionId, .data$competitionType, .data$season), by = base::c("iterationId" = "id") ) diff --git a/R/getMatches.R b/R/getMatches.R index 7d89b54..9cd16aa 100644 --- a/R/getMatches.R +++ b/R/getMatches.R @@ -6,6 +6,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing all matches for a given iteration ID #' #' @@ -59,23 +60,23 @@ getMatches <- function(iteration, token) { by = c("homeSquadId" = "id"), suffix = c("", "_home")) %>% dplyr::rename( - homeSquadName = name, - homeSquadType = type, - homeSquadSkillCornerId = skillCornerId_home, - homeSquadHeimSpielId = heimSpielId_home, - homeSquadWyscoutId = wyscoutId_home, - homeSquadCountryId = countryId + homeSquadName = .data$name, + homeSquadType = .data$type, + homeSquadSkillCornerId = .data$skillCornerId_home, + homeSquadHeimSpielId = .data$heimSpielId_home, + homeSquadWyscoutId = .data$wyscoutId_home, + homeSquadCountryId = .data$countryId ) %>% dplyr::left_join(squads, by = c("awaySquadId" = "id"), suffix = c("", "_away")) %>% dplyr::rename( - awaySquadName = name, - awaySquadType = type, - awaySquadSkillCornerId = skillCornerId_away, - awaySquadHeimSpielId = heimSpielId_away, - awaySquadWyscoutId = wyscoutId_away, - awaySquadCountryId = countryId + awaySquadName = .data$name, + awaySquadType = .data$type, + awaySquadSkillCornerId = .data$skillCornerId_away, + awaySquadHeimSpielId = .data$heimSpielId_away, + awaySquadWyscoutId = .data$wyscoutId_away, + awaySquadCountryId = .data$countryId ) # get countries data from API @@ -94,39 +95,39 @@ getMatches <- function(iteration, token) { # merge matches with countries matches <- matches %>% dplyr::left_join(countries, by = c("homeSquadCountryId" = "id")) %>% - dplyr::rename(homeSquadCountryName = fifaName) %>% + dplyr::rename(homeSquadCountryName = .data$fifaName) %>% dplyr::left_join(countries, by = c("awaySquadCountryId" = "id")) %>% - dplyr::rename(awaySquadCountryName = fifaName) + dplyr::rename(awaySquadCountryName = .data$fifaName) # reorder columns matches <- matches %>% dplyr::select( - id, - skillCornerId, - heimSpielId, - wyscoutId, - iterationId, - matchDayIndex, - matchDayName, - homeSquadId, - homeSquadName, - homeSquadType, - homeSquadCountryId, - homeSquadCountryName, - homeSquadSkillCornerId, - homeSquadHeimSpielId, - homeSquadWyscoutId, - awaySquadId, - awaySquadName, - awaySquadType, - awaySquadCountryId, - awaySquadCountryName, - awaySquadSkillCornerId, - awaySquadHeimSpielId, - awaySquadWyscoutId, - scheduledDate, - lastCalculationDate, - available + .data$id, + .data$skillCornerId, + .data$heimSpielId, + .data$wyscoutId, + .data$iterationId, + .data$matchDayIndex, + .data$matchDayName, + .data$homeSquadId, + .data$homeSquadName, + .data$homeSquadType, + .data$homeSquadCountryId, + .data$homeSquadCountryName, + .data$homeSquadSkillCornerId, + .data$homeSquadHeimSpielId, + .data$homeSquadWyscoutId, + .data$awaySquadId, + .data$awaySquadName, + .data$awaySquadType, + .data$awaySquadCountryId, + .data$awaySquadCountryName, + .data$awaySquadSkillCornerId, + .data$awaySquadHeimSpielId, + .data$awaySquadWyscoutId, + .data$scheduledDate, + .data$lastCalculationDate, + .data$available ) # return matches diff --git a/R/getPlayerIterationAverages.R b/R/getPlayerIterationAverages.R index c961e6e..e7d08ed 100644 --- a/R/getPlayerIterationAverages.R +++ b/R/getPlayerIterationAverages.R @@ -6,6 +6,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the KPI averages aggregated per player and #' position for the given iteration ID #' @@ -40,8 +41,8 @@ getPlayerIterationAverages <- function (iteration, token) { # get squadIds squadIds <- squads %>% - dplyr::filter(access == TRUE) %>% - dplyr::pull(id) %>% + dplyr::filter(.data$access == TRUE) %>% + dplyr::pull(.data$id) %>% base::unique() # get player iteration averages for all squads from API @@ -97,7 +98,7 @@ getPlayerIterationAverages <- function (iteration, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) # get iterations from API iterations <- getIterations(token = token) @@ -108,44 +109,55 @@ getPlayerIterationAverages <- function (iteration, token) { averages <- averages_raw %>% tidyr::unnest("kpis", keep_empty = TRUE) %>% dplyr::select( - iterationId, - squadId, - playerId, - position, - playDuration, - matchShare, - kpiId, - value + .data$iterationId, + .data$squadId, + .data$playerId, + .data$position, + .data$playDuration, + .data$matchShare, + .data$kpiId, + .data$value ) %>% # join with kpis to ensure all kpiIds are present and order by kpiId dplyr::full_join(kpis, by = c("kpiId" = "id")) %>% - dplyr::arrange(kpiId, playerId) %>% + dplyr::arrange(.data$kpiId, .data$playerId) %>% # drop kpiId column - dplyr::select(-kpiId) %>% + dplyr::select(-.data$kpiId) %>% # pivot data tidyr::pivot_wider( - names_from = name, - values_from = value, + names_from = .data$name, + values_from = .data$value, values_fill = 0, values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(playerId) == FALSE) %>% + dplyr::filter(base::is.na(.data$playerId) == FALSE) %>% # remove the "NA" column if it exists dplyr::select(-dplyr::matches("^NA$")) # merge with other data averages <- averages %>% - dplyr::left_join(dplyr::select(squads, id, squadName = name), + dplyr::left_join(dplyr::select(squads, .data$id, squadName = .data$name), by = c("squadId" = "id")) %>% dplyr::left_join( dplyr::select( - players, id, wyscoutId, heimSpielId, skillCornerId, - playerName = commonname, firstname, lastname, birthdate, birthplace, leg + players, + .data$id, + .data$wyscoutId, + .data$heimSpielId, + .data$skillCornerId, + playerName = .data$commonname, + .data$firstname, + .data$lastname, + .data$birthdate, + .data$birthplace, + .data$leg ), by = c("playerId" = "id")) %>% - dplyr::left_join(dplyr::select(iterations, id, competitionName, season), - by = c("iterationId" = "id")) + dplyr::left_join(dplyr::select( + iterations, .data$id, .data$competitionName, .data$season), + by = c("iterationId" = "id") + ) # define column order order <- c( diff --git a/R/getPlayerIterationScores.R b/R/getPlayerIterationScores.R index 6e48593..557f2da 100644 --- a/R/getPlayerIterationScores.R +++ b/R/getPlayerIterationScores.R @@ -25,6 +25,7 @@ allowed_positions <- c( #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the player scores aggregated per player for #' the given iteration ID and list of positions #' @@ -69,8 +70,8 @@ getPlayerIterationScores <- function (iteration, positions, token) { # get squadIds squadIds <- squads %>% - dplyr::filter(access == TRUE) %>% - dplyr::pull(id) %>% + dplyr::filter(.data$access == TRUE) %>% + dplyr::pull(.data$id) %>% base::unique() # get player iteration scores from API @@ -160,7 +161,7 @@ getPlayerIterationScores <- function (iteration, positions, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) # get competitions iterations <- getIterations(token = token) @@ -171,45 +172,56 @@ getPlayerIterationScores <- function (iteration, positions, token) { scores <- scores_raw %>% tidyr::unnest("playerScores", keep_empty = TRUE) %>% dplyr::select( - iterationId, - squadId, - playerId, - playDuration, - matchShare, - playerScoreId, - value + .data$iterationId, + .data$squadId, + .data$playerId, + .data$playDuration, + .data$matchShare, + .data$playerScoreId, + .data$value ) %>% # add column to store positions string dplyr::mutate(positions = position_string) %>% # join with kpis to ensure all scores are present and order by playerScoreId dplyr::full_join(score_list, by = c("playerScoreId" = "id")) %>% - dplyr::arrange(playerScoreId, playerId) %>% + dplyr::arrange(.data$playerScoreId, .data$playerId) %>% # drop playerScoreId column - dplyr::select(-playerScoreId) %>% + dplyr::select(-.data$playerScoreId) %>% # pivot data tidyr::pivot_wider( - names_from = name, - values_from = value, + names_from = .data$name, + values_from = .data$value, values_fill = 0, values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(playerId) == FALSE) %>% + dplyr::filter(base::is.na(.data$playerId) == FALSE) %>% # remove the "NA" column if it exists dplyr::select(-dplyr::matches("^NA$")) # merge with other data scores <- scores %>% - dplyr::left_join(dplyr::select(squads, id, squadName = name), + dplyr::left_join(dplyr::select(squads, .data$id, squadName = .data$name), by = c("squadId" = "id")) %>% dplyr::left_join( dplyr::select( - players, id, wyscoutId, heimSpielId, skillCornerId, - playerName = commonname, firstname, lastname, birthdate, birthplace, leg + players, + .data$id, + .data$wyscoutId, + .data$heimSpielId, + .data$skillCornerId, + playerName = .data$commonname, + .data$firstname, + .data$lastname, + .data$birthdate, + .data$birthplace, + .data$leg ), by = c("playerId" = "id")) %>% - dplyr::left_join(dplyr::select(iterations, id, competitionName, season), - by = c("iterationId" = "id")) + dplyr::left_join(dplyr::select( + iterations, .data$id, .data$competitionName, .data$season), + by = c("iterationId" = "id") + ) # define column order order <- c( diff --git a/R/getPlayerMatchScores.R b/R/getPlayerMatchScores.R index 88e9354..3d51bef 100644 --- a/R/getPlayerMatchScores.R +++ b/R/getPlayerMatchScores.R @@ -26,6 +26,7 @@ allowed_positions <- c( #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the scores aggregated per player and #' position for the given match ID and list of positions #' @@ -69,18 +70,18 @@ getPlayerMatchScores <- function (matches, positions, token) { ) )$data ) %>% - dplyr::select(id, iterationId, lastCalculationDate) %>% + dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% base::unique() # filter for fail matches fail_matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$id) # filter for avilable matches matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$id) # raise warnings if (base::length(fail_matches) > 0) { @@ -124,7 +125,7 @@ getPlayerMatchScores <- function (matches, positions, token) { # get unique iterationIds iterations <- matchInfo %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() # get player master data from API @@ -145,8 +146,9 @@ getPlayerMatchScores <- function (matches, positions, token) { )$data ) %>% dplyr::select( - id, playerName = commonname, firstname, - lastname, birthdate, birthplace, leg, idMappings + .data$id, playerName = .data$commonname, .data$firstname, + .data$lastname, .data$birthdate, .data$birthplace, .data$leg, + .data$idMappings ) %>% base::unique() @@ -171,7 +173,7 @@ getPlayerMatchScores <- function (matches, positions, token) { )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name) %>% + dplyr::select(.data$id, .data$name) %>% base::unique() # get kpi names from API @@ -186,7 +188,7 @@ getPlayerMatchScores <- function (matches, positions, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) # get matchplan data matchplan <- @@ -231,7 +233,7 @@ getPlayerMatchScores <- function (matches, positions, token) { values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(playerId) == FALSE) %>% + dplyr::filter(base::is.na(.data$playerId) == FALSE) %>% # remove the "NA" column if it exists dplyr::select(-dplyr::matches("^NA$")) %>% dplyr::mutate( @@ -293,29 +295,32 @@ getPlayerMatchScores <- function (matches, positions, token) { scores <- scores %>% dplyr::left_join( dplyr::select( - matchplan, id, scheduledDate, matchDayIndex, matchDayName, iterationId + matchplan, .data$id, .data$scheduledDate, .data$matchDayIndex, + .data$matchDayName, .data$iterationId ), by = c("matchId" = "id") ) %>% dplyr::left_join( dplyr::select( - iterations, id, competitionId, competitionName, competitionType, season + iterations, .data$id, .data$competitionId, .data$competitionName, + .data$competitionType, .data$season ), by = c("iterationId" = "id") ) %>% dplyr::left_join( - dplyr::select(squads, id, squadName = name), + dplyr::select(squads, .data$id, squadName = .data$name), by = c("squadId" = "id") ) %>% dplyr::left_join( dplyr::select( - players, id, wyscoutId, heimSpielId, skillCornerId, - playerName, firstname, lastname, birthdate, birthplace, leg + players, .data$id, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId, .data$playerName, .data$firstname, .data$lastname, + .data$birthdate, .data$birthplace, .data$leg ), by = c("playerId" = "id")) %>% # fix some column names dplyr::rename( - dateTime = scheduledDate + dateTime = .data$scheduledDate ) # define column order diff --git a/R/getPlayerMatchsums.R b/R/getPlayerMatchsums.R index 39bcfdc..1b24476 100644 --- a/R/getPlayerMatchsums.R +++ b/R/getPlayerMatchsums.R @@ -6,6 +6,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the matchsums aggregated per player and position for the given match ID #' #' @examples @@ -41,19 +42,19 @@ getPlayerMatchsums <- function (matches, token) { ) )$data ) %>% - dplyr::select(id, iterationId, lastCalculationDate) %>% + dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% base::unique() # filter for fail matches fail_matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$id) # filter for avilable matches matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$id) # raise warnings if (base::length(fail_matches) > 0) { @@ -90,7 +91,7 @@ getPlayerMatchsums <- function (matches, token) { # get unique iterationIds iterations <- matchInfo %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() # get player master data from API @@ -111,8 +112,9 @@ getPlayerMatchsums <- function (matches, token) { )$data ) %>% dplyr::select( - id, playerName = commonname, firstname, - lastname, birthdate, birthplace, leg, idMappings + .data$id, playerName = .data$commonname, .data$firstname, + .data$lastname, .data$birthdate, .data$birthplace, .data$leg, + .data$idMappings ) %>% base::unique() @@ -138,7 +140,7 @@ getPlayerMatchsums <- function (matches, token) { )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name) %>% + dplyr::select(.data$id, .data$name) %>% base::unique() @@ -154,7 +156,7 @@ getPlayerMatchsums <- function (matches, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) # get matchplan data @@ -198,7 +200,7 @@ getPlayerMatchsums <- function (matches, token) { values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(playerId) == FALSE) %>% + dplyr::filter(base::is.na(.data$playerId) == FALSE) %>% # remove the "NA" column if it exists dplyr::select(-dplyr::matches("^NA$")) %>% dplyr::mutate( @@ -238,17 +240,19 @@ getPlayerMatchsums <- function (matches, token) { by = c("iterationId" = "id") ) %>% dplyr::left_join( - dplyr::select(squads, id, squadName = name), + dplyr::select(squads, .data$id, squadName = .data$name), by = c("squadId" = "id") ) %>% dplyr::left_join( - dplyr::select(players, id, playerName, firstname, lastname, birthdate, - birthplace, leg, wyscoutId, heimSpielId, skillCornerId), + dplyr::select(players, .data$id, .data$playerName, .data$firstname, + .data$lastname, .data$birthdate, .data$birthplace, + .data$leg, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId), by = c("playerId" = "id") ) %>% # fix some column names dplyr::rename( - dateTime = scheduledDate + dateTime = .data$scheduledDate ) # define column order diff --git a/R/getPlayerProfileScores.R b/R/getPlayerProfileScores.R index a38f9f4..881741a 100644 --- a/R/getPlayerProfileScores.R +++ b/R/getPlayerProfileScores.R @@ -26,6 +26,7 @@ allowed_positions <- c( #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the player profilescores aggregated per player #' for the given iteration ID and list of positions #' @@ -70,8 +71,8 @@ getPlayerProfileScores <- function (iteration, positions, token) { # get squadIds squadIds <- squads %>% - dplyr::filter(access == TRUE) %>% - dplyr::pull(id) %>% + dplyr::filter(.data$access == TRUE) %>% + dplyr::pull(.data$id) %>% base::unique() # get player profile scores from API @@ -161,7 +162,7 @@ getPlayerProfileScores <- function (iteration, positions, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(name) + dplyr::select(.data$name) # get competitions iterations <- getIterations(token = token) @@ -172,44 +173,46 @@ getPlayerProfileScores <- function (iteration, positions, token) { scores <- scores_raw %>% tidyr::unnest("profileScores", keep_empty = TRUE) %>% dplyr::select( - iterationId, - squadId, - playerId, - playDuration, - matchShare, - profileName, - value + .data$iterationId, + .data$squadId, + .data$playerId, + .data$playDuration, + .data$matchShare, + .data$profileName, + .data$value ) %>% # add column to store positions string dplyr::mutate(positions = position_string) %>% # join with profiles to ensure all profiles are present and order by profile dplyr::full_join(profile_list, by = c("profileName" = "name")) %>% - dplyr::arrange(profileName, playerId) %>% + dplyr::arrange(.data$profileName, .data$playerId) %>% # pivot data tidyr::pivot_wider( - names_from = profileName, - values_from = value, + names_from = .data$profileName, + values_from = .data$value, values_fill = 0, values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(playerId) == FALSE) %>% + dplyr::filter(base::is.na(.data$playerId) == FALSE) %>% # remove the "NA" column if it exists dplyr::select(-dplyr::matches("^NA$")) # merge with other data scores <- scores %>% - dplyr::left_join(dplyr::select(squads, id, squadName = name), + dplyr::left_join(dplyr::select(squads, .data$id, squadName = .data$name), by = c("squadId" = "id")) %>% dplyr::left_join( dplyr::select( - players, id, wyscoutId, heimSpielId, skillCornerId, - playerName = commonname, firstname, lastname, birthdate, birthplace, leg + players, .data$id, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId, playerName = .data$commonname, .data$firstname, + .data$lastname, .data$birthdate, .data$birthplace, .data$leg ), by = c("playerId" = "id")) %>% dplyr::left_join( dplyr::select( - iterations, id, competitionId, competitionName, competitionType, season + iterations, .data$id, .data$competitionId, .data$competitionName, + .data$competitionType, .data$season ), by = c("iterationId" = "id") ) diff --git a/R/getSetPieces.R b/R/getSetPieces.R index 0b69853..c9a0479 100644 --- a/R/getSetPieces.R +++ b/R/getSetPieces.R @@ -7,6 +7,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing all set pieces and aggregated kpi values per #' set piece sub phase for a set of given list of match IDs #' @@ -46,18 +47,18 @@ getSetPieces <- function ( ) )$data ) %>% - dplyr::select(id, iterationId, lastCalculationDate) %>% + dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% base::unique() # filter for fail matches fail_matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$id) # filter for avilable matches matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$id) # raise warnings if (base::length(fail_matches) > 0) { @@ -94,9 +95,9 @@ getSetPieces <- function ( dplyr::mutate(matchId = ..1) ) ) %>% - tidyr::unnest_longer(setPieceSubPhase) %>% - tidyr::unnest(setPieceSubPhase, names_sep = ".") %>% - tidyr::unnest(setPieceSubPhase.aggregates, names_sep = ".") + tidyr::unnest_longer(.data$setPieceSubPhase) %>% + tidyr::unnest(.data$setPieceSubPhase, names_sep = ".") %>% + tidyr::unnest(.data$setPieceSubPhase.aggregates, names_sep = ".") # fix column names using regex base::names(set_pieces) <- @@ -104,7 +105,7 @@ getSetPieces <- function ( # get unique iterationIds iterations <- matchInfo %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() @@ -125,7 +126,7 @@ getSetPieces <- function ( ) )$data ) %>% - dplyr::select(id, commonname) %>% + dplyr::select(.data$id, .data$commonname) %>% base::unique() # get squad master data from API @@ -146,7 +147,7 @@ getSetPieces <- function ( )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name) %>% + dplyr::select(.data$id, .data$name) %>% base::unique() # get matchplan data @@ -170,9 +171,9 @@ getSetPieces <- function ( # determine defending squad set_pieces <- set_pieces %>% - mutate( + dplyr::mutate( defendingSquadId = ifelse( - squadId == awaySquadId, homeSquadId, awaySquadId + .data$squadId == .data$awaySquadId, .data$homeSquadId, .data$awaySquadId ) ) @@ -181,16 +182,16 @@ getSetPieces <- function ( dplyr::left_join( dplyr::select( squads, - attackingSquadId = id, - attackingSquadName = name + attackingSquadId = .data$id, + attackingSquadName = .data$name ), by = base::c("squadId" = "attackingSquadId") ) %>% dplyr::left_join( dplyr::select( squads, - defendingSquadId = id, - defendingSquadName = name + defendingSquadId = .data$id, + defendingSquadName = .data$name ), by = base::c("defendingSquadId" = "defendingSquadId") ) @@ -199,25 +200,33 @@ getSetPieces <- function ( set_pieces <- set_pieces %>% dplyr::left_join( dplyr::select( - players, id, setPieceSubPhaseMainEventPlayerName = commonname + players, + .data$id, + setPieceSubPhaseMainEventPlayerName = .data$commonname ), by = base::c("setPieceSubPhaseMainEventPlayerId" = "id") ) %>% dplyr::left_join( dplyr::select( - players, id, setPieceSubPhasePassReceiverName = commonname + players, + .data$id, + setPieceSubPhasePassReceiverName = .data$commonname ), by = base::c("setPieceSubPhasePassReceiverId" = "id") ) %>% dplyr::left_join( dplyr::select( - players, id, setPieceSubPhaseFirstTouchPlayerName = commonname + players, + .data$id, + setPieceSubPhaseFirstTouchPlayerName = .data$commonname ), by = base::c("setPieceSubPhaseFirstTouchPlayerId" = "id") ) %>% dplyr::left_join( dplyr::select( - players, id, setPieceSubPhaseSecondTouchPlayerName = commonname + players, + .data$id, + setPieceSubPhaseSecondTouchPlayerName = .data$commonname ), by = base::c("setPieceSubPhaseSecondTouchPlayerId" = "id") ) diff --git a/R/getSquadIterationAverages.R b/R/getSquadIterationAverages.R index 4644a73..a857f38 100644 --- a/R/getSquadIterationAverages.R +++ b/R/getSquadIterationAverages.R @@ -6,6 +6,7 @@ #' @export #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the KPI averages aggregated per squad for the #' given iteration ID #' @@ -40,7 +41,7 @@ getSquadIterationAverages <- function (iteration, token) { # get squadIds squadIds <- squads %>% - dplyr::pull(id) + dplyr::pull(.data$id) # clean data squads <- .cleanData(squads) @@ -72,7 +73,7 @@ getSquadIterationAverages <- function (iteration, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) # get competitions from API iterations <- getIterations(token = token) @@ -81,39 +82,41 @@ getSquadIterationAverages <- function (iteration, token) { # unnest scorings averages <- averages_raw %>% - tidyr::unnest(kpis) %>% + tidyr::unnest(.data$kpis) %>% dplyr::select( - iterationId, - squadId, - matches, - kpiId, - value) %>% + .data$iterationId, + .data$squadId, + .data$matches, + .data$kpiId, + .data$value) %>% # join with kpis to ensure all kpiIds are present and order by kpiId dplyr::full_join(kpis, by = c("kpiId" = "id")) %>% - dplyr::arrange(kpiId, squadId) %>% + dplyr::arrange(.data$kpiId, .data$squadId) %>% # drop kpiId column - dplyr::select(-kpiId) %>% + dplyr::select(-.data$kpiId) %>% # pivot data tidyr::pivot_wider( - names_from = name, - values_from = value, + names_from = .data$name, + values_from = .data$value, values_fill = 0, values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(squadId) == FALSE) + dplyr::filter(base::is.na(.data$squadId) == FALSE) # merge with other data averages <- averages %>% dplyr::left_join( dplyr::select( - squads, id, wyscoutId, heimSpielId, skillCornerId, squadName = name + squads, .data$id, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId, squadName = .data$name ), by = c("squadId" = "id") ) %>% dplyr::left_join( dplyr::select( - iterations, id, competitionId, competitionName, competitionType, season + iterations, .data$id, .data$competitionId, .data$competitionName, + .data$competitionType, .data$season ), by = c("iterationId" = "id") ) diff --git a/R/getSquadIterationScores.R b/R/getSquadIterationScores.R index ecd6895..b4d05e6 100644 --- a/R/getSquadIterationScores.R +++ b/R/getSquadIterationScores.R @@ -6,6 +6,7 @@ #' @export #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the squad scores aggregated per squad for the #' given iteration ID #' @@ -37,12 +38,12 @@ getSquadIterationScores <- function (iteration, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name, idMappings) %>% + dplyr::select(.data$id, .data$name, .data$idMappings) %>% base::unique() # get squad Ids squadIds <- squads %>% - dplyr::pull(id) + dplyr::pull(.data$id) # clean data squads <- .cleanData(squads) @@ -74,7 +75,7 @@ getSquadIterationScores <- function (iteration, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) # get competitions iterations <- getIterations(token = token) @@ -83,39 +84,41 @@ getSquadIterationScores <- function (iteration, token) { # unnest scores scores <- scores_raw %>% - tidyr::unnest(squadScores) %>% + tidyr::unnest(.data$squadScores) %>% dplyr::select( - iterationId, - squadId, - matches, - squadScoreId, - value) %>% + .data$iterationId, + .data$squadId, + .data$matches, + .data$squadScoreId, + .data$value) %>% # join with kpis to ensure all kpiIds are present and order by kpiId dplyr::full_join(score_list, by = c("squadScoreId" = "id")) %>% - dplyr::arrange(squadScoreId, squadId) %>% + dplyr::arrange(.data$squadScoreId, .data$squadId) %>% # drop kpiId column - dplyr::select(-squadScoreId) %>% + dplyr::select(-.data$squadScoreId) %>% # pivot data tidyr::pivot_wider( - names_from = name, - values_from = value, + names_from = .data$name, + values_from = .data$value, values_fill = 0, values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(squadId) == FALSE) + dplyr::filter(base::is.na(.data$squadId) == FALSE) # merge with other data scores <- scores %>% dplyr::left_join( dplyr::select( - squads, id, wyscoutId, heimSpielId, skillCornerId, squadName = name + squads, .data$id, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId, squadName = .data$name ), by = c("squadId" = "id") ) %>% dplyr::left_join( dplyr::select( - iterations, id, competitionId, competitionName, competitionType, season + iterations, .data$id, .data$competitionId, .data$competitionName, + .data$competitionType, .data$season ), by = c("iterationId" = "id") ) diff --git a/R/getSquadMatchScores.R b/R/getSquadMatchScores.R index 818378d..f48ecb1 100644 --- a/R/getSquadMatchScores.R +++ b/R/getSquadMatchScores.R @@ -6,6 +6,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the scores and rations aggregated per squad for the given match ID #' #' @examples @@ -41,18 +42,18 @@ getSquadMatchScores <- function (matches, token) { ) )$data ) %>% - dplyr::select(id, iterationId, lastCalculationDate) %>% + dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% base::unique() # filter for fail matches fail_matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$id) # filter for avilable matches matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$id) # raise warnings if (base::length(fail_matches) > 0) { @@ -89,7 +90,7 @@ getSquadMatchScores <- function (matches, token) { # get unique iterationIds iterations <- matchInfo %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() # get squads master data from API @@ -110,7 +111,7 @@ getSquadMatchScores <- function (matches, token) { )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name, idMappings) %>% + dplyr::select(.data$id, .data$name, .data$idMappings) %>% base::unique() # clean data @@ -128,7 +129,7 @@ getSquadMatchScores <- function (matches, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) # get matchplan data matchplan <- @@ -145,27 +146,27 @@ getSquadMatchScores <- function (matches, token) { temp <- base::data.frame(dict[[side]]) %>% dplyr::rename( - squadId = id, - squadScoreId = squadScores.squadScoreId, - value = squadScores.value + squadId = .data$id, + squadScoreId = .data$squadScores.squadScoreId, + value = .data$squadScores.value ) # unnest scores temp <- temp %>% # join with scores to ensure all squadScoreId are present and order by squadScoreId dplyr::full_join(scores_list, by = c("squadScoreId" = "id")) %>% - dplyr::arrange(squadScoreId, squadId) %>% + dplyr::arrange(.data$squadScoreId, .data$squadId) %>% # drop squadScoreId column - dplyr::select(-squadScoreId) %>% + dplyr::select(-.data$squadScoreId) %>% # pivot data tidyr::pivot_wider( - names_from = name, - values_from = value, + names_from = .data$name, + values_from = .data$value, values_fill = 0, values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(squadId) == FALSE) %>% + dplyr::filter(base::is.na(.data$squadId) == FALSE) %>% dplyr::mutate( # add matchId matchId = dict$matchId) @@ -192,25 +193,28 @@ getSquadMatchScores <- function (matches, token) { scores <- scores %>% dplyr::left_join( dplyr::select( - matchplan, id, scheduledDate, matchDayIndex, matchDayName, iterationId + matchplan, .data$id, .data$scheduledDate, .data$matchDayIndex, + .data$matchDayName, .data$iterationId ), by = c("matchId" = "id") ) %>% dplyr::left_join( dplyr::select( - iterations, id, competitionId, competitionName, competitionType, season + iterations, .data$id, .data$competitionId, .data$competitionName, + .data$competitionType, .data$season ), by = c("iterationId" = "id") ) %>% dplyr::left_join( dplyr::select( - squads, id, wyscoutId, heimSpielId, skillCornerId, squadName = name + squads, .data$id, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId, squadName = .data$name ), by = c("squadId" = "id") ) %>% # fix some column names dplyr::rename( - dateTime = scheduledDate + dateTime = .data$scheduledDate ) # define column order diff --git a/R/getSquadMatchsums.R b/R/getSquadMatchsums.R index 178d7ea..837ed1d 100644 --- a/R/getSquadMatchsums.R +++ b/R/getSquadMatchsums.R @@ -6,6 +6,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the matchsums aggregated per squad for the given match ID #' #' @examples @@ -41,18 +42,18 @@ getSquadMatchsums <- function (matches, token) { ) )$data ) %>% - dplyr::select(id, iterationId, lastCalculationDate) %>% + dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% base::unique() # filter for fail matches fail_matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$id) # filter for avilable matches matches <- matchInfo %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(id) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$id) # raise warnings if (base::length(fail_matches) > 0) { @@ -89,7 +90,7 @@ getSquadMatchsums <- function (matches, token) { # get unique iterationIds iterations <- matchInfo %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() # get squad master data from API @@ -110,7 +111,7 @@ getSquadMatchsums <- function (matches, token) { )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name, idMappings) %>% + dplyr::select(.data$id, .data$name, .data$idMappings) %>% base::unique() # clean data @@ -128,7 +129,7 @@ getSquadMatchsums <- function (matches, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name) + dplyr::select(.data$id, .data$name) # get matchplan data matchplan <- @@ -145,27 +146,27 @@ getSquadMatchsums <- function (matches, token) { temp <- base::data.frame(dict[[side]]) %>% dplyr::rename( - squadId = id, - kpiId = kpis.kpiId, - value = kpis.value + squadId = .data$id, + kpiId = .data$kpis.kpiId, + value = .data$kpis.value ) # unnest scorings temp <- temp %>% # join with kpis to ensure all kpiIds are present and order by kpiId dplyr::full_join(kpis, by = c("kpiId" = "id")) %>% - dplyr::arrange(kpiId, squadId) %>% + dplyr::arrange(.data$kpiId, .data$squadId) %>% # drop kpiId column - dplyr::select(-kpiId) %>% + dplyr::select(-.data$kpiId) %>% # pivot data tidyr::pivot_wider( - names_from = name, - values_from = value, + names_from = .data$name, + values_from = .data$value, values_fill = 0, values_fn = base::sum ) %>% # filter for non NA columns that were created by full join - dplyr::filter(base::is.na(squadId) == FALSE) %>% + dplyr::filter(base::is.na(.data$squadId) == FALSE) %>% dplyr::mutate( # add matchId matchId = dict$matchId) @@ -192,25 +193,28 @@ getSquadMatchsums <- function (matches, token) { matchsums <- matchsums %>% dplyr::left_join( dplyr::select( - matchplan, id, scheduledDate, matchDayIndex, matchDayName, iterationId + matchplan, .data$id, .data$scheduledDate, .data$matchDayIndex, + .data$matchDayName, .data$iterationId ), by = c("matchId" = "id") ) %>% dplyr::left_join( dplyr::select( - iterations, id, competitionId, competitionName, competitionType, season + iterations, .data$id, .data$competitionId, .data$competitionName, + .data$competitionType, .data$season ), by = c("iterationId" = "id") ) %>% dplyr::left_join( dplyr::select( - squads, squadId = id, wyscoutId, heimSpielId, skillCornerId, squadName = name + squads, squadId = .data$id, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId, squadName = .data$name ), by = c("squadId" = "squadId") ) %>% # fix some column names dplyr::rename( - dateTime = scheduledDate, + dateTime = .data$scheduledDate, ) # define column order diff --git a/R/getSquadRatings.R b/R/getSquadRatings.R index ab06b1f..8a876a3 100644 --- a/R/getSquadRatings.R +++ b/R/getSquadRatings.R @@ -6,6 +6,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing the squad ratings for the given iteration ID #' #' @examples @@ -34,7 +35,7 @@ getSquadRatings <- function (iteration, token) { ) )$data %>% jsonlite::flatten() %>% - dplyr::select(id, name, idMappings) %>% + dplyr::select(.data$id, .data$name, .data$idMappings) %>% base::unique() # clean data @@ -66,17 +67,18 @@ getSquadRatings <- function (iteration, token) { # merge with other data ratings <- ratings %>% - tidyr::unnest(squadRatings) %>% + tidyr::unnest(.data$squadRatings) %>% dplyr::left_join( dplyr::select( - squads, id, wyscoutId, heimSpielId, skillCornerId, squadName = name + squads, .data$id, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId, squadName = .data$name ), by = c("squadId" = "id") ) %>% dplyr::left_join( dplyr::select( - iterations, id, competitionId, competitionName, - competitionType, season, competitionGender + iterations, .data$id, .data$competitionId, .data$competitionName, + .data$competitionType, .data$season, .data$competitionGender ), by = c("iterationId" = "id") ) diff --git a/R/getStartingPositions.R b/R/getStartingPositions.R index 09b05bf..e0af012 100644 --- a/R/getStartingPositions.R +++ b/R/getStartingPositions.R @@ -7,6 +7,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing all starting positions for a set of given #' match IDs #' @@ -67,17 +68,17 @@ getStartingPositions <- function ( # filter for fail matches fail_matches <- match_info %>% - dplyr::select(matchId, lastCalculationDate) %>% + dplyr::select(.data$matchId, .data$lastCalculationDate) %>% base::unique() %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(matchId) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$matchId) # filter for available matches matches <- match_info %>% - dplyr::select(matchId, lastCalculationDate) %>% + dplyr::select(.data$matchId, .data$lastCalculationDate) %>% base::unique() %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(matchId) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$matchId) # raise warnings if (base::length(fail_matches) > 0) { @@ -96,7 +97,7 @@ getStartingPositions <- function ( # get unique iterationIds iterations <- match_info %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() @@ -140,7 +141,7 @@ getStartingPositions <- function ( )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name) %>% + dplyr::select(.data$id, .data$name) %>% base::unique() # fix column names using regex @@ -157,12 +158,14 @@ getStartingPositions <- function ( # extract shirt numbers shirt_numbers_home <- match_info %>% dplyr::select( - matchId, squadId = squadHomeId, squadPlayers = squadHomePlayers + .data$matchId, squadId = .data$squadHomeId, + squadPlayers = .data$squadHomePlayers ) shirt_numbers_away <- match_info %>% dplyr::select( - matchId, squadId = squadAwayId, squadPlayers = squadAwayPlayers + .data$matchId, squadId = .data$squadAwayId, + squadPlayers = .data$squadAwayPlayers ) # combine data frames @@ -170,26 +173,26 @@ getStartingPositions <- function ( # unnest players column shirt_numbers <- shirt_numbers %>% - tidyr::unnest_longer(squadPlayers) + tidyr::unnest_longer(.data$squadPlayers) # normalize the JSON structure into separate columns shirt_numbers <- shirt_numbers %>% - tidyr::unnest(squadPlayers) %>% + tidyr::unnest(.data$squadPlayers) %>% dplyr::rename("playerId" = "id") # extract starting positions starting_positions_home <- match_info %>% dplyr::select( - matchId, - squadId = squadHomeId, - squadStartingPositions = squadHomeStartingPositions + .data$matchId, + squadId = .data$squadHomeId, + squadStartingPositions = .data$squadHomeStartingPositions ) starting_positions_away <- match_info %>% dplyr::select( - matchId, - squadId = squadAwayId, - squadStartingPositions = squadAwayStartingPositions + .data$matchId, + squadId = .data$squadAwayId, + squadStartingPositions = .data$squadAwayStartingPositions ) # combine data frames @@ -199,18 +202,18 @@ getStartingPositions <- function ( # unnest starting_positions column starting_positions <- starting_positions %>% - tidyr::unnest_longer(squadStartingPositions) + tidyr::unnest_longer(.data$squadStartingPositions) # normalize the JSON structure into separate columns starting_positions <- starting_positions %>% - tidyr::unnest(squadStartingPositions) + tidyr::unnest(.data$squadStartingPositions) # start merging dfs # merge starting_positions with squads starting_positions <- starting_positions %>% dplyr::left_join( - dplyr::select(squads, squadId = id, squadName = name), + dplyr::select(squads, squadId = .data$id, squadName = .data$name), by = base::c("squadId" = "squadId") ) @@ -226,23 +229,24 @@ getStartingPositions <- function ( # merge with players starting_positions <- starting_positions %>% dplyr::left_join( - dplyr::select(players, id, playerName = commonname), + dplyr::select(players, .data$id, playerName = .data$commonname), by = base::c("playerId" = "id") ) # merge with matches info starting_positions <- starting_positions %>% dplyr::left_join( - dplyr::select(matchplan, id, matchDayIndex, matchDayName, - dateTime = scheduledDate,lastCalculationDate, iterationId), + dplyr::select(matchplan, .data$id, .data$matchDayIndex, .data$matchDayName, + dateTime = .data$scheduledDate, .data$lastCalculationDate, + .data$iterationId), by = base::c("matchId" = "id") ) # merge with competition info starting_positions <- starting_positions %>% dplyr::left_join( - dplyr::select(iterations, id, competitionName, competitionId, - competitionType, season), + dplyr::select(iterations, .data$id, .data$competitionName, + .data$competitionId, .data$competitionType, .data$season), by = base::c("iterationId" = "id") ) diff --git a/R/getSubstitutions.R b/R/getSubstitutions.R index 1e4685f..fb7f953 100644 --- a/R/getSubstitutions.R +++ b/R/getSubstitutions.R @@ -7,6 +7,7 @@ #' @export #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing all line-up changes for a set of given #' match IDs #' @@ -67,17 +68,17 @@ getSubstitutions <- function ( # filter for fail matches fail_matches <- match_info %>% - dplyr::select(matchId, lastCalculationDate) %>% + dplyr::select(.data$matchId, .data$lastCalculationDate) %>% base::unique() %>% - dplyr::filter(base::is.na(lastCalculationDate) == TRUE) %>% - dplyr::pull(matchId) + dplyr::filter(base::is.na(.data$lastCalculationDate) == TRUE) %>% + dplyr::pull(.data$matchId) # filter for available matches matches <- match_info %>% - dplyr::select(matchId, lastCalculationDate) %>% + dplyr::select(.data$matchId, .data$lastCalculationDate) %>% base::unique() %>% - dplyr::filter(base::is.na(lastCalculationDate) == FALSE) %>% - dplyr::pull(matchId) + dplyr::filter(base::is.na(.data$lastCalculationDate) == FALSE) %>% + dplyr::pull(.data$matchId) # raise warnings if (base::length(fail_matches) > 0) { @@ -96,7 +97,7 @@ getSubstitutions <- function ( # get unique iterationIds iterations <- match_info %>% - dplyr::pull(iterationId) %>% + dplyr::pull(.data$iterationId) %>% base::unique() @@ -140,7 +141,7 @@ getSubstitutions <- function ( )$data %>% jsonlite::flatten() ) %>% - dplyr::select(id, name) %>% + dplyr::select(.data$id, .data$name) %>% base::unique() # fix column names using regex @@ -157,12 +158,14 @@ getSubstitutions <- function ( # extract shirt numbers shirt_numbers_home <- match_info %>% dplyr::select( - matchId, squadId = squadHomeId, squadPlayers = squadHomePlayers + .data$matchId, squadId = .data$squadHomeId, + squadPlayers = .data$squadHomePlayers ) shirt_numbers_away <- match_info %>% dplyr::select( - matchId, squadId = squadAwayId, squadPlayers = squadAwayPlayers + .data$matchId, squadId = .data$squadAwayId, + squadPlayers = .data$squadAwayPlayers ) # combine data frames @@ -170,48 +173,48 @@ getSubstitutions <- function ( # unnest players column shirt_numbers <- shirt_numbers %>% - tidyr::unnest_longer(squadPlayers) + tidyr::unnest_longer(.data$squadPlayers) # normalize the JSON structure into separate columns shirt_numbers <- shirt_numbers %>% - tidyr::unnest(squadPlayers) %>% + tidyr::unnest(.data$squadPlayers) %>% dplyr::rename("playerId" = "id") # extract substitutions substitutions_home <- match_info %>% dplyr::select( - matchId, - squadId = squadHomeId, - squadSubstitutions = squadHomeSubstitutions + .data$matchId, + squadId = .data$squadHomeId, + squadSubstitutions = .data$squadHomeSubstitutions ) substitutions_away <- match_info %>% dplyr::select( - matchId, - squadId = squadAwayId, - squadSubstitutions = squadAwaySubstitutions + .data$matchId, + squadId = .data$squadAwayId, + squadSubstitutions = .data$squadAwaySubstitutions ) # combine data frames substitutions <- dplyr::bind_rows(substitutions_home, substitutions_away) %>% - filter(purrr::map_lgl(squadSubstitutions, ~ base::is.data.frame(.))) + dplyr::filter(purrr::map_lgl(.data$squadSubstitutions, ~ base::is.data.frame(.))) # unnest starting_positions column substitutions <- substitutions %>% - filter(lengths(squadSubstitutions) > 0) %>% - tidyr::unnest_longer(squadSubstitutions) + dplyr::filter(lengths(.data$squadSubstitutions) > 0) %>% + tidyr::unnest_longer(.data$squadSubstitutions) # normalize the JSON structure into separate columns substitutions <- substitutions %>% - tidyr::unnest(squadSubstitutions) %>% - tidyr::unnest(gameTime) + tidyr::unnest(.data$squadSubstitutions) %>% + tidyr::unnest(.data$gameTime) # start merging dfs # merge substitutions with squads substitutions <- substitutions %>% dplyr::left_join( - dplyr::select(squads, squadId = id, squadName = name), + dplyr::select(squads, squadId = .data$id, squadName = .data$name), by = base::c("squadId" = "squadId") ) @@ -226,10 +229,10 @@ getSubstitutions <- function ( dplyr::left_join( dplyr::select( shirt_numbers, - matchId, - squadId, - exchangedPlayerId = playerId, - exchangedShirtNumber = shirtNumber + .data$matchId, + .data$squadId, + exchangedPlayerId = .data$playerId, + exchangedShirtNumber = .data$shirtNumber ), by = base::c( "exchangedPlayerId" = "exchangedPlayerId", @@ -241,14 +244,14 @@ getSubstitutions <- function ( # merge with players substitutions <- substitutions %>% dplyr::left_join( - dplyr::select(players, id, playerName = commonname), + dplyr::select(players, .data$id, playerName = .data$commonname), by = base::c("playerId" = "id") ) %>% dplyr::left_join( dplyr::select( players, - exchangedPlayerId = id, - exchangedPlayerName = commonname + exchangedPlayerId = .data$id, + exchangedPlayerName = .data$commonname ), by = base::c("exchangedPlayerId" = "exchangedPlayerId") ) @@ -256,16 +259,17 @@ getSubstitutions <- function ( # merge with matches info substitutions <- substitutions %>% dplyr::left_join( - dplyr::select(matchplan, id, matchDayIndex, matchDayName, - dateTime = scheduledDate,lastCalculationDate, iterationId), + dplyr::select(matchplan, .data$id, .data$matchDayIndex, + .data$matchDayName, dateTime = .data$scheduledDate, + .data$lastCalculationDate, .data$iterationId), by = base::c("matchId" = "id") ) # merge with competition info substitutions <- substitutions %>% dplyr::left_join( - dplyr::select(iterations, id, competitionName, competitionId, - competitionType, season), + dplyr::select(iterations, .data$id, .data$competitionName, + .data$competitionId, .data$competitionType, .data$season), by = base::c("iterationId" = "id") ) diff --git a/R/utils.R b/R/utils.R index ba5823f..756e1ca 100644 --- a/R/utils.R +++ b/R/utils.R @@ -52,6 +52,9 @@ } } +# private storage for bucket +.api_state <- new.env(parent = emptyenv()) + #' Applies the rate limit policy to the .callAPI function #' #' @noRd @@ -65,7 +68,7 @@ .callAPIlimited <- function(base_url, id = "", suffix = "", token) { # check if Token bucket exist and create it if not - if (!exists("bucket")) { + if (is.null(.api_state$bucket)) { # get response from API response <- .callAPI(base_url, id, suffix, token) @@ -81,7 +84,7 @@ # create TokenBucket - bucket <<- TokenBucket( + .api_state$bucket <- TokenBucket( # set default rate, capacity, available tokens and time capacity = capacity, intervall = intervall, @@ -95,15 +98,15 @@ } # check if a token is available - if (bucket$isTokenAvailable()) { + if (.api_state$bucket$isTokenAvailable()) { # get API response response <- .callAPI(base_url, id, suffix, token) # consume a token - bucket$consumeToken() + .api_state$bucket$consumeToken() } else { # wait for bucket intervall - Sys.sleep(bucket$intervall) + Sys.sleep(.api_state$bucket$intervall) # call function again response <- .callAPIlimited(base_url, id, suffix, token) @@ -122,6 +125,7 @@ #' @param data a data frame #' #' @importFrom dplyr %>% +#' @importFrom rlang .data #' @return a dataframe containing clean columns names and SkillCorner/HeimSpiel #' columns .cleanData <- function (data) { @@ -151,16 +155,10 @@ # edit column names data <- data %>% - dplyr::rename(skillCornerId = "skillCorner", - heimSpielId = "heimSpiel", - wyscoutId = "wyscout") - - # edit column types - data <- data %>% - mutate( - skillCornerId = as.integer(skillCornerId), - heimSpielId = as.integer(heimSpielId), - wyscoutId = as.integer(wyscoutId) + dplyr::mutate( + skillCornerId = as.integer(.data$skillCorner), + heimSpielId = as.integer(.data$heimSpiel), + wyscoutId = as.integer(.data$wyscout) ) # return squads @@ -174,19 +172,17 @@ #' to control the frequency of certain actions or requests based on available tokens. #' Tokens are added to the bucket at a specified rate and can be consumed when needed. #' -#' @name TokenBucket -#' -#' @slot capacity the maximum amount of tokens in the bucket -#' @slot tokens the amount of token currently available in the bucket -#' @slot intervall the duration in seconds after which the bucket gets refilled -#' @slot last_update the timestamp from the liast time tokens were added or consumed +#' @field capacity The maximum number of tokens in the bucket. +#' @field tokens The number of tokens currently available in the bucket. +#' @field interval The duration in seconds after which the bucket gets refilled. +#' @field last_update The timestamp of the last update to the bucket. #' -#' @importFrom methods new -#' -#' @export +#' @exportClass TokenBucket #' #' @keywords classes #' +#' @importFrom methods new +#' #' @examples #' \donttest{ #' try({ diff --git a/man/TokenBucket.Rd b/man/TokenBucket-class.Rd similarity index 66% rename from man/TokenBucket.Rd rename to man/TokenBucket-class.Rd index 698faa0..b8433d4 100644 --- a/man/TokenBucket.Rd +++ b/man/TokenBucket-class.Rd @@ -1,7 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R \docType{class} -\name{TokenBucket} +\name{TokenBucket-class} +\alias{TokenBucket-class} \alias{TokenBucket} \title{TokenBucket Class} \description{ @@ -9,16 +10,16 @@ This class represents a token bucket, which is a rate limiting mechanism used to control the frequency of certain actions or requests based on available tokens. Tokens are added to the bucket at a specified rate and can be consumed when needed. } -\section{Slots}{ +\section{Fields}{ \describe{ -\item{\code{capacity}}{the maximum amount of tokens in the bucket} +\item{\code{capacity}}{The maximum number of tokens in the bucket.} -\item{\code{tokens}}{the amount of token currently available in the bucket} +\item{\code{tokens}}{The number of tokens currently available in the bucket.} -\item{\code{intervall}}{the duration in seconds after which the bucket gets refilled} +\item{\code{interval}}{The duration in seconds after which the bucket gets refilled.} -\item{\code{last_update}}{the timestamp from the liast time tokens were added or consumed} +\item{\code{last_update}}{The timestamp of the last update to the bucket.} }} diff --git a/man/getPlayerMatchsums.Rd b/man/getPlayerMatchsums.Rd index a502f0b..ad3600c 100644 --- a/man/getPlayerMatchsums.Rd +++ b/man/getPlayerMatchsums.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getPlayerMatchsums.R +% Please edit documentation in R/getPlayerMatchSums.R \name{getPlayerMatchsums} \alias{getPlayerMatchsums} \title{Return a dataframe that contains all player matchsums for a given match ID} diff --git a/man/getSquadMatchsums.Rd b/man/getSquadMatchsums.Rd index df3769f..c2f59c9 100644 --- a/man/getSquadMatchsums.Rd +++ b/man/getSquadMatchsums.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getSquadMatchsums.R +% Please edit documentation in R/getSquadMatchSums.R \name{getSquadMatchsums} \alias{getSquadMatchsums} \title{Return a dataframe that contains squad level matchsums for a given match ID} From e5b752972d067c5cd7999d793a4e41651a95fd40 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 27 Aug 2025 07:58:25 +0200 Subject: [PATCH 02/12] prepare package fro CRAN upload --- DESCRIPTION | 6 +++--- R/getAccessToken.R | 18 +++++++++--------- R/getEvents.R | 22 +++++++++++++++++----- R/getFormations.R | 18 +++++++++++++----- R/getIterations.R | 14 ++++++++++---- R/getMatches.R | 19 +++++++++++++------ R/getPlayerIterationAverages.R | 18 +++++++++++++----- R/getPlayerIterationScores.R | 22 ++++++++++++++++------ R/getPlayerMatchScores.R | 22 ++++++++++++++++------ R/getPlayerMatchsums.R | 18 +++++++++++++----- R/getPlayerProfileScores.R | 22 ++++++++++++++++------ R/getSetPieces.R | 18 +++++++++++++----- R/getSquadIterationAverages.R | 18 +++++++++++++----- R/getSquadIterationScores.R | 18 +++++++++++++----- R/getSquadMatchScores.R | 18 +++++++++++++----- R/getSquadMatchsums.R | 18 +++++++++++++----- R/getSquadRatings.R | 18 +++++++++++++----- R/getStartingPositions.R | 18 +++++++++++++----- R/getSubstitutions.R | 18 +++++++++++++----- R/utils.R | 2 +- man/getAccessToken.Rd | 20 ++++++++++---------- man/getEvents.Rd | 22 +++++++++++++++++----- man/getFormations.Rd | 18 +++++++++++++----- man/getIterations.Rd | 14 ++++++++++---- man/getMatches.Rd | 18 +++++++++++++----- man/getPlayerIterationAverages.Rd | 18 +++++++++++++----- man/getPlayerIterationScores.Rd | 20 +++++++++++++++----- man/getPlayerMatchScores.Rd | 20 +++++++++++++++----- man/getPlayerMatchsums.Rd | 18 +++++++++++++----- man/getPlayerProfileScores.Rd | 20 +++++++++++++++----- man/getSetPieces.Rd | 18 +++++++++++++----- man/getSquadIterationAverages.Rd | 18 +++++++++++++----- man/getSquadIterationScores.Rd | 18 +++++++++++++----- man/getSquadMatchScores.Rd | 18 +++++++++++++----- man/getSquadMatchsums.Rd | 18 +++++++++++++----- man/getSquadRatings.Rd | 18 +++++++++++++----- man/getStartingPositions.Rd | 18 +++++++++++++----- man/getSubstitutions.Rd | 18 +++++++++++++----- 38 files changed, 482 insertions(+), 195 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 483e2ad..e1c3b94 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,13 @@ Package: impectR -Title: Access data from the Impect API +Title: Access Data from the Impect API Version: 2.4.3 Authors@R: c( person("Impect", "GmbH", , "info.impect@impect.com", role = c("cph")), person("Florian", "Schmitt", , "florian.schmitt@impect.com", role = c("aut", "cre")), person("Thomas", "Walentin", , "thomas.walentin@impect.com", role = c("ctb")) ) -Maintainer: Florian schmitt -Description: This package is used to pull data from the Impect Customer API V5. It can retrieve data such as events or match sums. It supports MAC and Windows computers. +Maintainer: Florian Schmitt +Description: Pull data from the 'Impect' Customer API . The package can retrieve data such as events or match sums. License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/R/getAccessToken.R b/R/getAccessToken.R index 5271a01..44a953c 100644 --- a/R/getAccessToken.R +++ b/R/getAccessToken.R @@ -1,18 +1,18 @@ -#' Get an access token from the Impect Customer API +#' Get an access token from the 'Impect' Customer API #' -#' @param username your IMPECT username -#' @param password your IMPECT password +#' @param username your 'IMPECT' username +#' @param password your 'IMPECT' password #' #' @return a string containing a bearer token #' @export #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' username <- "yourUsername" -#' password <- "youPassword" -#' token <- getAccessToken(username = username, password = password) -#' }) +#' # Toy example: this will error quickly (no credentials) +#' try(getAccessToken(username = "invalidUser", password = "invalidPassword")) +#' +#' # Real usage: requires valid credentials +#' \dontrun{ +#' token <- getAccessToken(username = "yourUsername", password = "yourPassword") #' } getAccessToken <- function(username, password) { # validate input parameters diff --git a/R/getEvents.R b/R/getEvents.R index fcfff6f..ec72291 100644 --- a/R/getEvents.R +++ b/R/getEvents.R @@ -1,7 +1,7 @@ #' Return a dataframe that contains all events and kpi values for a set of given #' match IDs #' -#' @param matches IMPECT match ID or a list of match IDs +#' @param matches 'IMPECT' match ID or a list of match IDs #' @param token bearer token #' @param include_kpis include KPIs in event data #' @param include_set_pieces include additional set piece data in event data @@ -14,10 +14,22 @@ #' match IDs #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' events <- getEvents(matches = c(84248), token = token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(events <- getEvents( +#' matches = c(0, 1), +#' token = "invalid", +#' include_kpis = T, +#' include_set_pieces = F +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' events <- getEvents( +#' matches = c(84248, 158150), +#' token = "yourToken", +#' include_kpis = T, +#' include_set_pieces = F +#' ) #' } getEvents <- function ( matches, diff --git a/R/getFormations.R b/R/getFormations.R index 27eda6d..fce188c 100644 --- a/R/getFormations.R +++ b/R/getFormations.R @@ -1,7 +1,7 @@ #' Return a dataframe that contains all starting formations for a set of given #' match IDs #' -#' @param matches IMPECT match ID or a list of match IDs +#' @param matches 'IMPECT' match ID or a list of match IDs #' @param token bearer token #' #' @export @@ -12,10 +12,18 @@ #' match IDs #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' formations <- getFormations(matches = c(84248), token = token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(events <- getFormations( +#' matches = c(0, 1), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' formations <- getFormations( +#' matches = c(84248, 158150), +#' token = "yourToken" +#' ) #' } getFormations <- function ( matches, diff --git a/R/getIterations.R b/R/getIterations.R index 431ff68..5ccd3fc 100644 --- a/R/getIterations.R +++ b/R/getIterations.R @@ -8,10 +8,16 @@ #' @return a dataframe containing all iterations available to the user #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' competitionIterations <- getCompetitions(token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(events <- getIterations( +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' iterations <- getIterations( +#' token = "yourToken" +#' ) #' } getIterations <- function(token) { # get iteration data from API diff --git a/R/getMatches.R b/R/getMatches.R index 9cd16aa..e7cda8c 100644 --- a/R/getMatches.R +++ b/R/getMatches.R @@ -1,6 +1,6 @@ #' Return a dataframe with basic information for all matches for a given iteration ID #' -#' @param iteration IMPECT iteration ID +#' @param iteration 'IMPECT' iteration ID #' @param token bearer token #' #' @export @@ -9,12 +9,19 @@ #' @importFrom rlang .data #' @return a dataframe containing all matches for a given iteration ID #' -#' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' matches <- getMatches(518, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(matchplan <- getMatches( +#' iteration = 0, +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' matchplan <- getMatches( +#' iteration = 1004, +#' token = "yourToken" +#' ) #' } getMatches <- function(iteration, token) { diff --git a/R/getPlayerIterationAverages.R b/R/getPlayerIterationAverages.R index e7d08ed..d7d8c78 100644 --- a/R/getPlayerIterationAverages.R +++ b/R/getPlayerIterationAverages.R @@ -1,6 +1,6 @@ #' Return a dataframe that contains all player averages for a given iteration ID #' -#' @param iteration Impect iteration ID +#' @param iteration 'IMPECT' iteration ID #' @param token bearer token #' #' @export @@ -11,10 +11,18 @@ #' position for the given iteration ID #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' playerIterationAverages <- getPlayerIterationAverages(518, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(player_avgs <- getPlayerIterationAverages( +#' iteration = 0, +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' player_avgs <- getPlayerIterationAverages( +#' iteration = 1004, +#' token = "yourToken" +#' ) #' } getPlayerIterationAverages <- function (iteration, token) { diff --git a/R/getPlayerIterationScores.R b/R/getPlayerIterationScores.R index 557f2da..3ff8d37 100644 --- a/R/getPlayerIterationScores.R +++ b/R/getPlayerIterationScores.R @@ -15,7 +15,7 @@ allowed_positions <- c( #' Return a dataframe that contains all player scores for a given iteration ID #' -#' @param iteration Impect iteration ID +#' @param iteration 'IMPECT' iteration ID #' @param positions list of position names. Must be one of: "GOALKEEPER", #' "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", #' "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", @@ -30,10 +30,20 @@ allowed_positions <- c( #' the given iteration ID and list of positions #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' scores <- getPlayerIterationScores(518, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(player_scores <- getPlayerIterationScores( +#' iteration = 0, +#' positions = c("INVALID_POSITION_1", "INVALID_POSITION_2"), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' player_scores <- getPlayerIterationScores( +#' iteration = 1004, +#' positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"), +#' token = "yourToken" +#' ) #' } getPlayerIterationScores <- function (iteration, positions, token) { @@ -123,7 +133,7 @@ getPlayerIterationScores <- function (iteration, positions, token) { squadIds[!squadIds %in% scores_raw$squadId] ) if (base::length(error_list) > 0) { - base::cat( + base::message( base::sprintf( "No players played at position(s) %s for following squads:\n\t%s", positions, paste(error_list, collapse = ", ") diff --git a/R/getPlayerMatchScores.R b/R/getPlayerMatchScores.R index 3d51bef..4f85f76 100644 --- a/R/getPlayerMatchScores.R +++ b/R/getPlayerMatchScores.R @@ -16,7 +16,7 @@ allowed_positions <- c( #' Return a dataframe that contains all player scores for a given match ID #' and list of positions #' -#' @param matches Impect match IDs +#' @param matches 'IMPECT' match IDs #' @param positions list of position names. Must be one of: "GOALKEEPER", #' "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", #' "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", @@ -31,10 +31,20 @@ allowed_positions <- c( #' position for the given match ID and list of positions #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' playerMatchScores <- getPlayerMatchsums(84248, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(player_match_scores <- getPlayerMatchScores( +#' matches = c(0, 1), +#' positions = c("INVALID_POSITION_1", "INVALID_POSITION_2"), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' player_match_scores <- getPlayerMatchScores( +#' matches = c(84248, 158150), +#' positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"), +#' token = "yourToken" +#' ) #' } getPlayerMatchScores <- function (matches, positions, token) { @@ -283,7 +293,7 @@ getPlayerMatchScores <- function (matches, positions, token) { matches[!matches %in% scores$matchId] ) if (base::length(error_list) > 0) { - base::cat( + base::message( base::sprintf( "No players played at position(s) %s for following matches:\n\t%s", positions, paste(error_list, collapse = ", ") diff --git a/R/getPlayerMatchsums.R b/R/getPlayerMatchsums.R index 1b24476..19bc41b 100644 --- a/R/getPlayerMatchsums.R +++ b/R/getPlayerMatchsums.R @@ -1,6 +1,6 @@ #' Return a dataframe that contains all player matchsums for a given match ID #' -#' @param matches Impect match IDs +#' @param matches 'IMPECT' match IDs #' @param token bearer token #' #' @export @@ -10,10 +10,18 @@ #' @return a dataframe containing the matchsums aggregated per player and position for the given match ID #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' matchsums <- getPlayerMatchsums(84248, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(player_match_sums <- getPlayerMatchsums( +#' matches = c(0, 1), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' player_match_sums <- getPlayerMatchsums( +#' matches = c(84248, 158150), +#' token = "yourToken" +#' ) #' } getPlayerMatchsums <- function (matches, token) { diff --git a/R/getPlayerProfileScores.R b/R/getPlayerProfileScores.R index 881741a..2133bc5 100644 --- a/R/getPlayerProfileScores.R +++ b/R/getPlayerProfileScores.R @@ -16,7 +16,7 @@ allowed_positions <- c( #' Return a dataframe that contains all player profile scores for a given #' iteration ID #' -#' @param iteration Impect iteration ID +#' @param iteration 'IMPECT' iteration ID #' @param positions list of position names. Must be one of: "GOALKEEPER", #' "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", #' "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", @@ -31,10 +31,20 @@ allowed_positions <- c( #' for the given iteration ID and list of positions #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' scores <- getPlayerProfileScores(518, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(player_profile_scores <- getPlayerProfileScores( +#' iteration = 0, +#' positions = c("INVALID_POSITION_1", "INVALID_POSITION_2"), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' player_profile_scores <- getPlayerProfileScores( +#' iteration = 1004, +#' positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"), +#' token = "yourToken" +#' ) #' } getPlayerProfileScores <- function (iteration, positions, token) { @@ -124,7 +134,7 @@ getPlayerProfileScores <- function (iteration, positions, token) { squadIds[!squadIds %in% scores_raw$squadId] ) if (base::length(error_list) > 0) { - base::cat( + base::message( base::sprintf( "No players played at position(s) %s for following squads:\n\t%s", positions, paste(error_list, collapse = ", ") diff --git a/R/getSetPieces.R b/R/getSetPieces.R index c9a0479..30cc930 100644 --- a/R/getSetPieces.R +++ b/R/getSetPieces.R @@ -1,7 +1,7 @@ #' Return a dataframe that contains all set pieces and aggregated kpi values per #' set piece sub phase for a set of given list of match IDs #' -#' @param matches list fo IMPECT match IDs +#' @param matches list fo 'IMPECT' match IDs #' @param token bearer token #' #' @export @@ -12,10 +12,18 @@ #' set piece sub phase for a set of given list of match IDs #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' events <- getSetPieces(matches = c(84248), token = token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(set_pieces <- getSetPieces( +#' matches = c(0, 1), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' set_pieces <- getSetPieces( +#' matches = c(84248, 158150), +#' token = "yourToken" +#' ) #' } getSetPieces <- function ( matches, diff --git a/R/getSquadIterationAverages.R b/R/getSquadIterationAverages.R index a857f38..f529cfc 100644 --- a/R/getSquadIterationAverages.R +++ b/R/getSquadIterationAverages.R @@ -1,6 +1,6 @@ #' Return a dataframe that contains all squads averages for a given iteration ID #' -#' @param iteration Impect iteration ID +#' @param iteration 'IMPECT' iteration ID #' @param token bearer token #' @export @@ -11,10 +11,18 @@ #' given iteration ID #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' squadIterationAverages <- getSquadIterationAverages(518, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(squad_avgs <- getSquadIterationAverages( +#' iteration = 0, +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' squad_avgs <- getSquadIterationAverages( +#' iteration = 1004, +#' token = "yourToken" +#' ) #' } getSquadIterationAverages <- function (iteration, token) { diff --git a/R/getSquadIterationScores.R b/R/getSquadIterationScores.R index b4d05e6..e606aff 100644 --- a/R/getSquadIterationScores.R +++ b/R/getSquadIterationScores.R @@ -1,6 +1,6 @@ #' Return a dataframe that contains all squads scores for a given iteration ID #' -#' @param iteration Impect iteration ID +#' @param iteration 'IMPCET' iteration ID #' @param token bearer token #' @export @@ -11,10 +11,18 @@ #' given iteration ID #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' scores <- getSquadIterationScores(518, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(squad_scores <- getSquadIterationScores( +#' iteration = 0, +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' squad_scores <- getSquadIterationScores( +#' iteration = 1004, +#' token = "yourToken" +#' ) #' } getSquadIterationScores <- function (iteration, token) { diff --git a/R/getSquadMatchScores.R b/R/getSquadMatchScores.R index f48ecb1..dd092be 100644 --- a/R/getSquadMatchScores.R +++ b/R/getSquadMatchScores.R @@ -1,6 +1,6 @@ #' Return a dataframe that contains squad level scores and ratios for a given match ID #' -#' @param matches Impect match IDs +#' @param matches 'IMPECT' match IDs #' @param token bearer token #' #' @export @@ -10,10 +10,18 @@ #' @return a dataframe containing the scores and rations aggregated per squad for the given match ID #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' squadMatchScores <- getSquadMatchsums(84248, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(squad_match_scores <- getSquadMatchScores( +#' matches = c(0, 1), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' squad_match_scores <- getSquadMatchScores( +#' matches = c(84248, 158150), +#' token = "yourToken" +#' ) #' } getSquadMatchScores <- function (matches, token) { diff --git a/R/getSquadMatchsums.R b/R/getSquadMatchsums.R index 837ed1d..ebfff35 100644 --- a/R/getSquadMatchsums.R +++ b/R/getSquadMatchsums.R @@ -1,6 +1,6 @@ #' Return a dataframe that contains squad level matchsums for a given match ID #' -#' @param matches Impect match IDs +#' @param matches 'IMPECT' match IDs #' @param token bearer token #' #' @export @@ -10,10 +10,18 @@ #' @return a dataframe containing the matchsums aggregated per squad for the given match ID #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' matchsums <- getSquadMatchsums(84248, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(squad_match_sums <- getSquadMatchsums( +#' matches = c(0, 1), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' squad_match_sums <- getSquadMatchsums( +#' matches = c(84248, 158150), +#' token = "yourToken" +#' ) #' } getSquadMatchsums <- function (matches, token) { diff --git a/R/getSquadRatings.R b/R/getSquadRatings.R index 8a876a3..2fa4fda 100644 --- a/R/getSquadRatings.R +++ b/R/getSquadRatings.R @@ -1,6 +1,6 @@ #' Return a dataframe that contains squad ratings for a given iteration ID #' -#' @param iteration Impect iteration ID +#' @param iteration 'IMPECT' iteration ID #' @param token bearer token #' #' @export @@ -10,10 +10,18 @@ #' @return a dataframe containing the squad ratings for the given iteration ID #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' ratings <- getSquadRatings(1005, token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(squad_ratings <- getSquadRatings( +#' iteration = 0, +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' squad_ratings <- getSquadRatings( +#' iteration = 1004, +#' token = "yourToken" +#' ) #' } getSquadRatings <- function (iteration, token) { diff --git a/R/getStartingPositions.R b/R/getStartingPositions.R index e0af012..aa4606c 100644 --- a/R/getStartingPositions.R +++ b/R/getStartingPositions.R @@ -1,7 +1,7 @@ #' Return a dataframe that contains all starting positions for a set of given #' match IDs #' -#' @param matches IMPECT match ID or a list of match IDs +#' @param matches 'IMPECT' match ID or a list of match IDs #' @param token bearer token #' #' @export @@ -12,10 +12,18 @@ #' match IDs #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' startingPositions <- getStartingPositions(matches = c(84248), token = token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(starting_pos <- getStartingPositions( +#' matches = c(0, 1), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' starting_pos <- getStartingPositions( +#' matches = c(84248, 158150), +#' token = "yourToken" +#' ) #' } getStartingPositions <- function ( matches, diff --git a/R/getSubstitutions.R b/R/getSubstitutions.R index fb7f953..7d75a48 100644 --- a/R/getSubstitutions.R +++ b/R/getSubstitutions.R @@ -1,7 +1,7 @@ #' Return a dataframe that contains all line-up changes for a set of given #' match IDs #' -#' @param matches IMPECT match ID or a list of match IDs +#' @param matches 'IMPECT' match ID or a list of match IDs #' @param token bearer token #' #' @export @@ -12,10 +12,18 @@ #' match IDs #' #' @examples -#' \donttest{ -#' try({ # prevent cran errors -#' substitutions <- getSubstitutions(matches = c(84248), token = token) -#' }) +#' # Toy example: this will error quickly (no API token) +#' try(subs <- getSubstitutions( +#' matches = c(0, 1), +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' subs <- getSubstitutions( +#' matches = c(84248, 158150), +#' token = "yourToken" +#' ) #' } getSubstitutions <- function ( matches, diff --git a/R/utils.R b/R/utils.R index 756e1ca..2b0115c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -29,7 +29,7 @@ } else if (httr::status_code(response) == 429) { # handle rate limiting (429 status code) message <- httr::content(response, "parsed")$message - base::cat(base::paste("Received status code 429 (", message, + base::message(base::paste("Received status code 429 (", message, "), retrying in", retry_delay, "seconds...\n")) Sys.sleep(retry_delay) } else if (httr::status_code(response) %in% c(401, 403)) { diff --git a/man/getAccessToken.Rd b/man/getAccessToken.Rd index 8115f8a..6c58005 100644 --- a/man/getAccessToken.Rd +++ b/man/getAccessToken.Rd @@ -2,27 +2,27 @@ % Please edit documentation in R/getAccessToken.R \name{getAccessToken} \alias{getAccessToken} -\title{Get an access token from the Impect Customer API} +\title{Get an access token from the 'Impect' Customer API} \usage{ getAccessToken(username, password) } \arguments{ -\item{username}{your IMPECT username} +\item{username}{your 'IMPECT' username} -\item{password}{your IMPECT password} +\item{password}{your 'IMPECT' password} } \value{ a string containing a bearer token } \description{ -Get an access token from the Impect Customer API +Get an access token from the 'Impect' Customer API } \examples{ -\donttest{ -try({ # prevent cran errors - username <- "yourUsername" - password <- "youPassword" - token <- getAccessToken(username = username, password = password) -}) +# Toy example: this will error quickly (no credentials) +try(getAccessToken(username = "invalidUser", password = "invalidPassword")) + +# Real usage: requires valid credentials +\dontrun{ + token <- getAccessToken(username = "yourUsername", password = "yourPassword") } } diff --git a/man/getEvents.Rd b/man/getEvents.Rd index f2c55cc..abc3617 100644 --- a/man/getEvents.Rd +++ b/man/getEvents.Rd @@ -8,7 +8,7 @@ match IDs} getEvents(matches, token, include_kpis = TRUE, include_set_pieces = FALSE) } \arguments{ -\item{matches}{IMPECT match ID or a list of match IDs} +\item{matches}{'IMPECT' match ID or a list of match IDs} \item{token}{bearer token} @@ -25,9 +25,21 @@ Return a dataframe that contains all events and kpi values for a set of given match IDs } \examples{ -\donttest{ -try({ # prevent cran errors - events <- getEvents(matches = c(84248), token = token) -}) +# Toy example: this will error quickly (no API token) +try(events <- getEvents( + matches = c(0, 1), + token = "invalid", + include_kpis = T, + include_set_pieces = F +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +events <- getEvents( + matches = c(84248, 158150), + token = "yourToken", + include_kpis = T, + include_set_pieces = F +) } } diff --git a/man/getFormations.Rd b/man/getFormations.Rd index 2ed1947..a1c1689 100644 --- a/man/getFormations.Rd +++ b/man/getFormations.Rd @@ -8,7 +8,7 @@ match IDs} getFormations(matches, token) } \arguments{ -\item{matches}{IMPECT match ID or a list of match IDs} +\item{matches}{'IMPECT' match ID or a list of match IDs} \item{token}{bearer token} } @@ -21,9 +21,17 @@ Return a dataframe that contains all starting formations for a set of given match IDs } \examples{ -\donttest{ -try({ # prevent cran errors - formations <- getFormations(matches = c(84248), token = token) -}) +# Toy example: this will error quickly (no API token) +try(events <- getFormations( + matches = c(0, 1), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +formations <- getFormations( + matches = c(84248, 158150), + token = "yourToken" +) } } diff --git a/man/getIterations.Rd b/man/getIterations.Rd index 6a63e0c..a4ec1db 100644 --- a/man/getIterations.Rd +++ b/man/getIterations.Rd @@ -16,9 +16,15 @@ a dataframe containing all iterations available to the user Return a dataframe containing all iterations available to the user } \examples{ -\donttest{ -try({ # prevent cran errors - competitionIterations <- getCompetitions(token) -}) +# Toy example: this will error quickly (no API token) +try(events <- getIterations( + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +iterations <- getIterations( + token = "yourToken" +) } } diff --git a/man/getMatches.Rd b/man/getMatches.Rd index bf36efe..a571b40 100644 --- a/man/getMatches.Rd +++ b/man/getMatches.Rd @@ -7,7 +7,7 @@ getMatches(iteration, token) } \arguments{ -\item{iteration}{IMPECT iteration ID} +\item{iteration}{'IMPECT' iteration ID} \item{token}{bearer token} } @@ -18,9 +18,17 @@ a dataframe containing all matches for a given iteration ID Return a dataframe with basic information for all matches for a given iteration ID } \examples{ -\donttest{ -try({ # prevent cran errors - matches <- getMatches(518, token) -}) +# Toy example: this will error quickly (no API token) +try(matchplan <- getMatches( + iteration = 0, + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +matchplan <- getMatches( + iteration = 1004, + token = "yourToken" +) } } diff --git a/man/getPlayerIterationAverages.Rd b/man/getPlayerIterationAverages.Rd index 12a8f8b..c552f5b 100644 --- a/man/getPlayerIterationAverages.Rd +++ b/man/getPlayerIterationAverages.Rd @@ -7,7 +7,7 @@ getPlayerIterationAverages(iteration, token) } \arguments{ -\item{iteration}{Impect iteration ID} +\item{iteration}{'IMPECT' iteration ID} \item{token}{bearer token} } @@ -19,9 +19,17 @@ position for the given iteration ID Return a dataframe that contains all player averages for a given iteration ID } \examples{ -\donttest{ -try({ # prevent cran errors - playerIterationAverages <- getPlayerIterationAverages(518, token) -}) +# Toy example: this will error quickly (no API token) +try(player_avgs <- getPlayerIterationAverages( + iteration = 0, + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +player_avgs <- getPlayerIterationAverages( + iteration = 1004, + token = "yourToken" +) } } diff --git a/man/getPlayerIterationScores.Rd b/man/getPlayerIterationScores.Rd index f1758e2..179acb3 100644 --- a/man/getPlayerIterationScores.Rd +++ b/man/getPlayerIterationScores.Rd @@ -7,7 +7,7 @@ getPlayerIterationScores(iteration, positions, token) } \arguments{ -\item{iteration}{Impect iteration ID} +\item{iteration}{'IMPECT' iteration ID} \item{positions}{list of position names. Must be one of: "GOALKEEPER", "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", @@ -24,9 +24,19 @@ the given iteration ID and list of positions Return a dataframe that contains all player scores for a given iteration ID } \examples{ -\donttest{ -try({ # prevent cran errors - scores <- getPlayerIterationScores(518, token) -}) +# Toy example: this will error quickly (no API token) +try(player_scores <- getPlayerIterationScores( + iteration = 0, + positions = c("INVALID_POSITION_1", "INVALID_POSITION_2"), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +player_scores <- getPlayerIterationScores( + iteration = 1004, + positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"), + token = "yourToken" +) } } diff --git a/man/getPlayerMatchScores.Rd b/man/getPlayerMatchScores.Rd index a61e0a2..3073acc 100644 --- a/man/getPlayerMatchScores.Rd +++ b/man/getPlayerMatchScores.Rd @@ -8,7 +8,7 @@ and list of positions} getPlayerMatchScores(matches, positions, token) } \arguments{ -\item{matches}{Impect match IDs} +\item{matches}{'IMPECT' match IDs} \item{positions}{list of position names. Must be one of: "GOALKEEPER", "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", @@ -26,9 +26,19 @@ Return a dataframe that contains all player scores for a given match ID and list of positions } \examples{ -\donttest{ -try({ # prevent cran errors - playerMatchScores <- getPlayerMatchsums(84248, token) -}) +# Toy example: this will error quickly (no API token) +try(player_match_scores <- getPlayerMatchScores( + matches = c(0, 1), + positions = c("INVALID_POSITION_1", "INVALID_POSITION_2"), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +player_match_scores <- getPlayerMatchScores( + matches = c(84248, 158150), + positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"), + token = "yourToken" +) } } diff --git a/man/getPlayerMatchsums.Rd b/man/getPlayerMatchsums.Rd index ad3600c..f88886b 100644 --- a/man/getPlayerMatchsums.Rd +++ b/man/getPlayerMatchsums.Rd @@ -7,7 +7,7 @@ getPlayerMatchsums(matches, token) } \arguments{ -\item{matches}{Impect match IDs} +\item{matches}{'IMPECT' match IDs} \item{token}{bearer token} } @@ -18,9 +18,17 @@ a dataframe containing the matchsums aggregated per player and position for the Return a dataframe that contains all player matchsums for a given match ID } \examples{ -\donttest{ -try({ # prevent cran errors - matchsums <- getPlayerMatchsums(84248, token) -}) +# Toy example: this will error quickly (no API token) +try(player_match_sums <- getPlayerMatchsums( + matches = c(0, 1), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +player_match_sums <- getPlayerMatchsums( + matches = c(84248, 158150), + token = "yourToken" +) } } diff --git a/man/getPlayerProfileScores.Rd b/man/getPlayerProfileScores.Rd index 207f38e..c90eac8 100644 --- a/man/getPlayerProfileScores.Rd +++ b/man/getPlayerProfileScores.Rd @@ -8,7 +8,7 @@ iteration ID} getPlayerProfileScores(iteration, positions, token) } \arguments{ -\item{iteration}{Impect iteration ID} +\item{iteration}{'IMPECT' iteration ID} \item{positions}{list of position names. Must be one of: "GOALKEEPER", "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", @@ -26,9 +26,19 @@ Return a dataframe that contains all player profile scores for a given iteration ID } \examples{ -\donttest{ -try({ # prevent cran errors - scores <- getPlayerProfileScores(518, token) -}) +# Toy example: this will error quickly (no API token) +try(player_profile_scores <- getPlayerProfileScores( + iteration = 0, + positions = c("INVALID_POSITION_1", "INVALID_POSITION_2"), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +player_profile_scores <- getPlayerProfileScores( + iteration = 1004, + positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"), + token = "yourToken" +) } } diff --git a/man/getSetPieces.Rd b/man/getSetPieces.Rd index e0f7f3e..c479102 100644 --- a/man/getSetPieces.Rd +++ b/man/getSetPieces.Rd @@ -8,7 +8,7 @@ set piece sub phase for a set of given list of match IDs} getSetPieces(matches, token) } \arguments{ -\item{matches}{list fo IMPECT match IDs} +\item{matches}{list fo 'IMPECT' match IDs} \item{token}{bearer token} } @@ -21,9 +21,17 @@ Return a dataframe that contains all set pieces and aggregated kpi values per set piece sub phase for a set of given list of match IDs } \examples{ -\donttest{ -try({ # prevent cran errors - events <- getSetPieces(matches = c(84248), token = token) -}) +# Toy example: this will error quickly (no API token) +try(set_pieces <- getSetPieces( + matches = c(0, 1), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +set_pieces <- getSetPieces( + matches = c(84248, 158150), + token = "yourToken" +) } } diff --git a/man/getSquadIterationAverages.Rd b/man/getSquadIterationAverages.Rd index 45475b8..b435ea8 100644 --- a/man/getSquadIterationAverages.Rd +++ b/man/getSquadIterationAverages.Rd @@ -7,7 +7,7 @@ getSquadIterationAverages(iteration, token) } \arguments{ -\item{iteration}{Impect iteration ID} +\item{iteration}{'IMPECT' iteration ID} \item{token}{bearer token} } @@ -19,9 +19,17 @@ given iteration ID Return a dataframe that contains all squads averages for a given iteration ID } \examples{ -\donttest{ -try({ # prevent cran errors - squadIterationAverages <- getSquadIterationAverages(518, token) -}) +# Toy example: this will error quickly (no API token) +try(squad_avgs <- getSquadIterationAverages( + iteration = 0, + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +squad_avgs <- getSquadIterationAverages( + iteration = 1004, + token = "yourToken" +) } } diff --git a/man/getSquadIterationScores.Rd b/man/getSquadIterationScores.Rd index 3a25a6d..4cb590a 100644 --- a/man/getSquadIterationScores.Rd +++ b/man/getSquadIterationScores.Rd @@ -7,7 +7,7 @@ getSquadIterationScores(iteration, token) } \arguments{ -\item{iteration}{Impect iteration ID} +\item{iteration}{'IMPCET' iteration ID} \item{token}{bearer token} } @@ -19,9 +19,17 @@ given iteration ID Return a dataframe that contains all squads scores for a given iteration ID } \examples{ -\donttest{ -try({ # prevent cran errors - scores <- getSquadIterationScores(518, token) -}) +# Toy example: this will error quickly (no API token) +try(squad_scores <- getSquadIterationScores( + iteration = 0, + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +squad_scores <- getSquadIterationScores( + iteration = 1004, + token = "yourToken" +) } } diff --git a/man/getSquadMatchScores.Rd b/man/getSquadMatchScores.Rd index 6e8447d..d835842 100644 --- a/man/getSquadMatchScores.Rd +++ b/man/getSquadMatchScores.Rd @@ -7,7 +7,7 @@ getSquadMatchScores(matches, token) } \arguments{ -\item{matches}{Impect match IDs} +\item{matches}{'IMPECT' match IDs} \item{token}{bearer token} } @@ -18,9 +18,17 @@ a dataframe containing the scores and rations aggregated per squad for the given Return a dataframe that contains squad level scores and ratios for a given match ID } \examples{ -\donttest{ -try({ # prevent cran errors - squadMatchScores <- getSquadMatchsums(84248, token) -}) +# Toy example: this will error quickly (no API token) +try(squad_match_scores <- getSquadMatchScores( + matches = c(0, 1), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +squad_match_scores <- getSquadMatchScores( + matches = c(84248, 158150), + token = "yourToken" +) } } diff --git a/man/getSquadMatchsums.Rd b/man/getSquadMatchsums.Rd index c2f59c9..f532d0d 100644 --- a/man/getSquadMatchsums.Rd +++ b/man/getSquadMatchsums.Rd @@ -7,7 +7,7 @@ getSquadMatchsums(matches, token) } \arguments{ -\item{matches}{Impect match IDs} +\item{matches}{'IMPECT' match IDs} \item{token}{bearer token} } @@ -18,9 +18,17 @@ a dataframe containing the matchsums aggregated per squad for the given match ID Return a dataframe that contains squad level matchsums for a given match ID } \examples{ -\donttest{ -try({ # prevent cran errors - matchsums <- getSquadMatchsums(84248, token) -}) +# Toy example: this will error quickly (no API token) +try(squad_match_sums <- getSquadMatchsums( + matches = c(0, 1), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +squad_match_sums <- getSquadMatchsums( + matches = c(84248, 158150), + token = "yourToken" +) } } diff --git a/man/getSquadRatings.Rd b/man/getSquadRatings.Rd index b7007b3..f6bbaf3 100644 --- a/man/getSquadRatings.Rd +++ b/man/getSquadRatings.Rd @@ -7,7 +7,7 @@ getSquadRatings(iteration, token) } \arguments{ -\item{iteration}{Impect iteration ID} +\item{iteration}{'IMPECT' iteration ID} \item{token}{bearer token} } @@ -18,9 +18,17 @@ a dataframe containing the squad ratings for the given iteration ID Return a dataframe that contains squad ratings for a given iteration ID } \examples{ -\donttest{ -try({ # prevent cran errors - ratings <- getSquadRatings(1005, token) -}) +# Toy example: this will error quickly (no API token) +try(squad_ratings <- getSquadRatings( + iteration = 0, + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +squad_ratings <- getSquadRatings( + iteration = 1004, + token = "yourToken" +) } } diff --git a/man/getStartingPositions.Rd b/man/getStartingPositions.Rd index e425023..fca6adc 100644 --- a/man/getStartingPositions.Rd +++ b/man/getStartingPositions.Rd @@ -8,7 +8,7 @@ match IDs} getStartingPositions(matches, token) } \arguments{ -\item{matches}{IMPECT match ID or a list of match IDs} +\item{matches}{'IMPECT' match ID or a list of match IDs} \item{token}{bearer token} } @@ -21,9 +21,17 @@ Return a dataframe that contains all starting positions for a set of given match IDs } \examples{ -\donttest{ -try({ # prevent cran errors - startingPositions <- getStartingPositions(matches = c(84248), token = token) -}) +# Toy example: this will error quickly (no API token) +try(starting_pos <- getStartingPositions( + matches = c(0, 1), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +starting_pos <- getStartingPositions( + matches = c(84248, 158150), + token = "yourToken" +) } } diff --git a/man/getSubstitutions.Rd b/man/getSubstitutions.Rd index 28a1c9f..68748fa 100644 --- a/man/getSubstitutions.Rd +++ b/man/getSubstitutions.Rd @@ -8,7 +8,7 @@ match IDs} getSubstitutions(matches, token) } \arguments{ -\item{matches}{IMPECT match ID or a list of match IDs} +\item{matches}{'IMPECT' match ID or a list of match IDs} \item{token}{bearer token} } @@ -21,9 +21,17 @@ Return a dataframe that contains all line-up changes for a set of given match IDs } \examples{ -\donttest{ -try({ # prevent cran errors - substitutions <- getSubstitutions(matches = c(84248), token = token) -}) +# Toy example: this will error quickly (no API token) +try(subs <- getSubstitutions( + matches = c(0, 1), + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +subs <- getSubstitutions( + matches = c(84248, 158150), + token = "yourToken" +) } } From 64188800272789582d28520c5833b7e528801924 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 8 Oct 2025 09:52:15 +0200 Subject: [PATCH 03/12] Prepare package fro CRAN submission --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e1c3b94..b95f9ac 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: impectR -Title: Access Data from the Impect API +Title: Access Data from the 'Impect' API Version: 2.4.3 Authors@R: c( person("Impect", "GmbH", , "info.impect@impect.com", role = c("cph")), From 689a1e05abcd525f067e97f36246ed32422181aa Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 8 Oct 2025 12:22:31 +0200 Subject: [PATCH 04/12] introduce host parameter to query different envs --- R/getAccessToken.R | 10 +++---- R/getEvents.R | 51 ++++++++++++++++++++++------------ R/getFormations.R | 18 ++++++++---- R/getIterations.R | 6 ++-- R/getMatches.R | 12 +++++--- R/getPlayerIterationAverages.R | 21 ++++++++++---- R/getPlayerIterationScores.R | 22 +++++++++++---- R/getPlayerMatchScores.R | 31 +++++++++++++++------ R/getPlayerMatchsums.R | 26 +++++++++++------ R/getPlayerProfileScores.R | 22 +++++++++++---- R/getSetPieces.R | 20 ++++++++----- R/getSquadIterationAverages.R | 18 ++++++++---- R/getSquadIterationScores.R | 18 ++++++++---- R/getSquadMatchScores.R | 27 +++++++++++++----- R/getSquadMatchsums.R | 27 +++++++++++++----- R/getSquadRatings.R | 15 +++++++--- R/getStartingPositions.R | 21 ++++++++++---- R/getSubstitutions.R | 21 ++++++++++---- R/utils.R | 14 ++++++---- 19 files changed, 279 insertions(+), 121 deletions(-) diff --git a/R/getAccessToken.R b/R/getAccessToken.R index 44a953c..a34a731 100644 --- a/R/getAccessToken.R +++ b/R/getAccessToken.R @@ -14,16 +14,16 @@ #' \dontrun{ #' token <- getAccessToken(username = "yourUsername", password = "yourPassword") #' } -getAccessToken <- function(username, password) { +getAccessToken <- function( + username, + password, + token_url = "https://login.impect.com/auth/realms/production/protocol/openid-connect/token" + ) { # validate input parameters if (missing(username) || missing(password) || username == "" || password == "") { stop("Username and password are required.") } - # create tokenURL - token_url <- - "https://login.impect.com/auth/realms/production/protocol/openid-connect/token" - # compose login link login <- base::paste0( "client_id=api&grant_type=password&username=", diff --git a/R/getEvents.R b/R/getEvents.R index ec72291..ff2702a 100644 --- a/R/getEvents.R +++ b/R/getEvents.R @@ -5,6 +5,7 @@ #' @param token bearer token #' @param include_kpis include KPIs in event data #' @param include_set_pieces include additional set piece data in event data +#' @param host host environment #' #' @export #' @@ -35,8 +36,9 @@ getEvents <- function ( matches, token, include_kpis = TRUE, - include_set_pieces = FALSE - ) { + include_set_pieces = FALSE, + host = "https://api.impect.com" +) { # check if match input is not a list and convert to list if required if (!base::is.list(matches)) { @@ -55,9 +57,12 @@ getEvents <- function ( httr::content( .callAPIlimited( base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), + ), "text", encoding = "UTF-8" ) @@ -98,18 +103,19 @@ getEvents <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., suffix = "/events", token = token ), "text", encoding = "UTF-8" - ) - )$data %>% + ) + )$data %>% dplyr::mutate(matchId = ..1) %>% jsonlite::flatten() - ) + ) # fix column names using regex base::names(events) <- @@ -123,7 +129,8 @@ getEvents <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., suffix = "/event-kpis", token = token @@ -138,13 +145,14 @@ getEvents <- function ( kpis <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/kpis/event", + host, + base_url = "/v5/customerapi/kpis/event", token = token - ), + ), "text", encoding = "UTF-8" - ) - )$data %>% + ) + )$data %>% jsonlite::flatten() %>% dplyr::select(.data$id, .data$name) } @@ -157,7 +165,8 @@ getEvents <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., suffix = "/set-pieces", token = token @@ -167,7 +176,7 @@ getEvents <- function ( ) )$data %>% dplyr::mutate(matchId = ..1) %>% - jsonlite::flatten() + jsonlite::flatten() ) %>% tidyr::unnest_longer(.data$setPieceSubPhase) %>% tidyr::unnest(.data$setPieceSubPhase, names_sep = ".") %>% @@ -201,7 +210,8 @@ getEvents <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/players", token = token @@ -221,7 +231,8 @@ getEvents <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -241,10 +252,14 @@ getEvents <- function ( # get matchplan data matchplan <- - purrr::map_df(iterations, ~ getMatches(iteration = ., token = token)) + purrr::map_df(iterations, ~ getMatches( + iteration = ., + token = token, + host = host) + ) # get iterations - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # account for matches without dribbles, duels, or opponents tagged attributes <- c( @@ -316,7 +331,7 @@ getEvents <- function ( dplyr::left_join( dplyr::select( players, .data$id, setPieceSubPhaseMainEventPlayerName = .data$commonname - ), + ), by = base::c("setPieceSubPhaseMainEventPlayerId" = "id") ) %>% dplyr::left_join( diff --git a/R/getFormations.R b/R/getFormations.R index fce188c..dba1677 100644 --- a/R/getFormations.R +++ b/R/getFormations.R @@ -3,6 +3,7 @@ #' #' @param matches 'IMPECT' match ID or a list of match IDs #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -27,7 +28,8 @@ #' } getFormations <- function ( matches, - token + token, + host = "https://api.impect.com" ) { # check if match input is not a list and convert to list if required @@ -46,7 +48,8 @@ getFormations <- function ( response <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), @@ -113,7 +116,8 @@ getFormations <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -133,10 +137,14 @@ getFormations <- function ( # get matchplan data matchplan <- - purrr::map_df(iterations, ~ getMatches(iteration = ., token = token)) + purrr::map_df(iterations, ~ getMatches( + iteration = ., + token = token, + host = host) + ) # get iterations - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # extract formations formations_home <- match_info %>% diff --git a/R/getIterations.R b/R/getIterations.R index 5ccd3fc..b433726 100644 --- a/R/getIterations.R +++ b/R/getIterations.R @@ -1,6 +1,7 @@ #' Return a dataframe containing all iterations available to the user #' #' @param token bearer token +#' @param host host environment #' #' @export @@ -19,12 +20,13 @@ #' token = "yourToken" #' ) #' } -getIterations <- function(token) { +getIterations <- function(token, host = "https://api.impect.com") { # get iteration data from API iterations <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations", + host, + base_url = "/v5/customerapi/iterations", token = token ), "text", diff --git a/R/getMatches.R b/R/getMatches.R index e7cda8c..1be5f30 100644 --- a/R/getMatches.R +++ b/R/getMatches.R @@ -2,6 +2,7 @@ #' #' @param iteration 'IMPECT' iteration ID #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -23,13 +24,14 @@ #' token = "yourToken" #' ) #' } -getMatches <- function(iteration, token) { +getMatches <- function(iteration, token, host = "https://api.impect.com") { # get matches from API matches <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/matches", token = token @@ -47,7 +49,8 @@ getMatches <- function(iteration, token) { squads <-jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squads", token = token @@ -90,7 +93,8 @@ getMatches <- function(iteration, token) { countries <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/countries/", + host, + base_url = "/v5/customerapi/countries/", token = token ), "text", diff --git a/R/getPlayerIterationAverages.R b/R/getPlayerIterationAverages.R index d7d8c78..bdb2241 100644 --- a/R/getPlayerIterationAverages.R +++ b/R/getPlayerIterationAverages.R @@ -2,6 +2,7 @@ #' #' @param iteration 'IMPECT' iteration ID #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -24,7 +25,11 @@ #' token = "yourToken" #' ) #' } -getPlayerIterationAverages <- function (iteration, token) { +getPlayerIterationAverages <- function ( + iteration, + token, + host = "https://api.impect.com" +) { # check if iteration input is a string or integer if (!(base::is.numeric(iteration) || @@ -36,7 +41,8 @@ getPlayerIterationAverages <- function (iteration, token) { squads <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squads", token = token @@ -60,8 +66,9 @@ getPlayerIterationAverages <- function (iteration, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( + host, base_url = paste0( - "https://api.impect.com/v5/customerapi/iterations/", + "/v5/customerapi/iterations/", iteration, "/squads/", ., @@ -80,7 +87,8 @@ getPlayerIterationAverages <- function (iteration, token) { players <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/players", token = token @@ -98,7 +106,8 @@ getPlayerIterationAverages <- function (iteration, token) { kpis <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/kpis", + host, + base_url = "/v5/customerapi/kpis", token = token ), "text", @@ -109,7 +118,7 @@ getPlayerIterationAverages <- function (iteration, token) { dplyr::select(.data$id, .data$name) # get iterations from API - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate averages diff --git a/R/getPlayerIterationScores.R b/R/getPlayerIterationScores.R index 3ff8d37..1b62a91 100644 --- a/R/getPlayerIterationScores.R +++ b/R/getPlayerIterationScores.R @@ -21,6 +21,7 @@ allowed_positions <- c( #' "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", #' "RIGHT_WINGER", "CENTER_FORWARD" #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -45,7 +46,12 @@ allowed_positions <- c( #' token = "yourToken" #' ) #' } -getPlayerIterationScores <- function (iteration, positions, token) { +getPlayerIterationScores <- function ( + iteration, + positions, + token, + host = "https://api.impect.com" +) { # check if iteration input is a string or integer if (!(base::is.numeric(iteration) || @@ -67,7 +73,8 @@ getPlayerIterationScores <- function (iteration, positions, token) { squads <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squads", token = token @@ -92,8 +99,9 @@ getPlayerIterationScores <- function (iteration, positions, token) { response <- jsonlite::fromJSON( httr::content( .callAPIlimited( + host, base_url = paste0( - "https://api.impect.com/v5/customerapi/iterations/", + "/v5/customerapi/iterations/", iteration, "/squads/", ., @@ -145,7 +153,8 @@ getPlayerIterationScores <- function (iteration, positions, token) { players <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/players", token = token @@ -163,7 +172,8 @@ getPlayerIterationScores <- function (iteration, positions, token) { score_list <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/player-scores", + host, + base_url = "/v5/customerapi/player-scores", token = token ), "text", @@ -174,7 +184,7 @@ getPlayerIterationScores <- function (iteration, positions, token) { dplyr::select(.data$id, .data$name) # get competitions - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate averages diff --git a/R/getPlayerMatchScores.R b/R/getPlayerMatchScores.R index 4f85f76..ae45008 100644 --- a/R/getPlayerMatchScores.R +++ b/R/getPlayerMatchScores.R @@ -22,6 +22,7 @@ allowed_positions <- c( #' "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", #' "RIGHT_WINGER", "CENTER_FORWARD" #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -46,7 +47,12 @@ allowed_positions <- c( #' token = "yourToken" #' ) #' } -getPlayerMatchScores <- function (matches, positions, token) { +getPlayerMatchScores <- function ( + matches, + positions, + token, + host = "https://api.impect.com" +) { # check if match input is a list and convert to list if required if (!base::is.list(matches)) { @@ -71,7 +77,8 @@ getPlayerMatchScores <- function (matches, positions, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), @@ -118,8 +125,9 @@ getPlayerMatchScores <- function (matches, positions, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( + host, base_url = base::paste0( - "https://api.impect.com/v5/customerapi/matches/", + "/v5/customerapi/matches/", ., "/positions/", position_string, @@ -145,7 +153,8 @@ getPlayerMatchScores <- function (matches, positions, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/players", token = token @@ -172,7 +181,8 @@ getPlayerMatchScores <- function (matches, positions, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -190,7 +200,8 @@ getPlayerMatchScores <- function (matches, positions, token) { score_list <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/player-scores", + host, + base_url = "/v5/customerapi/player-scores", token = token ), "text", @@ -202,10 +213,14 @@ getPlayerMatchScores <- function (matches, positions, token) { # get matchplan data matchplan <- - purrr::map_df(iterations, ~ getMatches(iteration = ., token = token)) + purrr::map_df(iterations, ~ getMatches( + iteration = ., + token = token, + host = host + )) # get competitions - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate scores diff --git a/R/getPlayerMatchsums.R b/R/getPlayerMatchsums.R index 19bc41b..0cafafb 100644 --- a/R/getPlayerMatchsums.R +++ b/R/getPlayerMatchsums.R @@ -2,6 +2,7 @@ #' #' @param matches 'IMPECT' match IDs #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -23,7 +24,11 @@ #' token = "yourToken" #' ) #' } -getPlayerMatchsums <- function (matches, token) { +getPlayerMatchsums <- function ( + matches, + token, + host = "https://api.impect.com" +) { # check if match input is a list and convert to list if required if (!base::is.list(matches)) { @@ -41,7 +46,8 @@ getPlayerMatchsums <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), @@ -86,7 +92,8 @@ getPlayerMatchsums <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., suffix = "/player-kpis", token = token @@ -109,7 +116,8 @@ getPlayerMatchsums <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/players", token = token @@ -137,7 +145,8 @@ getPlayerMatchsums <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -156,7 +165,8 @@ getPlayerMatchsums <- function (matches, token) { kpis <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/kpis", + host, + base_url = "/v5/customerapi/kpis", token = token ), "text", @@ -169,10 +179,10 @@ getPlayerMatchsums <- function (matches, token) { # get matchplan data matchplan <- - purrr::map_df(iterations, ~ getMatches(iteration = ., token = token)) + purrr::map_df(iterations, ~ getMatches(iteration = ., token = token, host = host)) # get competitions - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate matchsums diff --git a/R/getPlayerProfileScores.R b/R/getPlayerProfileScores.R index 2133bc5..8eaa1f8 100644 --- a/R/getPlayerProfileScores.R +++ b/R/getPlayerProfileScores.R @@ -22,6 +22,7 @@ allowed_positions <- c( #' "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", #' "RIGHT_WINGER", "CENTER_FORWARD" #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -46,7 +47,12 @@ allowed_positions <- c( #' token = "yourToken" #' ) #' } -getPlayerProfileScores <- function (iteration, positions, token) { +getPlayerProfileScores <- function ( + iteration, + positions, + token, + host = "https://api.impect.com" +) { # check if iteration input is a string or integer if (!(base::is.numeric(iteration) || @@ -68,7 +74,8 @@ getPlayerProfileScores <- function (iteration, positions, token) { squads <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squads", token = token @@ -93,8 +100,9 @@ getPlayerProfileScores <- function (iteration, positions, token) { response <- jsonlite::fromJSON( httr::content( .callAPIlimited( + host, base_url = paste0( - "https://api.impect.com/v5/customerapi/iterations/", + "/v5/customerapi/iterations/", iteration, "/squads/", ., @@ -146,7 +154,8 @@ getPlayerProfileScores <- function (iteration, positions, token) { players <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/players", token = token @@ -164,7 +173,8 @@ getPlayerProfileScores <- function (iteration, positions, token) { profile_list <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/player-profiles", + host, + base_url = "/v5/customerapi/player-profiles", token = token ), "text", @@ -175,7 +185,7 @@ getPlayerProfileScores <- function (iteration, positions, token) { dplyr::select(.data$name) # get competitions - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate averages diff --git a/R/getSetPieces.R b/R/getSetPieces.R index 30cc930..94801f5 100644 --- a/R/getSetPieces.R +++ b/R/getSetPieces.R @@ -3,6 +3,7 @@ #' #' @param matches list fo 'IMPECT' match IDs #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -27,7 +28,8 @@ #' } getSetPieces <- function ( matches, - token + token, + host = "https://api.impect.com" ) { # check if match input is not a list and convert to list if required @@ -46,7 +48,8 @@ getSetPieces <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), @@ -91,7 +94,8 @@ getSetPieces <- function ( jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., suffix = "/set-pieces", token = token @@ -124,7 +128,8 @@ getSetPieces <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/players", token = token @@ -144,7 +149,8 @@ getSetPieces <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -161,10 +167,10 @@ getSetPieces <- function ( # get matchplan data matchplan <- purrr::map_df(iterations, - ~ getMatches(iteration = ., token = token)) + ~ getMatches(iteration = ., token = token, host = host)) # get iterations - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # start merging dfs diff --git a/R/getSquadIterationAverages.R b/R/getSquadIterationAverages.R index f529cfc..fb370ec 100644 --- a/R/getSquadIterationAverages.R +++ b/R/getSquadIterationAverages.R @@ -2,6 +2,7 @@ #' #' @param iteration 'IMPECT' iteration ID #' @param token bearer token +#' @param host host environment #' @export @@ -24,7 +25,11 @@ #' token = "yourToken" #' ) #' } -getSquadIterationAverages <- function (iteration, token) { +getSquadIterationAverages <- function ( + iteration, + token, + host = "https://api.impect.com" +) { # check if iteration input is a string or integer if (!(base::is.numeric(iteration) || @@ -36,7 +41,8 @@ getSquadIterationAverages <- function (iteration, token) { squads <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squads", token = token @@ -58,7 +64,8 @@ getSquadIterationAverages <- function (iteration, token) { averages_raw <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squad-kpis", token = token @@ -73,7 +80,8 @@ getSquadIterationAverages <- function (iteration, token) { kpis <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/kpis", + host, + base_url = "/v5/customerapi/kpis", token = token ), "text", @@ -84,7 +92,7 @@ getSquadIterationAverages <- function (iteration, token) { dplyr::select(.data$id, .data$name) # get competitions from API - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate averages diff --git a/R/getSquadIterationScores.R b/R/getSquadIterationScores.R index e606aff..ea0ea9f 100644 --- a/R/getSquadIterationScores.R +++ b/R/getSquadIterationScores.R @@ -2,6 +2,7 @@ #' #' @param iteration 'IMPCET' iteration ID #' @param token bearer token +#' @param host host environment #' @export @@ -24,7 +25,11 @@ #' token = "yourToken" #' ) #' } -getSquadIterationScores <- function (iteration, token) { +getSquadIterationScores <- function ( + iteration, + token, + host = "https://api.impect.com" +) { # check if iteration input is a string or integer if (!(base::is.numeric(iteration) || @@ -36,7 +41,8 @@ getSquadIterationScores <- function (iteration, token) { squads <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squads", token = token @@ -60,7 +66,8 @@ getSquadIterationScores <- function (iteration, token) { scores_raw <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squad-scores", token = token @@ -75,7 +82,8 @@ getSquadIterationScores <- function (iteration, token) { score_list <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/squad-scores", + host, + base_url = "/v5/customerapi/squad-scores", token = token ), "text", @@ -86,7 +94,7 @@ getSquadIterationScores <- function (iteration, token) { dplyr::select(.data$id, .data$name) # get competitions - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate averages diff --git a/R/getSquadMatchScores.R b/R/getSquadMatchScores.R index dd092be..a90e5c3 100644 --- a/R/getSquadMatchScores.R +++ b/R/getSquadMatchScores.R @@ -2,6 +2,7 @@ #' #' @param matches 'IMPECT' match IDs #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -23,7 +24,11 @@ #' token = "yourToken" #' ) #' } -getSquadMatchScores <- function (matches, token) { +getSquadMatchScores <- function ( + matches, + token, + host = "https://api.impect.com" +) { # check if match input is a list and convert to list if required if (!base::is.list(matches)) { @@ -41,7 +46,8 @@ getSquadMatchScores <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), @@ -85,7 +91,8 @@ getSquadMatchScores <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., suffix = "/squad-scores", token = token @@ -108,7 +115,8 @@ getSquadMatchScores <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -129,7 +137,8 @@ getSquadMatchScores <- function (matches, token) { scores_list <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/squad-scores", + host, + base_url = "/v5/customerapi/squad-scores", token = token ), "text", @@ -141,10 +150,14 @@ getSquadMatchScores <- function (matches, token) { # get matchplan data matchplan <- - purrr::map_df(iterations, ~ getMatches(iteration = ., token = token)) + purrr::map_df(iterations, ~ getMatches( + iteration = ., + token = token, + host = host + )) # get competitions - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate matchsums diff --git a/R/getSquadMatchsums.R b/R/getSquadMatchsums.R index ebfff35..eebfb8c 100644 --- a/R/getSquadMatchsums.R +++ b/R/getSquadMatchsums.R @@ -2,6 +2,7 @@ #' #' @param matches 'IMPECT' match IDs #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -23,7 +24,11 @@ #' token = "yourToken" #' ) #' } -getSquadMatchsums <- function (matches, token) { +getSquadMatchsums <- function ( + matches, + token, + host = "https://api.impect.com" +) { # check if match input is a list and convert to list if required if (!base::is.list(matches)) { @@ -41,7 +46,8 @@ getSquadMatchsums <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), @@ -85,7 +91,8 @@ getSquadMatchsums <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., suffix = "/squad-kpis", token = token @@ -108,7 +115,8 @@ getSquadMatchsums <- function (matches, token) { ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -129,7 +137,8 @@ getSquadMatchsums <- function (matches, token) { kpis <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/kpis", + host, + base_url = "/v5/customerapi/kpis", token = token ), "text", @@ -141,10 +150,14 @@ getSquadMatchsums <- function (matches, token) { # get matchplan data matchplan <- - purrr::map_df(iterations, ~ getMatches(iteration = ., token = token)) + purrr::map_df(iterations, ~ getMatches( + iteration = ., + token = token, + host = host + )) # get competitions - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # manipulate matchsums diff --git a/R/getSquadRatings.R b/R/getSquadRatings.R index 2fa4fda..51a33a3 100644 --- a/R/getSquadRatings.R +++ b/R/getSquadRatings.R @@ -2,6 +2,7 @@ #' #' @param iteration 'IMPECT' iteration ID #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -23,7 +24,11 @@ #' token = "yourToken" #' ) #' } -getSquadRatings <- function (iteration, token) { +getSquadRatings <- function ( + iteration, + token, + host = "https://api.impect.com" +) { # check if iteration input is a int if (!base::is.numeric(iteration)) { @@ -33,7 +38,8 @@ getSquadRatings <- function (iteration, token) { squads <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squads", token = token @@ -54,7 +60,8 @@ getSquadRatings <- function (iteration, token) { jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = iteration, suffix = "/squads/ratings", token = token @@ -71,7 +78,7 @@ getSquadRatings <- function (iteration, token) { gsub("\\.(.)", "\\U\\1", base::names(ratings), perl = TRUE) # get competitions - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # merge with other data ratings <- ratings %>% diff --git a/R/getStartingPositions.R b/R/getStartingPositions.R index aa4606c..7363a02 100644 --- a/R/getStartingPositions.R +++ b/R/getStartingPositions.R @@ -3,6 +3,7 @@ #' #' @param matches 'IMPECT' match ID or a list of match IDs #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -27,7 +28,8 @@ #' } getStartingPositions <- function ( matches, - token + token, + host = "https://api.impect.com" ) { # check if match input is not a list and convert to list if required @@ -46,7 +48,8 @@ getStartingPositions <- function ( response <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), @@ -116,7 +119,8 @@ getStartingPositions <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/players", token = token @@ -138,7 +142,8 @@ getStartingPositions <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -158,10 +163,14 @@ getStartingPositions <- function ( # get matchplan data matchplan <- - purrr::map_df(iterations, ~ getMatches(iteration = ., token = token)) + purrr::map_df(iterations, ~ getMatches( + iteration = ., + token = token, + host = host + )) # get iterations - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # extract shirt numbers shirt_numbers_home <- match_info %>% diff --git a/R/getSubstitutions.R b/R/getSubstitutions.R index 7d75a48..e05e51f 100644 --- a/R/getSubstitutions.R +++ b/R/getSubstitutions.R @@ -3,6 +3,7 @@ #' #' @param matches 'IMPECT' match ID or a list of match IDs #' @param token bearer token +#' @param host host environment #' #' @export #' @@ -27,7 +28,8 @@ #' } getSubstitutions <- function ( matches, - token + token, + host = "https://api.impect.com" ) { # check if match input is not a list and convert to list if required @@ -46,7 +48,8 @@ getSubstitutions <- function ( response <- jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", + host, + base_url = "/v5/customerapi/matches/", id = ., token = token ), @@ -116,7 +119,8 @@ getSubstitutions <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/players", token = token @@ -138,7 +142,8 @@ getSubstitutions <- function ( ~ jsonlite::fromJSON( httr::content( .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/iterations/", + host, + base_url = "/v5/customerapi/iterations/", id = ., suffix = "/squads", token = token @@ -158,10 +163,14 @@ getSubstitutions <- function ( # get matchplan data matchplan <- - purrr::map_df(iterations, ~ getMatches(iteration = ., token = token)) + purrr::map_df(iterations, ~ getMatches( + iteration = ., + token = token, + host = host + )) # get iterations - iterations <- getIterations(token = token) + iterations <- getIterations(token = token, host = host) # extract shirt numbers shirt_numbers_home <- match_info %>% diff --git a/R/utils.R b/R/utils.R index 2b0115c..bdb853c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -4,13 +4,14 @@ #' #' @noRd #' +#' @param host host environment #' @param base_url API endpoint URL #' @param id The id of the object to be retrieved #' @param suffix The suffix of the endpoint URL that comes after the id #' @param token Bearer token #' #' @return Response content of the API endpoint -.callAPI <- function(base_url, id = "", suffix = "", token, +.callAPI <- function(host, base_url, id = "", suffix = "", token, max_retries = 3, retry_delay = 1) { # try API call @@ -18,7 +19,7 @@ # get API response response <- httr::GET( - url = base::paste0(base_url, id, suffix), + url = base::paste0(host, base_url, id, suffix), httr::add_headers( Authorization = base::paste("Bearer", token, sep = " ")) ) @@ -59,19 +60,20 @@ #' #' @noRd #' +#' @param host host environment #' @param base_url Impect API endpoint URL #' @param id the id of the object to be retrieved #' @param suffix suffix of the endpoint URL that comes after the id #' @param token bearer token #' #' @return a dataframe containing the response of an API endpoint -.callAPIlimited <- function(base_url, id = "", suffix = "", token) { +.callAPIlimited <- function(host, base_url, id = "", suffix = "", token) { # check if Token bucket exist and create it if not if (is.null(.api_state$bucket)) { # get response from API - response <- .callAPI(base_url, id, suffix, token) + response <- .callAPI(host, base_url, id, suffix, token) # get rate limit policy policy <- response[["all_headers"]][[1]][["headers"]][["ratelimit-policy"]] @@ -100,7 +102,7 @@ # check if a token is available if (.api_state$bucket$isTokenAvailable()) { # get API response - response <- .callAPI(base_url, id, suffix, token) + response <- .callAPI(host, base_url, id, suffix, token) # consume a token .api_state$bucket$consumeToken() @@ -109,7 +111,7 @@ Sys.sleep(.api_state$bucket$intervall) # call function again - response <- .callAPIlimited(base_url, id, suffix, token) + response <- .callAPIlimited(host, base_url, id, suffix, token) } # return response From b64ab6589c7ef00239e7a572f8df49a766a2e267 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 8 Oct 2025 13:57:16 +0200 Subject: [PATCH 05/12] add coaches info to matchsums (players and squads), match scores (player and squads) and events --- R/getEvents.R | 99 +++++++++++++++++++++++++++++++------ R/getPlayerMatchScores.R | 103 +++++++++++++++++++++++++++++++++------ R/getPlayerMatchsums.R | 97 ++++++++++++++++++++++++++++++------ R/getSquadMatchScores.R | 98 +++++++++++++++++++++++++++++++------ R/getSquadMatchsums.R | 96 ++++++++++++++++++++++++++++++------ 5 files changed, 419 insertions(+), 74 deletions(-) diff --git a/R/getEvents.R b/R/getEvents.R index ff2702a..2b23e91 100644 --- a/R/getEvents.R +++ b/R/getEvents.R @@ -53,23 +53,34 @@ getEvents <- function ( matchInfo <- purrr::map_df( matches, - ~ jsonlite::fromJSON( - httr::content( - .callAPIlimited( - base_url = "https://api.impect.com/v5/customerapi/matches/", - host, - base_url = "/v5/customerapi/matches/", - id = ., - token = token + ~ { + temp <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/matches/", + id = ., + token = token ), - ), - "text", - encoding = "UTF-8" + "text", + encoding = "UTF-8" ) )$data - ) %>% - dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% - base::unique() + + response <- dplyr::tibble( + id = temp$id, + dateTime = temp$dateTime, + iterationId = temp$iterationId, + lastCalculationDate = temp$lastCalculationDate, + squadHomeId = temp$squadHome$id, + squadAwayId = temp$squadAway$id, + homeCoachId = temp$squadHome$coachId, + awayCoachId = temp$squadAway$coachId, + formationHome = temp$squadHome$startingFormation, + formationAway = temp$squadAway$startingFormation + ) + } + ) # filter for fail matches fail_matches <- matchInfo %>% @@ -250,6 +261,34 @@ getEvents <- function ( base::names(squads) <- gsub("\\.(.)", "\\U\\1", base::names(squads), perl = TRUE) + # get coach master data from API + coaches <- + purrr::map_df( + iterations, + ~ { + response <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/iterations/", + id = ., + suffix = "/coaches", + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + + if (base::length(response) > 0) { + response <- response %>% + jsonlite::flatten() + } + } + ) %>% + dplyr::select(.data$id, .data$name) %>% + base::unique() + # get matchplan data matchplan <- purrr::map_df(iterations, ~ getMatches( @@ -299,6 +338,34 @@ getEvents <- function ( by = base::c("currentAttackingSquadId" = "squadId") ) + # merge events with matchInfo & coaches + events <- events %>% + dplyr::left_join( + dplyr::select( + matchInfo, + matchId = .data$id, + .data$homeCoachId, + .data$awayCoachId + ), + by = base::c("matchId" = "matchId") + ) %>% + dplyr::left_join( + dplyr::select( + coaches, + homeCoachId = .data$id, + homeCoachName = .data$name + ), + by = base::c("homeCoachId" = "homeCoachId") + ) %>% + dplyr::left_join( + dplyr::select( + coaches, + awayCoachId = .data$id, + awayCoachName = .data$name + ), + by = base::c("awayCoachId" = "awayCoachId") + ) + # merge events with players events <- events %>% dplyr::left_join( @@ -421,11 +488,15 @@ getEvents <- function ( "homeSquadCountryId", "homeSquadCountryName", "homeSquadType", + "homeCoachId", + "homeCoachName", "awaySquadId", "awaySquadName", "awaySquadCountryId", "awaySquadCountryName", "awaySquadType", + "awayCoachId", + "awayCoachName", "eventId", "eventNumber", "sequenceIndex", diff --git a/R/getPlayerMatchScores.R b/R/getPlayerMatchScores.R index ae45008..81e0f8a 100644 --- a/R/getPlayerMatchScores.R +++ b/R/getPlayerMatchScores.R @@ -70,25 +70,38 @@ getPlayerMatchScores <- function ( ".\nChoose one or more of: ", paste(allowed_positions, collapse = ", ")) } - # get match info from API + # get matchInfo from API matchInfo <- purrr::map_df( matches, - ~ jsonlite::fromJSON( - httr::content( - .callAPIlimited( - host, - base_url = "/v5/customerapi/matches/", - id = ., - token = token - ), - "text", - encoding = "UTF-8" + ~ { + temp <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/matches/", + id = ., + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + + response <- dplyr::tibble( + id = temp$id, + dateTime = temp$dateTime, + iterationId = temp$iterationId, + lastCalculationDate = temp$lastCalculationDate, + squadHomeId = temp$squadHome$id, + squadAwayId = temp$squadAway$id, + homeCoachId = temp$squadHome$coachId, + awayCoachId = temp$squadAway$coachId, + formationHome = temp$squadHome$startingFormation, + formationAway = temp$squadAway$startingFormation ) - )$data - ) %>% - dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% - base::unique() + } + ) # filter for fail matches fail_matches <- matchInfo %>% @@ -196,6 +209,36 @@ getPlayerMatchScores <- function ( dplyr::select(.data$id, .data$name) %>% base::unique() + # get coach master data from API + + # get coach master data from API + coaches <- + purrr::map_df( + iterations, + ~ { + response <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/iterations/", + id = ., + suffix = "/coaches", + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + + if (base::length(response) > 0) { + response <- response %>% + jsonlite::flatten() + } + } + ) %>% + dplyr::select(.data$id, .data$name) %>% + base::unique() + # get kpi names from API score_list <- jsonlite::fromJSON( httr::content( @@ -342,7 +385,33 @@ getPlayerMatchScores <- function ( .data$skillCornerId, .data$playerName, .data$firstname, .data$lastname, .data$birthdate, .data$birthplace, .data$leg ), - by = c("playerId" = "id")) %>% + by = c("playerId" = "id") + ) %>% + dplyr::left_join( + bind_rows( + select( + matchInfo, + matchId = .data$id, + squadId = .data$squadHomeId, + coachId = .data$homeCoachId + ), + select( + matchInfo, + matchId = .data$id, + squadId = .data$squadAwayId, + coachId = .data$awayCoachId + ) + ), + by = base::c("matchId" = "matchId", "squadId" = "squadId") + ) %>% + dplyr::left_join( + dplyr::select( + coaches, + coachId = .data$id, + coachName = .data$name + ), + by = base::c("coachId" = "coachId") + ) %>% # fix some column names dplyr::rename( dateTime = .data$scheduledDate @@ -361,6 +430,8 @@ getPlayerMatchScores <- function ( "matchDayName", "squadId", "squadName", + "coachId", + "coachName", "playerId", "wyscoutId", "heimSpielId", diff --git a/R/getPlayerMatchsums.R b/R/getPlayerMatchsums.R index 0cafafb..24376e5 100644 --- a/R/getPlayerMatchsums.R +++ b/R/getPlayerMatchsums.R @@ -43,22 +43,34 @@ getPlayerMatchsums <- function ( matchInfo <- purrr::map_df( matches, - ~ jsonlite::fromJSON( - httr::content( - .callAPIlimited( - host, - base_url = "/v5/customerapi/matches/", - id = ., - token = token - ), - "text", - encoding = "UTF-8" - ) - )$data - ) %>% - dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% - base::unique() + ~ { + temp <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/matches/", + id = ., + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + response <- dplyr::tibble( + id = temp$id, + dateTime = temp$dateTime, + iterationId = temp$iterationId, + lastCalculationDate = temp$lastCalculationDate, + squadHomeId = temp$squadHome$id, + squadAwayId = temp$squadAway$id, + homeCoachId = temp$squadHome$coachId, + awayCoachId = temp$squadAway$coachId, + formationHome = temp$squadHome$startingFormation, + formationAway = temp$squadAway$startingFormation + ) + } + ) # filter for fail matches fail_matches <- matchInfo %>% @@ -160,6 +172,34 @@ getPlayerMatchsums <- function ( dplyr::select(.data$id, .data$name) %>% base::unique() + # get coach master data from API + coaches <- + purrr::map_df( + iterations, + ~ { + response <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/iterations/", + id = ., + suffix = "/coaches", + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + + if (base::length(response) > 0) { + response <- response %>% + jsonlite::flatten() + } + } + ) %>% + dplyr::select(.data$id, .data$name) %>% + base::unique() + # get kpi names from API kpis <- jsonlite::fromJSON( @@ -268,6 +308,31 @@ getPlayerMatchsums <- function ( .data$skillCornerId), by = c("playerId" = "id") ) %>% + dplyr::left_join( + bind_rows( + select( + matchInfo, + matchId = .data$id, + squadId = .data$squadHomeId, + coachId = .data$homeCoachId + ), + select( + matchInfo, + matchId = .data$id, + squadId = .data$squadAwayId, + coachId = .data$awayCoachId + ) + ), + by = base::c("matchId" = "matchId", "squadId" = "squadId") + ) %>% + dplyr::left_join( + dplyr::select( + coaches, + coachId = .data$id, + coachName = .data$name + ), + by = base::c("coachId" = "coachId") + ) %>% # fix some column names dplyr::rename( dateTime = .data$scheduledDate @@ -286,6 +351,8 @@ getPlayerMatchsums <- function ( "matchDayName", "squadId", "squadName", + "coachId", + "coachName", "playerId", "wyscoutId", "heimSpielId", diff --git a/R/getSquadMatchScores.R b/R/getSquadMatchScores.R index a90e5c3..7b5c55d 100644 --- a/R/getSquadMatchScores.R +++ b/R/getSquadMatchScores.R @@ -39,25 +39,38 @@ getSquadMatchScores <- function ( } } - # get match info from API + # get matchInfo from API matchInfo <- purrr::map_df( matches, - ~ jsonlite::fromJSON( - httr::content( - .callAPIlimited( - host, - base_url = "/v5/customerapi/matches/", - id = ., - token = token - ), - "text", - encoding = "UTF-8" + ~ { + temp <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/matches/", + id = ., + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + + response <- dplyr::tibble( + id = temp$id, + dateTime = temp$dateTime, + iterationId = temp$iterationId, + lastCalculationDate = temp$lastCalculationDate, + squadHomeId = temp$squadHome$id, + squadAwayId = temp$squadAway$id, + homeCoachId = temp$squadHome$coachId, + awayCoachId = temp$squadAway$coachId, + formationHome = temp$squadHome$startingFormation, + formationAway = temp$squadAway$startingFormation ) - )$data - ) %>% - dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% - base::unique() + } + ) # filter for fail matches fail_matches <- matchInfo %>% @@ -133,6 +146,34 @@ getSquadMatchScores <- function ( # clean data squads <- .cleanData(squads) + # get coach master data from API + coaches <- + purrr::map_df( + iterations, + ~ { + response <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/iterations/", + id = ., + suffix = "/coaches", + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + + if (base::length(response) > 0) { + response <- response %>% + jsonlite::flatten() + } + } + ) %>% + dplyr::select(.data$id, .data$name) %>% + base::unique() + # get score names from API scores_list <- jsonlite::fromJSON( httr::content( @@ -233,6 +274,31 @@ getSquadMatchScores <- function ( ), by = c("squadId" = "id") ) %>% + dplyr::left_join( + bind_rows( + select( + matchInfo, + matchId = .data$id, + squadId = .data$squadHomeId, + coachId = .data$homeCoachId + ), + select( + matchInfo, + matchId = .data$id, + squadId = .data$squadAwayId, + coachId = .data$awayCoachId + ) + ), + by = base::c("matchId" = "matchId", "squadId" = "squadId") + ) %>% + dplyr::left_join( + dplyr::select( + coaches, + coachId = .data$id, + coachName = .data$name + ), + by = base::c("coachId" = "coachId") + ) %>% # fix some column names dplyr::rename( dateTime = .data$scheduledDate @@ -254,6 +320,8 @@ getSquadMatchScores <- function ( "heimSpielId", "skillCornerId", "squadName", + "coachId", + "coachName", scores_list$name ) diff --git a/R/getSquadMatchsums.R b/R/getSquadMatchsums.R index eebfb8c..97790e6 100644 --- a/R/getSquadMatchsums.R +++ b/R/getSquadMatchsums.R @@ -43,21 +43,34 @@ getSquadMatchsums <- function ( matchInfo <- purrr::map_df( matches, - ~ jsonlite::fromJSON( - httr::content( - .callAPIlimited( - host, - base_url = "/v5/customerapi/matches/", - id = ., - token = token - ), - "text", - encoding = "UTF-8" + ~ { + temp <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/matches/", + id = ., + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + + response <- dplyr::tibble( + id = temp$id, + dateTime = temp$dateTime, + iterationId = temp$iterationId, + lastCalculationDate = temp$lastCalculationDate, + squadHomeId = temp$squadHome$id, + squadAwayId = temp$squadAway$id, + homeCoachId = temp$squadHome$coachId, + awayCoachId = temp$squadAway$coachId, + formationHome = temp$squadHome$startingFormation, + formationAway = temp$squadAway$startingFormation ) - )$data - ) %>% - dplyr::select(.data$id, .data$iterationId, .data$lastCalculationDate) %>% - base::unique() + } + ) # filter for fail matches fail_matches <- matchInfo %>% @@ -133,6 +146,34 @@ getSquadMatchsums <- function ( # clean data squads <- .cleanData(squads) + # get coach master data from API + coaches <- + purrr::map_df( + iterations, + ~ { + response <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/iterations/", + id = ., + suffix = "/coaches", + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + + if (base::length(response) > 0) { + response <- response %>% + jsonlite::flatten() + } + } + ) %>% + dplyr::select(.data$id, .data$name) %>% + base::unique() + # get kpi names from API kpis <- jsonlite::fromJSON( httr::content( @@ -233,6 +274,31 @@ getSquadMatchsums <- function ( ), by = c("squadId" = "squadId") ) %>% + dplyr::left_join( + bind_rows( + select( + matchInfo, + matchId = .data$id, + squadId = .data$squadHomeId, + coachId = .data$homeCoachId + ), + select( + matchInfo, + matchId = .data$id, + squadId = .data$squadAwayId, + coachId = .data$awayCoachId + ) + ), + by = base::c("matchId" = "matchId", "squadId" = "squadId") + ) %>% + dplyr::left_join( + dplyr::select( + coaches, + coachId = .data$id, + coachName = .data$name + ), + by = base::c("coachId" = "coachId") + ) %>% # fix some column names dplyr::rename( dateTime = .data$scheduledDate, @@ -254,6 +320,8 @@ getSquadMatchsums <- function ( "heimSpielId", "skillCornerId", "squadName", + "coachId", + "coachName", kpis$name ) From 1137d68712f2d5ff24bbe880c2cc368d1f34e651 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Thu, 9 Oct 2025 11:16:32 +0200 Subject: [PATCH 06/12] introduce logic to differentiate between calling specific positions vs all positions at once --- R/getPlayerIterationScores.R | 201 ++++++++++++++++++++++------------- R/getPlayerMatchScores.R | 164 +++++++++++++++++++--------- 2 files changed, 244 insertions(+), 121 deletions(-) diff --git a/R/getPlayerIterationScores.R b/R/getPlayerIterationScores.R index 1b62a91..08ba3f9 100644 --- a/R/getPlayerIterationScores.R +++ b/R/getPlayerIterationScores.R @@ -16,11 +16,12 @@ allowed_positions <- c( #' Return a dataframe that contains all player scores for a given iteration ID #' #' @param iteration 'IMPECT' iteration ID -#' @param positions list of position names. Must be one of: "GOALKEEPER", +#' @param token bearer token +#' @param positions optional list of position names. Must be one of: "GOALKEEPER", #' "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", #' "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", -#' "RIGHT_WINGER", "CENTER_FORWARD" -#' @param token bearer token +#' "RIGHT_WINGER", "CENTER_FORWARD". If not submitted, function will return all +#' positions individually. #' @param host host environment #' #' @export @@ -48,8 +49,8 @@ allowed_positions <- c( #' } getPlayerIterationScores <- function ( iteration, - positions, token, + positions = NULL, host = "https://api.impect.com" ) { @@ -59,15 +60,17 @@ getPlayerIterationScores <- function ( stop("Unprocessable type for 'iteration' variable") } - # check if the input positions are valid - invalid_positions <- positions[!positions %in% allowed_positions] - if (length(invalid_positions) > 0) { - stop("Invalid position(s): ", paste(invalid_positions, collapse = ", "), - ".\nChoose one or more of: ", paste(allowed_positions, collapse = ", ")) - } + if (!base::is.null(positions)) { + # check if the input positions are valid + invalid_positions <- positions[!positions %in% allowed_positions] + if (length(invalid_positions) > 0) { + stop("Invalid position(s): ", paste(invalid_positions, collapse = ", "), + ".\nChoose one or more of: ", paste(allowed_positions, collapse = ", ")) + } - # compile position string - position_string <- paste(positions, collapse = ",") + # compile position string + position_string <- paste(positions, collapse = ",") + } # get squads master data from API squads <- jsonlite::fromJSON( @@ -92,61 +95,92 @@ getPlayerIterationScores <- function ( base::unique() # get player iteration scores from API - scores_raw <- - purrr::map_df( - squadIds, - ~ { - response <- jsonlite::fromJSON( - httr::content( - .callAPIlimited( - host, - base_url = paste0( - "/v5/customerapi/iterations/", - iteration, - "/squads/", - ., - "/positions/", - position_string, - "/player-scores" + if (!base::is.null(positions)) { + scores_raw <- + purrr::map_df( + squadIds, + ~ { + response <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = paste0( + "/v5/customerapi/iterations/", + iteration, + "/squads/", + ., + "/positions/", + position_string, + "/player-scores" + ), + token = token ), - token = token - ), - "text", - encoding = "UTF-8" - ) - )$data + "text", + encoding = "UTF-8" + ) + )$data - if (base::length(response) > 0) { - response <- response %>% - dplyr::mutate(squadId = ..1, iterationId = iteration) + if (base::length(response) > 0) { + response <- response %>% + dplyr::mutate(squadId = ..1, iterationId = iteration) + } } - } - ) + ) - # raise exception if no player played at given positions in matches - if (base::length(scores_raw) == 0) { - base::stop( - base::paste0( - "No players played at position(s) ", - position_string, - " in iteration ", - iteration, - "." + # raise exception if no player played at given positions in matches + if (base::length(scores_raw) == 0) { + base::stop( + base::paste0( + "No players played at position(s) ", + position_string, + " in iteration ", + iteration, + "." + ) ) + } + + # print matches without players at given position + error_list <- base::as.character( + squadIds[!squadIds %in% scores_raw$squadId] ) - } + if (base::length(error_list) > 0) { + base::message( + base::sprintf( + "No players played at position(s) %s for following squads:\n\t%s", + positions, paste(error_list, collapse = ", ") + ) + ) + } + } else { + scores_raw <- + purrr::map_df( + squadIds, + ~ { + response <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = paste0( + "/v5/customerapi/iterations/", + iteration, + "/squads/", + ., + "/player-scores" + ), + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data - # print matches without players at given position - error_list <- base::as.character( - squadIds[!squadIds %in% scores_raw$squadId] - ) - if (base::length(error_list) > 0) { - base::message( - base::sprintf( - "No players played at position(s) %s for following squads:\n\t%s", - positions, paste(error_list, collapse = ", ") + if (base::length(response) > 0) { + response <- response %>% + dplyr::mutate(squadId = ..1, iterationId = iteration) + } + } ) - ) } # get player master data from API @@ -189,20 +223,39 @@ getPlayerIterationScores <- function ( # manipulate averages # unnest scorings - scores <- scores_raw %>% - tidyr::unnest("playerScores", keep_empty = TRUE) %>% - dplyr::select( - .data$iterationId, - .data$squadId, - .data$playerId, - .data$playDuration, - .data$matchShare, - .data$playerScoreId, - .data$value - ) %>% + if (!base::is.null(positions)) { + scores <- scores_raw %>% + tidyr::unnest("playerScores", keep_empty = TRUE) %>% + dplyr::select( + .data$iterationId, + .data$squadId, + .data$playerId, + .data$playDuration, + .data$matchShare, + .data$playerScoreId, + .data$value + ) + # add column to store positions string - dplyr::mutate(positions = position_string) %>% - # join with kpis to ensure all scores are present and order by playerScoreId + scores <- scores %>% + dplyr::mutate(positions = position_string) + } else { + scores <- scores_raw %>% + tidyr::unnest("playerScores", keep_empty = TRUE) %>% + dplyr::select( + .data$iterationId, + .data$squadId, + .data$playerId, + .data$position, + .data$playDuration, + .data$matchShare, + .data$playerScoreId, + .data$value + ) + } + + # join with kpis to ensure all scores are present and order by playerScoreId + scores <- scores %>% dplyr::full_join(score_list, by = c("playerScoreId" = "id")) %>% dplyr::arrange(.data$playerScoreId, .data$playerId) %>% # drop playerScoreId column @@ -266,6 +319,10 @@ getPlayerIterationScores <- function ( score_list$name ) + if (base::is.null(positions)) { + order[order == "positions"] <- "position" + } + # select columns scores <- scores %>% dplyr::select(dplyr::all_of(order)) diff --git a/R/getPlayerMatchScores.R b/R/getPlayerMatchScores.R index 81e0f8a..41c79ec 100644 --- a/R/getPlayerMatchScores.R +++ b/R/getPlayerMatchScores.R @@ -17,11 +17,12 @@ allowed_positions <- c( #' and list of positions #' #' @param matches 'IMPECT' match IDs -#' @param positions list of position names. Must be one of: "GOALKEEPER", +#' @param token bearer token +#' @param positions optional list of position names. Must be one of: "GOALKEEPER", #' "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", #' "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", -#' "RIGHT_WINGER", "CENTER_FORWARD" -#' @param token bearer token +#' "RIGHT_WINGER", "CENTER_FORWARD". If not submitted, function will return all +#' positions individually. #' @param host host environment #' #' @export @@ -49,8 +50,8 @@ allowed_positions <- c( #' } getPlayerMatchScores <- function ( matches, - positions, token, + positions = NULL, host = "https://api.impect.com" ) { @@ -63,11 +64,16 @@ getPlayerMatchScores <- function ( } } - # check if the input positions are valid - invalid_positions <- positions[!positions %in% allowed_positions] - if (length(invalid_positions) > 0) { - stop("Invalid position(s): ", paste(invalid_positions, collapse = ", "), - ".\nChoose one or more of: ", paste(allowed_positions, collapse = ", ")) + if (!base::is.null(positions)) { + # check if the input positions are valid + invalid_positions <- positions[!positions %in% allowed_positions] + if (length(invalid_positions) > 0) { + stop("Invalid position(s): ", paste(invalid_positions, collapse = ", "), + ".\nChoose one or more of: ", paste(allowed_positions, collapse = ", ")) + } + + # compile position string + position_string <- paste(positions, collapse = ",") } # get matchInfo from API @@ -88,6 +94,9 @@ getPlayerMatchScores <- function ( ) )$data + # define functino to convert NULL to NA + safe_extract <- function(x) if (is.null(x)) NA else x + response <- dplyr::tibble( id = temp$id, dateTime = temp$dateTime, @@ -95,8 +104,8 @@ getPlayerMatchScores <- function ( lastCalculationDate = temp$lastCalculationDate, squadHomeId = temp$squadHome$id, squadAwayId = temp$squadAway$id, - homeCoachId = temp$squadHome$coachId, - awayCoachId = temp$squadAway$coachId, + homeCoachId = safe_extract(temp$squadHome$coachId), + awayCoachId = safe_extract(temp$squadAway$coachId), formationHome = temp$squadHome$startingFormation, formationAway = temp$squadAway$startingFormation ) @@ -128,31 +137,50 @@ getPlayerMatchScores <- function ( } } - # compile position string - position_string <- paste(positions, collapse = ",") - # get player match scores from API - scores_raw <- - purrr::map( - matches, - ~ jsonlite::fromJSON( - httr::content( - .callAPIlimited( - host, - base_url = base::paste0( - "/v5/customerapi/matches/", - ., - "/positions/", - position_string, - "/player-scores" + if (!base::is.null(positions)) { + scores_raw <- + purrr::map( + matches, + ~ jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = base::paste0( + "/v5/customerapi/matches/", + ., + "/positions/", + position_string, + "/player-scores" + ), + token = token ), - token = token - ), - "text", - encoding = "UTF-8" - ) - )$data - ) + "text", + encoding = "UTF-8" + ) + )$data + ) + } else { + scores_raw <- + purrr::map( + matches, + ~ jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = base::paste0( + "/v5/customerapi/matches/", + ., + "/player-scores" + ), + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data + ) + } # get unique iterationIds iterations <- matchInfo %>% @@ -235,9 +263,18 @@ getPlayerMatchScores <- function ( jsonlite::flatten() } } - ) %>% - dplyr::select(.data$id, .data$name) %>% - base::unique() + ) + if (base::length(coaches) > 0) { + coaches <- coaches %>% + dplyr::select(.data$id, .data$name) %>% + base::unique() + } else { + coaches <- coaches %>% + dplyr::mutate( + id = NA, + name = NA + ) + } # get kpi names from API score_list <- jsonlite::fromJSON( @@ -277,17 +314,43 @@ getPlayerMatchScores <- function ( jsonlite::toJSON(dict[side][[1]]$players), simplifyDataFrame = TRUE ), - recursive = FALSE) + recursive = FALSE) %>% + dplyr::mutate( + matchId = dict$matchId, + squadId = dict[side][[1]]$id, + ) + + if (!base::is.null(positions)) { + # unnest scores + temp <- temp %>% + tidyr::unnest("playerScores", keep_empty = TRUE) %>% + dplyr::select( + "matchId", + "squadId", + "playerId" = "id", + "playerScoreId", + "value", + "matchShare", + "playDuration") %>% + # add positions + dplyr::mutate(positions = position_string) + } else { + # unnest scores + temp <- temp %>% + tidyr::unnest("playerScores", keep_empty = TRUE) %>% + dplyr::select( + "matchId", + "squadId", + "playerId" = "id", + "position", + "playerScoreId", + "value", + "matchShare", + "playDuration") + + } - # unnest scores temp <- temp %>% - tidyr::unnest("playerScores", keep_empty = TRUE) %>% - dplyr::select( - "playerId" = "id", - "playerScoreId", - "value", - "matchShare", - "playDuration") %>% # join with kpis to ensure all kpiIds are present and order by kpiId dplyr::full_join(score_list, by = c("playerScoreId" = "id")) %>% dplyr::arrange("playerScoreId", "playerId") %>% @@ -308,9 +371,8 @@ getPlayerMatchScores <- function ( # add matchId matchId = dict$matchId, # add squadId - squadId = dict[[side]]$id, - # add positions - positions = position_string) + squadId = dict[[side]]$id + ) return(temp) } @@ -448,6 +510,10 @@ getPlayerMatchScores <- function ( score_list$name ) + if (base::is.null(positions)) { + order[order == "positions"] <- "position" + } + # select columns scores <- scores %>% dplyr::select(dplyr::all_of(order)) From 13a1286893aa014bc2cc32b7805dd7bf2ed276ff Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Thu, 9 Oct 2025 11:49:06 +0200 Subject: [PATCH 07/12] add function to retrieve squad coefficients --- R/getSquadCoefficients.R | 142 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 R/getSquadCoefficients.R diff --git a/R/getSquadCoefficients.R b/R/getSquadCoefficients.R new file mode 100644 index 0000000..8441818 --- /dev/null +++ b/R/getSquadCoefficients.R @@ -0,0 +1,142 @@ +#' Return a dataframe that contains squad ratings for a given iteration ID +#' +#' @param iteration 'IMPECT' iteration ID +#' @param token bearer token +#' @param host host environment +#' +#' @export +#' +#' @importFrom dplyr %>% +#' @importFrom rlang .data +#' @return a dataframe containing the squad ratings for the given iteration ID +#' +#' @examples +#' # Toy example: this will error quickly (no API token) +#' try(squad_ratings <- getSquadRatings( +#' iteration = 0, +#' token = "invalid" +#' )) +#' +#' # Real usage: requires valid Bearer Token from `getAccessToken()` +#' \dontrun{ +#' squad_ratings <- getSquadRatings( +#' iteration = 1004, +#' token = "yourToken" +#' ) +#' } +getSquadCoefficients <- function ( + iteration, + token, + host = "https://api.impect.com" +) { + + # check if iteration input is a int + if (!base::is.numeric(iteration)) { + stop("Unprocessable type for 'iteration' variable") + } + # get squad amater data from API + squads <- jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/iterations/", + id = iteration, + suffix = "/squads", + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data %>% + jsonlite::flatten() %>% + dplyr::select(.data$id, .data$name, .data$idMappings) %>% + base::unique() + + # clean data + squads <- .cleanData(squads) + + # get squad ratings from API + coefficients <- jsonlite::flatten( + jsonlite::fromJSON( + httr::content( + .callAPIlimited( + host, + base_url = "/v5/customerapi/iterations/", + id = iteration, + suffix = "/predictions/model-coefficients", + token = token + ), + "text", + encoding = "UTF-8" + ) + )$data$entries %>% + dplyr::mutate(iterationId = iteration) + ) + + # fix column names using regex + base::names(coefficients) <- + gsub("\\.(.)", "\\U\\1", base::names(coefficients), perl = TRUE) + + # get competitions + iterations <- getIterations(token = token, host = host) + + # unnest squads column + coefficients <- coefficients %>% + tidyr::unnest(.data$squads) + + # merge with other data + coefficients <- coefficients %>% + dplyr::left_join( + dplyr::select( + squads, .data$id, .data$wyscoutId, .data$heimSpielId, + .data$skillCornerId, squadName = .data$name + ), + by = c("id" = "id") + ) %>% + dplyr::left_join( + dplyr::select( + iterations, .data$id, .data$competitionName, + .data$competitionType, .data$season, .data$competitionGender + ), + by = c("iterationId" = "id") + ) + + # rename columns + coefficients <- coefficients %>% + dplyr::rename( + squadId = .data$id, + attackCoefficient = .data$att, + defenseCoefficient = .data$def, + interceptCoefficient = .data$competitionIntercept, + homeCoefficient = .data$competitionHome, + competitionCoefficient = .data$competitionComp + ) + + # define column order + order <- c( + "iterationId", + "competitionId", + "competitionName", + "competitionType", + "season", + "competitionGender", + "interceptCoefficient", + "homeCoefficient", + "competitionCoefficient", + "date", + "squadId", + "wyscoutId", + "heimSpielId", + "skillCornerId", + "squadName", + "attackCoefficient", + "defenseCoefficient" + ) + + # select columns + coefficients <- coefficients %>% + dplyr::select(dplyr::all_of(order)) + + # return matchsums + return(coefficients) +} From f4fca18a01755a0234025313bf53cf217c9de065 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 15 Oct 2025 10:48:02 +0200 Subject: [PATCH 08/12] add example for match prediction --- examples/predict_matches.R | 104 +++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 examples/predict_matches.R diff --git a/examples/predict_matches.R b/examples/predict_matches.R new file mode 100644 index 0000000..d06e7a4 --- /dev/null +++ b/examples/predict_matches.R @@ -0,0 +1,104 @@ +library(tidyverse) +library(lubridate) +library(fuzzyjoin) +library(impectR) +devtools::load_all() + +# define login credentials +username <- "florian.schmitt@impect.com" +password <- "JT!jX9bVjn7gwGP" + +# set env +host <- "https://api.release.impect.com" +token_url <- "https://login.impect.com/auth/realms/release/protocol/openid-connect/token" + +# get access token +token <- getAccessToken(username, password, token_url = token_url) + +# define iteration Id +iteration <- 1385 + +# get matches for iteration +matches <- getMatches(iteration, token, host = host) + +# get squad model coefficients +coefficients <- getSquadCoefficients(iteration, token, host = host) + +# prepare columns for merging +matches$date <- as.POSIXct(matches$scheduledDate, tz = "UTC") # convert to UTC +matches$date <- as.Date(matches$date) # normalize to date only +matches$homeSquadId <- as.integer(matches$homeSquadId) +matches$awaySquadId <- as.integer(matches$awaySquadId) +coefficients$date <- as.Date(coefficients$date) # normalize to date only +coefficients$squadId <- as.integer(coefficients$squadId) + +# sort by date +matches <- matches[order(matches$date), ] +coefficients <- coefficients[order(coefficients$date), ] + +# merge to coefficients to get the most recent coefficient date for each match +matches <- fuzzyjoin::difference_inner_join( + matches, + coefficients %>% + select(date) %>% + distinct(date), + by = "date", + max_dist = Inf, + distance_col = "date_diff" +) %>% + rename("dateMatch" = "date.x", "dateCoef" = "date.y") %>% + # filter for only coefficient dates from the past of each match + filter(dateMatch >= dateCoef) %>% + group_by(dateMatch) %>% + # pick most recent coefficient before the match + slice_min(date_diff) %>% + ungroup() %>% + select(-date_diff) %>% + # join with competition-specific coefficients using most recent date + left_join( + coefficients %>% + select(date, interceptCoefficient, homeCoefficient, competitionCoefficient) %>% + distinct(), + by = c("dateCoef" = "date") + ) + +# merge squad-specific coefficients using the most recent date +matches <- matches %>% + # merge for home squad + left_join( + coefficients %>% + select(date, squadId, attackCoefficient, defenseCoefficient), + by = c("dateCoef" = "date", "homeSquadId" = "squadId") + ) %>% + rename( + "attackCoefficientHome" = "attackCoefficient", + "defenseCoefficientHome" = "defenseCoefficient" + ) %>% + # merge for away squad + left_join( + coefficients %>% + select(date, squadId, attackCoefficient, defenseCoefficient), + by = c("dateCoef" = "date", "awaySquadId" = "squadId") + ) %>% + rename( + "attackCoefficientAway" = "attackCoefficient", + "defenseCoefficientAway" = "defenseCoefficient" + ) + +# compute predictions +matches <- matches %>% + mutate( + predHome = exp( + interceptCoefficient + + homeCoefficient + + competitionCoefficient + + attackCoefficientHome + + defenseCoefficientAway + ), + predAway = exp( + interceptCoefficient + + competitionCoefficient + + attackCoefficientAway + + defenseCoefficientHome + ) + ) From 3f3889699ca7fc25930e36fb9199a7094f83c9a0 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 15 Oct 2025 14:09:06 +0200 Subject: [PATCH 09/12] add examples folder for CRAN submission --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index 36035fb..193d926 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ ^\.gitignore$ ^\.Rhistory$ ^dev$ +^examples$ From 1ce5ca2bd54e39140c75b286d18e6ab39d818521 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 15 Oct 2025 14:10:30 +0200 Subject: [PATCH 10/12] bump version --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 15 +++++++++++++ README.Rmd | 64 +++++++++++++++++++++++++++++++++++++++++++--------- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 127 insertions(+), 20 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b95f9ac..481f406 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: impectR Title: Access Data from the 'Impect' API -Version: 2.4.3 +Version: 2.5.0 Authors@R: c( person("Impect", "GmbH", , "info.impect@impect.com", role = c("cph")), person("Florian", "Schmitt", , "florian.schmitt@impect.com", role = c("aut", "cre")), diff --git a/NAMESPACE b/NAMESPACE index 9c0a87f..0cb991c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(getPlayerMatchScores) export(getPlayerMatchsums) export(getPlayerProfileScores) export(getSetPieces) +export(getSquadCoefficients) export(getSquadIterationAverages) export(getSquadIterationScores) export(getSquadMatchScores) diff --git a/NEWS.md b/NEWS.md index 25a8d76..25cac46 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,18 @@ +# impectR 2.5.0 + +## Major Changes +* Use new endpoints to drastically improve performance of `getPlayerMatchScores()` and `getPlayerIterationScores()`. The argument `positions` is no longer required. If it is not spplied the function defaults to the new endpoints and returns all unique player-position-squad combinations. +* Add coaches ot the following functions: + * `getEvents()` + * `getPlayerMatchSums()` + * `getSquadMatchSums()` + * `getPlayerMatchScores()` + * `getSquadMatchScores()` +* Add function `getSquadCoefficients()` to retrieve detailed model coefficients to enable match predictions + +## Minor Changes +* Minor fixes to enable CRAN submission + # impectR 2.4.3 ## Minor Changes diff --git a/README.Rmd b/README.Rmd index 395e61a..a09699e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -21,9 +21,9 @@ knitr::opts_chunk$set( A package provided by: Impect GmbH -Version: v2.4.3 +Version: v2.5.0 -**Updated: June 5th 2025** +**Updated: October 15th 2025** --- @@ -46,11 +46,17 @@ match and season level. ## Installation You can install the latest version of impectR from -[GitHub](https://github.com/) with: +CRAN with: -``` r +```r +install.packages("impectR") +``` + +You can also install it from [GitHub](https://github.com/) with: + +```r # install.packages("devtools") -devtools::install_github("ImpectAPI/impectR@v2.4.3") +devtools::install_github("ImpectAPI/impectR@v2.5.0") ``` ## Usage @@ -91,7 +97,7 @@ your sales representative. Now let’s assume you are interested in data for 2022/23 season of the 1. Bundesliga (iteration = 518). The following snippet gets you a list of matches for this iteration: -``` {r match plan, eval=FALSE} +```{r match plan, eval=FALSE} # get matches for iteration matches <- getMatches(iteration = 518, token = token) @@ -158,8 +164,11 @@ squadMatchsums <- getSquadMatchsums(matches = matchIds, token = token) positions <- c("LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER") # get player scores and ratios for match and positions per player -playerMatchScores <- - getPlayerMatchScores(matches = matchIds, positions = positions, token = token) +playerMatchScores <- getPlayerMatchScores( + matches = matchIds, + token = token, + positions = positions # optional +) # get squad scores and ratios for match per squad squadMatchScores <- getSquadMatchScores(matches = matchIds, token = token) @@ -234,15 +243,50 @@ squadIterationAverages <- # get player scores and ratios for iteration and positions playerIterationScores <- - getPlayerIterationScores(iteration = iteration, positions = positions, token = token) + getPlayerIterationScores( + iteration = iteration, + token = token, + positions = positions. #optional + ) # get squad scores and ratios for iteration squadIterationScores <- getSquadIterationScores(iteration = iteration, token = token) +``` + +The squad rating values that you can find on the league ranking in the Scouting portal can +also be retrieved from the API. In addition, we also provide you with the more detailed squad +coefficients that can be used to make match predictions. See [this example script](https://github.com/ImpectAPI/impectPy/blob/release/examples/predict_matches.ipynb) +for further details. -# get squad ratings for iteration +```{r squad ratings & coefficients, eval=FALSE} +# get squad rating for iteration squadRatings <- getSquadRatings(iteration = iteration, token = token) +# get squad coefficients for iteration +squadCoefficients <- getSquadCoefficients(iteration = iteration, token = token) +``` + +You can now also retrieve the positional profile scores for players via our API. This +includes profiles that you created through the scouting portal. The function requires a +positional input that determines which matchShares to consider when computing the scores. +In the below example, all matchShares that a player played as either a left back or a right +back are included for profile score calculation. + +```{r splayer profile scores, eval=FALSE} +# define iteration ID +iteration = 518 + +# define positions to get scores aggregated by +positions = ["LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER"] + +# get player profile scores +playerProfileScores <- + ip.getPlayerProfileScores( + iteration = iteration, + positions = positions, + token = token + ) ``` diff --git a/README.md b/README.md index a74e855..08cfc0c 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ A package provided by: Impect GmbH -Version: v2.4.3 +Version: v2.5.0 -**Updated: June 5th 2025** +**Updated: October 15th 2025** ------------------------------------------------------------------------ @@ -34,12 +34,17 @@ match and season level. ## Installation -You can install the latest version of impectR from -[GitHub](https://github.com/) with: +You can install the latest version of impectR from CRAN with: + +``` r +install.packages("impectR") +``` + +You can also install it from [GitHub](https://github.com/) with: ``` r # install.packages("devtools") -devtools::install_github("ImpectAPI/impectR@v2.4.3") +devtools::install_github("ImpectAPI/impectR@v2.5.0") ``` ## Usage @@ -147,8 +152,11 @@ squadMatchsums <- getSquadMatchsums(matches = matchIds, token = token) positions <- c("LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER") # get player scores and ratios for match and positions per player -playerMatchScores <- - getPlayerMatchScores(matches = matchIds, positions = positions, token = token) +playerMatchScores <- getPlayerMatchScores( + matches = matchIds, + token = token, + positions = positions # optional +) # get squad scores and ratios for match per squad squadMatchScores <- getSquadMatchScores(matches = matchIds, token = token) @@ -222,14 +230,53 @@ squadIterationAverages <- # get player scores and ratios for iteration and positions playerIterationScores <- - getPlayerIterationScores(iteration = iteration, positions = positions, token = token) + getPlayerIterationScores( + iteration = iteration, + token = token, + positions = positions. #optional + ) # get squad scores and ratios for iteration squadIterationScores <- getSquadIterationScores(iteration = iteration, token = token) +``` -# get squad ratings for iteration +The squad rating values that you can find on the league ranking in the +Scouting portal can also be retrieved from the API. In addition, we also +provide you with the more detailed squad coefficients that can be used +to make match predictions. See [this example +script](https://github.com/ImpectAPI/impectPy/blob/release/examples/predict_matches.ipynb) +for further details. + +``` r +# get squad rating for iteration squadRatings <- getSquadRatings(iteration = iteration, token = token) + +# get squad coefficients for iteration +squadCoefficients <- getSquadCoefficients(iteration = iteration, token = token) +``` + +You can now also retrieve the positional profile scores for players via +our API. This includes profiles that you created through the scouting +portal. The function requires a positional input that determines which +matchShares to consider when computing the scores. In the below example, +all matchShares that a player played as either a left back or a right +back are included for profile score calculation. + +``` r +# define iteration ID +iteration = 518 + +# define positions to get scores aggregated by +positions = ["LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER"] + +# get player profile scores +playerProfileScores <- + ip.getPlayerProfileScores( + iteration = iteration, + positions = positions, + token = token + ) ``` Please keep in mind that Impect enforces a rate limit of 10 requests per From 1b77f85c41c9dc9741eb0646f061d9f031f54453 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 15 Oct 2025 14:11:00 +0200 Subject: [PATCH 11/12] write manuals --- man/getAccessToken.Rd | 9 +++++++- man/getEvents.Rd | 10 ++++++++- man/getFormations.Rd | 4 +++- man/getIterations.Rd | 4 +++- man/getMatches.Rd | 4 +++- man/getPlayerIterationAverages.Rd | 4 +++- man/getPlayerIterationScores.Rd | 16 ++++++++++---- man/getPlayerMatchScores.Rd | 16 ++++++++++---- man/getPlayerMatchsums.Rd | 6 ++++-- man/getPlayerProfileScores.Rd | 9 +++++++- man/getSetPieces.Rd | 4 +++- man/getSquadCoefficients.Rd | 36 +++++++++++++++++++++++++++++++ man/getSquadIterationAverages.Rd | 4 +++- man/getSquadIterationScores.Rd | 4 +++- man/getSquadMatchScores.Rd | 4 +++- man/getSquadMatchsums.Rd | 6 ++++-- man/getSquadRatings.Rd | 4 +++- man/getStartingPositions.Rd | 4 +++- man/getSubstitutions.Rd | 4 +++- 19 files changed, 126 insertions(+), 26 deletions(-) create mode 100644 man/getSquadCoefficients.Rd diff --git a/man/getAccessToken.Rd b/man/getAccessToken.Rd index 6c58005..fcae9ef 100644 --- a/man/getAccessToken.Rd +++ b/man/getAccessToken.Rd @@ -4,12 +4,19 @@ \alias{getAccessToken} \title{Get an access token from the 'Impect' Customer API} \usage{ -getAccessToken(username, password) +getAccessToken( + username, + password, + token_url = + "https://login.impect.com/auth/realms/production/protocol/openid-connect/token" +) } \arguments{ \item{username}{your 'IMPECT' username} \item{password}{your 'IMPECT' password} + +\item{token_url}{host specific token url} } \value{ a string containing a bearer token diff --git a/man/getEvents.Rd b/man/getEvents.Rd index abc3617..ab7bb0e 100644 --- a/man/getEvents.Rd +++ b/man/getEvents.Rd @@ -5,7 +5,13 @@ \title{Return a dataframe that contains all events and kpi values for a set of given match IDs} \usage{ -getEvents(matches, token, include_kpis = TRUE, include_set_pieces = FALSE) +getEvents( + matches, + token, + include_kpis = TRUE, + include_set_pieces = FALSE, + host = "https://api.impect.com" +) } \arguments{ \item{matches}{'IMPECT' match ID or a list of match IDs} @@ -15,6 +21,8 @@ getEvents(matches, token, include_kpis = TRUE, include_set_pieces = FALSE) \item{include_kpis}{include KPIs in event data} \item{include_set_pieces}{include additional set piece data in event data} + +\item{host}{host environment} } \value{ a dataframe containing all events and kpi values for a set of given diff --git a/man/getFormations.Rd b/man/getFormations.Rd index a1c1689..1c3dd56 100644 --- a/man/getFormations.Rd +++ b/man/getFormations.Rd @@ -5,12 +5,14 @@ \title{Return a dataframe that contains all starting formations for a set of given match IDs} \usage{ -getFormations(matches, token) +getFormations(matches, token, host = "https://api.impect.com") } \arguments{ \item{matches}{'IMPECT' match ID or a list of match IDs} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing all starting formations for a set of given diff --git a/man/getIterations.Rd b/man/getIterations.Rd index a4ec1db..fc35583 100644 --- a/man/getIterations.Rd +++ b/man/getIterations.Rd @@ -4,10 +4,12 @@ \alias{getIterations} \title{Return a dataframe containing all iterations available to the user} \usage{ -getIterations(token) +getIterations(token, host = "https://api.impect.com") } \arguments{ \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing all iterations available to the user diff --git a/man/getMatches.Rd b/man/getMatches.Rd index a571b40..4c6e2a6 100644 --- a/man/getMatches.Rd +++ b/man/getMatches.Rd @@ -4,12 +4,14 @@ \alias{getMatches} \title{Return a dataframe with basic information for all matches for a given iteration ID} \usage{ -getMatches(iteration, token) +getMatches(iteration, token, host = "https://api.impect.com") } \arguments{ \item{iteration}{'IMPECT' iteration ID} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing all matches for a given iteration ID diff --git a/man/getPlayerIterationAverages.Rd b/man/getPlayerIterationAverages.Rd index c552f5b..a244a7b 100644 --- a/man/getPlayerIterationAverages.Rd +++ b/man/getPlayerIterationAverages.Rd @@ -4,12 +4,14 @@ \alias{getPlayerIterationAverages} \title{Return a dataframe that contains all player averages for a given iteration ID} \usage{ -getPlayerIterationAverages(iteration, token) +getPlayerIterationAverages(iteration, token, host = "https://api.impect.com") } \arguments{ \item{iteration}{'IMPECT' iteration ID} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing the KPI averages aggregated per player and diff --git a/man/getPlayerIterationScores.Rd b/man/getPlayerIterationScores.Rd index 179acb3..9aedb7d 100644 --- a/man/getPlayerIterationScores.Rd +++ b/man/getPlayerIterationScores.Rd @@ -4,17 +4,25 @@ \alias{getPlayerIterationScores} \title{Return a dataframe that contains all player scores for a given iteration ID} \usage{ -getPlayerIterationScores(iteration, positions, token) +getPlayerIterationScores( + iteration, + token, + positions = NULL, + host = "https://api.impect.com" +) } \arguments{ \item{iteration}{'IMPECT' iteration ID} -\item{positions}{list of position names. Must be one of: "GOALKEEPER", +\item{token}{bearer token} + +\item{positions}{optional list of position names. Must be one of: "GOALKEEPER", "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", -"RIGHT_WINGER", "CENTER_FORWARD"} +"RIGHT_WINGER", "CENTER_FORWARD". If not submitted, function will return all +positions individually.} -\item{token}{bearer token} +\item{host}{host environment} } \value{ a dataframe containing the player scores aggregated per player for diff --git a/man/getPlayerMatchScores.Rd b/man/getPlayerMatchScores.Rd index 3073acc..21f897b 100644 --- a/man/getPlayerMatchScores.Rd +++ b/man/getPlayerMatchScores.Rd @@ -5,17 +5,25 @@ \title{Return a dataframe that contains all player scores for a given match ID and list of positions} \usage{ -getPlayerMatchScores(matches, positions, token) +getPlayerMatchScores( + matches, + token, + positions = NULL, + host = "https://api.impect.com" +) } \arguments{ \item{matches}{'IMPECT' match IDs} -\item{positions}{list of position names. Must be one of: "GOALKEEPER", +\item{token}{bearer token} + +\item{positions}{optional list of position names. Must be one of: "GOALKEEPER", "LEFT_WINGBACK_DEFENDER", "RIGHT_WINGBACK_DEFENDER", "CENTRAL_DEFENDER", "DEFENSE_MIDFIELD", "CENTRAL_MIDFIELD", "ATTACKING_MIDFIELD", "LEFT_WINGER", -"RIGHT_WINGER", "CENTER_FORWARD"} +"RIGHT_WINGER", "CENTER_FORWARD". If not submitted, function will return all +positions individually.} -\item{token}{bearer token} +\item{host}{host environment} } \value{ a dataframe containing the scores aggregated per player and diff --git a/man/getPlayerMatchsums.Rd b/man/getPlayerMatchsums.Rd index f88886b..9c9b643 100644 --- a/man/getPlayerMatchsums.Rd +++ b/man/getPlayerMatchsums.Rd @@ -1,15 +1,17 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getPlayerMatchSums.R +% Please edit documentation in R/getPlayerMatchsums.R \name{getPlayerMatchsums} \alias{getPlayerMatchsums} \title{Return a dataframe that contains all player matchsums for a given match ID} \usage{ -getPlayerMatchsums(matches, token) +getPlayerMatchsums(matches, token, host = "https://api.impect.com") } \arguments{ \item{matches}{'IMPECT' match IDs} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing the matchsums aggregated per player and position for the given match ID diff --git a/man/getPlayerProfileScores.Rd b/man/getPlayerProfileScores.Rd index c90eac8..ccd12a5 100644 --- a/man/getPlayerProfileScores.Rd +++ b/man/getPlayerProfileScores.Rd @@ -5,7 +5,12 @@ \title{Return a dataframe that contains all player profile scores for a given iteration ID} \usage{ -getPlayerProfileScores(iteration, positions, token) +getPlayerProfileScores( + iteration, + positions, + token, + host = "https://api.impect.com" +) } \arguments{ \item{iteration}{'IMPECT' iteration ID} @@ -16,6 +21,8 @@ getPlayerProfileScores(iteration, positions, token) "RIGHT_WINGER", "CENTER_FORWARD"} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing the player profilescores aggregated per player diff --git a/man/getSetPieces.Rd b/man/getSetPieces.Rd index c479102..c2cf70e 100644 --- a/man/getSetPieces.Rd +++ b/man/getSetPieces.Rd @@ -5,12 +5,14 @@ \title{Return a dataframe that contains all set pieces and aggregated kpi values per set piece sub phase for a set of given list of match IDs} \usage{ -getSetPieces(matches, token) +getSetPieces(matches, token, host = "https://api.impect.com") } \arguments{ \item{matches}{list fo 'IMPECT' match IDs} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing all set pieces and aggregated kpi values per diff --git a/man/getSquadCoefficients.Rd b/man/getSquadCoefficients.Rd new file mode 100644 index 0000000..6c27ee4 --- /dev/null +++ b/man/getSquadCoefficients.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getSquadCoefficients.R +\name{getSquadCoefficients} +\alias{getSquadCoefficients} +\title{Return a dataframe that contains squad ratings for a given iteration ID} +\usage{ +getSquadCoefficients(iteration, token, host = "https://api.impect.com") +} +\arguments{ +\item{iteration}{'IMPECT' iteration ID} + +\item{token}{bearer token} + +\item{host}{host environment} +} +\value{ +a dataframe containing the squad ratings for the given iteration ID +} +\description{ +Return a dataframe that contains squad ratings for a given iteration ID +} +\examples{ +# Toy example: this will error quickly (no API token) +try(squad_ratings <- getSquadRatings( + iteration = 0, + token = "invalid" +)) + +# Real usage: requires valid Bearer Token from `getAccessToken()` +\dontrun{ +squad_ratings <- getSquadRatings( + iteration = 1004, + token = "yourToken" +) +} +} diff --git a/man/getSquadIterationAverages.Rd b/man/getSquadIterationAverages.Rd index b435ea8..9f66c42 100644 --- a/man/getSquadIterationAverages.Rd +++ b/man/getSquadIterationAverages.Rd @@ -4,12 +4,14 @@ \alias{getSquadIterationAverages} \title{Return a dataframe that contains all squads averages for a given iteration ID} \usage{ -getSquadIterationAverages(iteration, token) +getSquadIterationAverages(iteration, token, host = "https://api.impect.com") } \arguments{ \item{iteration}{'IMPECT' iteration ID} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing the KPI averages aggregated per squad for the diff --git a/man/getSquadIterationScores.Rd b/man/getSquadIterationScores.Rd index 4cb590a..f7c4ff2 100644 --- a/man/getSquadIterationScores.Rd +++ b/man/getSquadIterationScores.Rd @@ -4,12 +4,14 @@ \alias{getSquadIterationScores} \title{Return a dataframe that contains all squads scores for a given iteration ID} \usage{ -getSquadIterationScores(iteration, token) +getSquadIterationScores(iteration, token, host = "https://api.impect.com") } \arguments{ \item{iteration}{'IMPCET' iteration ID} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing the squad scores aggregated per squad for the diff --git a/man/getSquadMatchScores.Rd b/man/getSquadMatchScores.Rd index d835842..600f4c9 100644 --- a/man/getSquadMatchScores.Rd +++ b/man/getSquadMatchScores.Rd @@ -4,12 +4,14 @@ \alias{getSquadMatchScores} \title{Return a dataframe that contains squad level scores and ratios for a given match ID} \usage{ -getSquadMatchScores(matches, token) +getSquadMatchScores(matches, token, host = "https://api.impect.com") } \arguments{ \item{matches}{'IMPECT' match IDs} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing the scores and rations aggregated per squad for the given match ID diff --git a/man/getSquadMatchsums.Rd b/man/getSquadMatchsums.Rd index f532d0d..bdf4cce 100644 --- a/man/getSquadMatchsums.Rd +++ b/man/getSquadMatchsums.Rd @@ -1,15 +1,17 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getSquadMatchSums.R +% Please edit documentation in R/getSquadMatchsums.R \name{getSquadMatchsums} \alias{getSquadMatchsums} \title{Return a dataframe that contains squad level matchsums for a given match ID} \usage{ -getSquadMatchsums(matches, token) +getSquadMatchsums(matches, token, host = "https://api.impect.com") } \arguments{ \item{matches}{'IMPECT' match IDs} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing the matchsums aggregated per squad for the given match ID diff --git a/man/getSquadRatings.Rd b/man/getSquadRatings.Rd index f6bbaf3..c5eae3d 100644 --- a/man/getSquadRatings.Rd +++ b/man/getSquadRatings.Rd @@ -4,12 +4,14 @@ \alias{getSquadRatings} \title{Return a dataframe that contains squad ratings for a given iteration ID} \usage{ -getSquadRatings(iteration, token) +getSquadRatings(iteration, token, host = "https://api.impect.com") } \arguments{ \item{iteration}{'IMPECT' iteration ID} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing the squad ratings for the given iteration ID diff --git a/man/getStartingPositions.Rd b/man/getStartingPositions.Rd index fca6adc..2610ac8 100644 --- a/man/getStartingPositions.Rd +++ b/man/getStartingPositions.Rd @@ -5,12 +5,14 @@ \title{Return a dataframe that contains all starting positions for a set of given match IDs} \usage{ -getStartingPositions(matches, token) +getStartingPositions(matches, token, host = "https://api.impect.com") } \arguments{ \item{matches}{'IMPECT' match ID or a list of match IDs} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing all starting positions for a set of given diff --git a/man/getSubstitutions.Rd b/man/getSubstitutions.Rd index 68748fa..92cd947 100644 --- a/man/getSubstitutions.Rd +++ b/man/getSubstitutions.Rd @@ -5,12 +5,14 @@ \title{Return a dataframe that contains all line-up changes for a set of given match IDs} \usage{ -getSubstitutions(matches, token) +getSubstitutions(matches, token, host = "https://api.impect.com") } \arguments{ \item{matches}{'IMPECT' match ID or a list of match IDs} \item{token}{bearer token} + +\item{host}{host environment} } \value{ a dataframe containing all line-up changes for a set of given From 6ef228d9daf97187d2ebbeb170967961ca73bfa9 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Wed, 15 Oct 2025 14:11:22 +0200 Subject: [PATCH 12/12] minor fixes for CRAN submission --- R/getAccessToken.R | 1 + R/getPlayerMatchScores.R | 6 +++--- R/getPlayerMatchsums.R | 6 +++--- R/getSquadMatchScores.R | 6 +++--- R/getSquadMatchsums.R | 6 +++--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/R/getAccessToken.R b/R/getAccessToken.R index a34a731..a318e8d 100644 --- a/R/getAccessToken.R +++ b/R/getAccessToken.R @@ -2,6 +2,7 @@ #' #' @param username your 'IMPECT' username #' @param password your 'IMPECT' password +#' @param token_url host specific token url #' #' @return a string containing a bearer token #' @export diff --git a/R/getPlayerMatchScores.R b/R/getPlayerMatchScores.R index 41c79ec..cddf8f4 100644 --- a/R/getPlayerMatchScores.R +++ b/R/getPlayerMatchScores.R @@ -450,14 +450,14 @@ getPlayerMatchScores <- function ( by = c("playerId" = "id") ) %>% dplyr::left_join( - bind_rows( - select( + dplyr::bind_rows( + dplyr::select( matchInfo, matchId = .data$id, squadId = .data$squadHomeId, coachId = .data$homeCoachId ), - select( + dplyr::select( matchInfo, matchId = .data$id, squadId = .data$squadAwayId, diff --git a/R/getPlayerMatchsums.R b/R/getPlayerMatchsums.R index 24376e5..a7eff18 100644 --- a/R/getPlayerMatchsums.R +++ b/R/getPlayerMatchsums.R @@ -309,14 +309,14 @@ getPlayerMatchsums <- function ( by = c("playerId" = "id") ) %>% dplyr::left_join( - bind_rows( - select( + dplyr::bind_rows( + dplyr::select( matchInfo, matchId = .data$id, squadId = .data$squadHomeId, coachId = .data$homeCoachId ), - select( + dplyr::select( matchInfo, matchId = .data$id, squadId = .data$squadAwayId, diff --git a/R/getSquadMatchScores.R b/R/getSquadMatchScores.R index 7b5c55d..9180d89 100644 --- a/R/getSquadMatchScores.R +++ b/R/getSquadMatchScores.R @@ -275,14 +275,14 @@ getSquadMatchScores <- function ( by = c("squadId" = "id") ) %>% dplyr::left_join( - bind_rows( - select( + dplyr::bind_rows( + dplyr::select( matchInfo, matchId = .data$id, squadId = .data$squadHomeId, coachId = .data$homeCoachId ), - select( + dplyr::select( matchInfo, matchId = .data$id, squadId = .data$squadAwayId, diff --git a/R/getSquadMatchsums.R b/R/getSquadMatchsums.R index 97790e6..5d4c41b 100644 --- a/R/getSquadMatchsums.R +++ b/R/getSquadMatchsums.R @@ -275,14 +275,14 @@ getSquadMatchsums <- function ( by = c("squadId" = "squadId") ) %>% dplyr::left_join( - bind_rows( - select( + dplyr::bind_rows( + dplyr::select( matchInfo, matchId = .data$id, squadId = .data$squadHomeId, coachId = .data$homeCoachId ), - select( + dplyr::select( matchInfo, matchId = .data$id, squadId = .data$squadAwayId,