bugfixes for empty comments and empty logs master
authorgroceryheist <nathante@uw.edu>
Mon, 9 Apr 2018 23:53:47 +0000 (23:53 +0000)
committergroceryheist <nathante@uw.edu>
Mon, 9 Apr 2018 23:53:47 +0000 (23:53 +0000)
R/wikia_admin.R

index 10b7b1f0a265e90b4118e15774087e5a084b0f2f..22b0b02dc880c161026e891c95447b3f244d17ef 100644 (file)
@@ -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"]
-
-    added <- unlist(strsplit(unlist(strsplit(comment, '(\\+|\\=)')), ', '))
-
-    # 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)
+      user <- sub('^.*?:', '', d[i,"title"])
+      log.comment <- d[i, "comment"]
+      change.time <- d[i, "timestamp"]
+
+      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)
+
+      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)
 

Community Data Science Collective || Want to submit a patch?