#' Getting death stats
#'
#' Get the deaths from an appropriate API endpoint.
#'
#' Uses a \code{people} object for sorting, and substitution if needed.
#' @param url URL of the appropriate API endpoint, defaults to \code{getOption("url.general.deaths.latest")},
#' and if that returns \code{NULL}, the Wurstmineberg API endpoint is used.
#' @param people The people dataset to be used for sorting/naming the players, defaults to \code{activePeople}
#' @param type Either \code{latest} for latest deaths only, or \code{full}, for a full set. Default is \code{latest}
#' @keywords deaths
#' @return \code{data.frame} containing latest deaths for each player
#' @export
#' @note The API uses a different log than Minecraft stats, tl;dr things are complicated
#' @examples
#' \dontrun{
#' options(url.general.deaths.latest = "http://api.wurstmineberg.de/server/deaths/latest.json")
#' deaths <- getDeaths()
#' }
getDeaths <- function(url = getOption("url.general.deaths.latest"),
people = NULL, type = "latest"){
if (is.null(url)){
url <- "http://api.wurstmineberg.de/server/deaths/latest.json"
}
if (!("activePeople" %in% ls()) & people == activePeople){
people <- getActivePeople()
}
latestdeaths <- jsonlite::fromJSON(url)
deaths <- plyr::ldply(latestdeaths$deaths, data.frame, .id = "player")
deaths$timestamp <- as.POSIXct(deaths$timestamp, tz="UTC")
deaths$daysSince <- as.numeric(round(difftime(Sys.time(), deaths$timestamp, units="days")))
# Match against activePeople and sort accordingly
deaths <- deaths[match(people$id, deaths$player), ]
deaths$player <- people$name
deaths$joinStatus <- people$joinStatus
# Remove NAs introduced by matching with activePoeple
# Should be uneccessary when everyone hase been active / died since logging started
deaths <- deaths[!is.na(deaths$timestamp), ]
return(deaths)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.