OliverKeyes has submitted this change and it was merged.

Change subject: Enables quick backfilling through system command line Can now 
backfill by calling:   `Rscript run.R [YYYY-MM-DD [YYYY-MM-DD]]` in Terminal. 
If the starting date argument is missing it behaves as classic call to run() in 
run.R, o.w. it will backfill from Y
......................................................................


Enables quick backfilling through system command line
Can now backfill by calling:
  `Rscript run.R [YYYY-MM-DD [YYYY-MM-DD]]`
in Terminal. If the starting date argument is missing
it behaves as classic call to run() in run.R, o.w. it
will backfill from YYYY-MM-DD to Sys.Date()-1 or from
date 1 to date 2.

Requires a change to the cron job since run.R no longer
includes a call to run().

Change-Id: I68c224e9f45931146ef7b3f69e84a2f1bc247a57
---
M CHANGELOG.md
M config.R
M run.R
3 files changed, 44 insertions(+), 8 deletions(-)

Approvals:
  OliverKeyes: Verified; Looks good to me, approved



diff --git a/CHANGELOG.md b/CHANGELOG.md
index 069a91a..d4ef4ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,12 @@
 # Change Log (Patch Notes)
 All notable changes to this project will be documented in this file.
 
+## 2016/01/18
+- Adds quick backfilling through system command line
+
+## 2016/01/15
+- Adds a check for empty dataset returned
+
 ## 2015/11/05
 - Reset default tables for user satisfaction metrics
 - Fix LDN bug
diff --git a/config.R b/config.R
index 41df37b..cbc2d2c 100644
--- a/config.R
+++ b/config.R
@@ -7,11 +7,13 @@
 write_dirs <- paste0(write_root, dirs)
 
 # Dependencies
-library(lubridate)
-library(olivr)
 suppressPackageStartupMessages(library(data.table))
-library(readr)
-library(ortiz)
-library(plyr)
-library(magrittr)
-library(survival)
+suppressMessages({
+  library(lubridate)
+  library(olivr)
+  library(readr)
+  library(ortiz)
+  library(plyr)
+  library(magrittr)
+  library(survival)
+})
diff --git a/run.R b/run.R
index 4da8f28..8bdeb2c 100644
--- a/run.R
+++ b/run.R
@@ -1,4 +1,13 @@
+args <- commandArgs(trailingOnly = TRUE)
 source("common.R") # config.R is sourced by common.R anyway
+
+# Usage: Rscript run.R [start_date [end_date]]
+#
+#   - To backfill data from a specific date (inclusive) to Sys.Date()-1:
+#     $> Rscript run.R YYYY-MM-DD
+#
+#   - To backfill data from a specific date range (inclusive):
+#     $> Rscript run.R YYYY-MM-DD YYYY-MM-DD
 
 # Central function
 run <- function(dates = NULL){
@@ -58,4 +67,23 @@
 
 }
 
-run()
+switch(as.character(length(args)),
+       "0" = {
+         message("Assuming user wants previous day's data.")
+         run()
+       },
+       "1" = {
+         start_date <- as.Date(args[1])
+         end_date <- Sys.Date() - 1
+         message("Backfilling data from", start_date, "to", end_date)
+         run(seq(start_date, end_date, "day"))
+       },
+       "2" = {
+         start_date <- as.Date(args[1])
+         end_date <- as.Date(args[2])
+         if (start_date < end_date) {
+           message("Backfilling data from", start_date, "to", end_date)
+           run(seq(start_date, end_date, "day"))
+         }
+         print("Backfilling start date must be before the end date.")
+       })

-- 
To view, visit https://gerrit.wikimedia.org/r/264785
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I68c224e9f45931146ef7b3f69e84a2f1bc247a57
Gerrit-PatchSet: 4
Gerrit-Project: wikimedia/discovery/golden
Gerrit-Branch: master
Gerrit-Owner: Bearloga <mpo...@wikimedia.org>
Gerrit-Reviewer: OliverKeyes <oke...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to