diff --git a/R/wikia_admin.R b/R/wikia_admin.R index 10b7b1f..22b0b02 100644 --- a/R/wikia_admin.R +++ b/R/wikia_admin.R @@ -67,21 +67,25 @@ generate.admin.addrm <- function (logevents, current.admins) { # another function to handle processing the ancients: parse.ancient <- function (i, d) { - user <- sub('^.*?:', '', d[i,"title"]) - comment <- d[i, "comment"] - change.time <- d[i, "timestamp"] + user <- sub('^.*?:', '', d[i,"title"]) + log.comment <- d[i, "comment"] + change.time <- d[i, "timestamp"] - added <- unlist(strsplit(unlist(strsplit(comment, '(\\+|\\=)')), ', ')) + log.comment <- as.character(log.comment) + added <- unlist(strsplit(unlist(strsplit(log.comment, '(\\+|\\=)')), ', ')) + + if(is.null(added)){ + added <- '' + } + ## clean any leadin, trailing whitespace + added <- gsub("^\\s+|\\s+$", "", added) - # clean any leadin, trailing whitespace - added <- gsub("^\\s+|\\s+$", "", added) - - data.frame(user=user, - role=added, - action="added", - timestamp=change.time, - era="ancient", - stringsAsFactors=FALSE) + data.frame(user=user, + role=added, + action="added", + timestamp=change.time, + era="ancient", + stringsAsFactors=FALSE) } # if there are any ancients, we parse them @@ -109,10 +113,15 @@ generate.admin.addrm <- function (logevents, current.admins) { return(o) } - current.admins.parsed <- do.call("rbind", - lapply(1:dim(current.admins)[1], - parse.current.admins, current.admins)) - + if(dim(current.admins)[1] > 0){ + current.admins.parsed <- do.call("rbind", + lapply(1:dim(current.admins)[1], + parse.current.admins, current.admins)) + } + else { + current.admins.parsed <- data.frame(user=character(),role=character()) + } + # select pre-ancients as people who have a given right *today* but # were never seen as having it added is.pre.ancients <- function (i, d, combined) { @@ -155,11 +164,13 @@ generate.admin.addrm <- function (logevents, current.admins) { pre.ancients <- rbind(pre.ancients, combined.removed) - # give them the earliest ancient timestamp minus 1 day - pre.ancients$action <- "added" - pre.ancients$timestamp <- as.POSIXct("2000-01-01 00:00:00") # min(combined$timestamp) - 60 * 1440 - pre.ancients$era <- "pre.ancient" - + if(nrow(pre.ancients) > 0){ + ## give them the earliest ancient timestamp minus 1 day + pre.ancients$action <- "added" + pre.ancients$timestamp <- as.POSIXct("2000-01-01 00:00:00") # min(combined$timestamp) - 60 * 1440 + pre.ancients$era <- "pre.ancient" + } + # and then add the pre.ancients to the combined <- rbind(combined, pre.ancients)