R Package Last X Functionality
The Last X Seconds functionality allows the filtering of metrics so they only count occurrences of the given metric(s) that have taken place within the last ‘X’ seconds of a match.
If used on a live match it will return metric values based on the last ‘X’ seconds since the request was made. If called on a completed match (or quarter) it will filter from the end of the quarter, back to the last ‘X’ number of seconds. As it is a 'seconds' filter, enter 300 to filter the last 5 minutes, 600 for last 10 minutes etc.
This functionality has been applied to all of the relevant player/squad metric functions in the R Package; getPlayerStats()
, getSquadStats()
, getPlayerStatsPOST()
& getSquadStatsPOST()
.
Application
The getPlayerStats()
and getSquadStats()
functions now have an optional parameter input lastXseconds that allows users to take advantage of the Last X Seconds functionality.
It can be passed in alongside any of the other inputs available in these functions.
library(cdAFLAPI)
getPlayerStats(matchId = 120390401,
period = c(1) ,
zone = "F50" ,
metric = "GOAL" ,
team = "home" ,
lastXseconds = 600)
library(cdAFLAPI)
getPlayerStats(matchId = 120390401,
period = c(4) ,
zone = "F50" ,
metric = "GOAL" ,
team = "home" ,
lastXseconds = 600)
The behavior of the API is to tally the metrics across whatever combination of parameters are supplied to it. For example, if we were to combine the quarters from the two examples above into one call, J. De Goey will output as having 2 goals, one in the last 10 minutes of Q1 and Q4.
Post Endpoint
Last X Seconds functionality can also be included in the POST endpoint functions for Player & Squad stats by including a lastXseconds parameter in the payload(s) that go into the function.
# Home Squad Players F50 Goals – Last 10 Minutes of Q4
library(cdAFLAPI)
# Home Squad Players F50 Goals – Last 10 Minutes of Q1
F50_Goals_Q1 `<-` list(
metricCodes = list("GOAL") ,
periods = list(1) ,
zones = list("F50") ,
team = "home" ,
lastXseconds= 600 ,
id = "F50_Goals_Q1"
)
# Home Squad Players F50 Goals – Last 10 Minutes of Q4
F50_Goals_Q4 `<-` list(
metricCodes = list("GOAL") ,
periods = list(4) ,
zones = list("F50") ,
team = "home" ,
lastXseconds= 600 ,
id = "F50_Goals_Q4"
)
# Combine payload(s) via createPayload()
playerPayload `<-` createPayLoad(endpoint = "player", F50_Goals_Q1, F50_Goals_Q4)
# Return data
data `<-` getPlayerStatsPOST(matchId = 120390401, payload = playerPayload, info = F)
In all cases mentioned above, lastXseconds is an optional parameter.
Not including it in either the payload(s) to getPlayerStatsPOST()
/ getSquadStatsPOST()
or as inputs to getPlayerStats()
/ getSquadStats()
directly, will result in metrics being returned for the full period/match specified.