TokenBucket Class
Description
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.
Fields
capacityThe maximum number of tokens in the bucket.
tokensThe number of tokens currently available in the bucket.
intervalThe duration in seconds after which the bucket gets refilled.
last_updateThe timestamp of the last update to the bucket.
Examples
try({
# create token bucket
bucket <- TokenBucket(
capacity = 10,
tokens = 10,
intervall = 1,
last_update = Sys.Time()
)
# add tokens to bucket
bucket$addTokens()
# check if a token is available
bucket$isTokenAvailable
# consume token
bucket$consumeToken
})
Get an access token from the 'Impect' Customer API
Description
Get an access token from the 'Impect' Customer API
Usage
getAccessToken(
username,
password,
token_url =
"https://login.impect.com/auth/realms/production/protocol/openid-connect/token"
)
Arguments
username
your 'IMPECT' username
password
your 'IMPECT' password
token_url
host specific token url
Value
a string containing a bearer token
Examples
# Toy example: this will error quickly (no credentials)
try(getAccessToken(username = "invalidUser", password = "invalidPassword"))
# Real usage: requires valid credentials
## Not run:
token <- getAccessToken(username = "yourUsername", password = "yourPassword")
## End(Not run)
Return a dataframe that contains all events and kpi values for a set of given match IDs
Description
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,
host = "https://api.impect.com"
)
Arguments
matches
'IMPECT' match ID or a list of match IDs
token
bearer token
include_kpis
include KPIs in event data
include_set_pieces
include additional set piece data in event data
host
host environment
Value
a dataframe containing all events and kpi values for a set of given match IDs
Examples
# 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()`
## Not run:
events <- getEvents(
matches = c(84248, 158150),
token = "yourToken",
include_kpis = T,
include_set_pieces = F
)
## End(Not run)
Return a dataframe that contains all starting formations for a set of given match IDs
Description
Return a dataframe that contains all starting formations for a set of given match IDs
Usage
getFormations(matches, token, host = "https://api.impect.com")
Arguments
matches
'IMPECT' match ID or a list of match IDs
token
bearer token
host
host environment
Value
a dataframe containing all starting formations for a set of given match IDs
Examples
# 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()`
## Not run:
formations <- getFormations(
matches = c(84248, 158150),
token = "yourToken"
)
## End(Not run)
Return a dataframe containing all iterations available to the user
Description
Return a dataframe containing all iterations available to the user
Usage
getIterations(token, host = "https://api.impect.com")
Arguments
token
bearer token
host
host environment
Value
a dataframe containing all iterations available to the user
Examples
# Toy example: this will error quickly (no API token)
try(events <- getIterations(
token = "invalid"
))
# Real usage: requires valid Bearer Token from `getAccessToken()`
## Not run:
iterations <- getIterations(
token = "yourToken"
)
## End(Not run)
Return a dataframe with basic information for all matches for a given iteration ID
Description
Return a dataframe with basic information for all matches for a given iteration ID
Usage
getMatches(iteration, token, host = "https://api.impect.com")
Arguments
iteration
'IMPECT' iteration ID
token
bearer token
host
host environment
Value
a dataframe containing all matches for a given iteration ID
Examples
# Toy example: this will error quickly (no API token)
try(matchplan <- getMatches(
iteration = 0,
token = "invalid"
))
# Real usage: requires valid Bearer Token from `getAccessToken()`
## Not run:
matchplan <- getMatches(
iteration = 1004,
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all player averages for a given iteration ID
Description
Return a dataframe that contains all player averages for a given iteration ID
Usage
getPlayerIterationAverages(iteration, token, host = "https://api.impect.com")
Arguments
iteration
'IMPECT' iteration ID
token
bearer token
host
host environment
Value
a dataframe containing the KPI averages aggregated per player and position for the given iteration ID
Examples
# 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()`
## Not run:
player_avgs <- getPlayerIterationAverages(
iteration = 1004,
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all player scores for a given iteration ID
Description
Return a dataframe that contains all player scores for a given iteration ID
Usage
getPlayerIterationScores(
iteration,
token,
positions = NULL,
host = "https://api.impect.com"
)
Arguments
iteration
'IMPECT' iteration ID
token
bearer token
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". If not submitted, function will return all positions individually.
host
host environment
Value
a dataframe containing the player scores aggregated per player for the given iteration ID and list of positions
Examples
# 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()`
## Not run:
player_scores <- getPlayerIterationScores(
iteration = 1004,
positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"),
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all player scores for a given match ID and list of positions
Description
Return a dataframe that contains all player scores for a given match ID and list of positions
Usage
getPlayerMatchScores(
matches,
token,
positions = NULL,
host = "https://api.impect.com"
)
Arguments
matches
'IMPECT' match IDs
token
bearer token
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". If not submitted, function will return all positions individually.
host
host environment
Value
a dataframe containing the scores aggregated per player and position for the given match ID and list of positions
Examples
# 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()`
## Not run:
player_match_scores <- getPlayerMatchScores(
matches = c(84248, 158150),
positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"),
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all player matchsums for a given match ID
Description
Return a dataframe that contains all player matchsums for a given match ID
Usage
getPlayerMatchsums(matches, token, host = "https://api.impect.com")
Arguments
matches
'IMPECT' match IDs
token
bearer token
host
host environment
Value
a dataframe containing the matchsums aggregated per player and position for the given match ID
Examples
# 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()`
## Not run:
player_match_sums <- getPlayerMatchsums(
matches = c(84248, 158150),
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all player profile scores for a given iteration ID
Description
Return a dataframe that contains all player profile scores for a given iteration ID
Usage
getPlayerProfileScores(
iteration,
positions,
token,
host = "https://api.impect.com"
)
Arguments
iteration
'IMPECT' iteration ID
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", "RIGHT_WINGER", "CENTER_FORWARD"
token
bearer token
host
host environment
Value
a dataframe containing the player profilescores aggregated per player for the given iteration ID and list of positions
Examples
# 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()`
## Not run:
player_profile_scores <- getPlayerProfileScores(
iteration = 1004,
positions = c("CENTRAL_DEFENDER", "DEFENSE_MIDFIELD"),
token = "yourToken"
)
## End(Not run)
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
Description
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, host = "https://api.impect.com")
Arguments
matches
list fo 'IMPECT' match IDs
token
bearer token
host
host environment
Value
a dataframe containing all set pieces and aggregated kpi values per set piece sub phase for a set of given list of match IDs
Examples
# 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()`
## Not run:
set_pieces <- getSetPieces(
matches = c(84248, 158150),
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains squad ratings for a given iteration ID
Description
Return a dataframe that contains squad ratings for a given iteration ID
Usage
getSquadCoefficients(iteration, token, host = "https://api.impect.com")
Arguments
iteration
'IMPECT' iteration ID
token
bearer token
host
host environment
Value
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()`
## Not run:
squad_ratings <- getSquadRatings(
iteration = 1004,
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all squads averages for a given iteration ID
Description
Return a dataframe that contains all squads averages for a given iteration ID
Usage
getSquadIterationAverages(iteration, token, host = "https://api.impect.com")
Arguments
iteration
'IMPECT' iteration ID
token
bearer token
host
host environment
Value
a dataframe containing the KPI averages aggregated per squad for the given iteration ID
Examples
# 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()`
## Not run:
squad_avgs <- getSquadIterationAverages(
iteration = 1004,
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all squads scores for a given iteration ID
Description
Return a dataframe that contains all squads scores for a given iteration ID
Usage
getSquadIterationScores(iteration, token, host = "https://api.impect.com")
Arguments
iteration
'IMPCET' iteration ID
token
bearer token
host
host environment
Value
a dataframe containing the squad scores aggregated per squad for the given iteration ID
Examples
# 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()`
## Not run:
squad_scores <- getSquadIterationScores(
iteration = 1004,
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains squad level scores and ratios for a given match ID
Description
Return a dataframe that contains squad level scores and ratios for a given match ID
Usage
getSquadMatchScores(matches, token, host = "https://api.impect.com")
Arguments
matches
'IMPECT' match IDs
token
bearer token
host
host environment
Value
a dataframe containing the scores and rations aggregated per squad for the given match ID
Examples
# 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()`
## Not run:
squad_match_scores <- getSquadMatchScores(
matches = c(84248, 158150),
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains squad level matchsums for a given match ID
Description
Return a dataframe that contains squad level matchsums for a given match ID
Usage
getSquadMatchsums(matches, token, host = "https://api.impect.com")
Arguments
matches
'IMPECT' match IDs
token
bearer token
host
host environment
Value
a dataframe containing the matchsums aggregated per squad for the given match ID
Examples
# 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()`
## Not run:
squad_match_sums <- getSquadMatchsums(
matches = c(84248, 158150),
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains squad ratings for a given iteration ID
Description
Return a dataframe that contains squad ratings for a given iteration ID
Usage
getSquadRatings(iteration, token, host = "https://api.impect.com")
Arguments
iteration
'IMPECT' iteration ID
token
bearer token
host
host environment
Value
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()`
## Not run:
squad_ratings <- getSquadRatings(
iteration = 1004,
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all starting positions for a set of given match IDs
Description
Return a dataframe that contains all starting positions for a set of given match IDs
Usage
getStartingPositions(matches, token, host = "https://api.impect.com")
Arguments
matches
'IMPECT' match ID or a list of match IDs
token
bearer token
host
host environment
Value
a dataframe containing all starting positions for a set of given match IDs
Examples
# 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()`
## Not run:
starting_pos <- getStartingPositions(
matches = c(84248, 158150),
token = "yourToken"
)
## End(Not run)
Return a dataframe that contains all line-up changes for a set of given match IDs
Description
Return a dataframe that contains all line-up changes for a set of given match IDs
Usage
getSubstitutions(matches, token, host = "https://api.impect.com")
Arguments
matches
'IMPECT' match ID or a list of match IDs
token
bearer token
host
host environment
Value
a dataframe containing all line-up changes for a set of given match IDs
Examples
# 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()`
## Not run:
subs <- getSubstitutions(
matches = c(84248, 158150),
token = "yourToken"
)
## End(Not run)