[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [ernie/master] Automatically update list of graphs to generate.



Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Sat, 8 May 2010 21:08:28 +0200
Subject: Automatically update list of graphs to generate.
Commit: 85d235eedbd47c3b26d22a0c5a33839e107b16e4

---
 R/bridge-stats.R    |   28 ++++++++++++++++++++++++----
 R/consensus-stats.R |   35 +++++++++++++++++++++++++++++------
 R/dirreq-stats.R    |   35 +++++++++++++++++++++++++++++------
 3 files changed, 82 insertions(+), 16 deletions(-)

diff --git a/R/bridge-stats.R b/R/bridge-stats.R
index db629a1..066e51f 100644
--- a/R/bridge-stats.R
+++ b/R/bridge-stats.R
@@ -99,13 +99,33 @@ plot_months <- function(years, months, countries) {
   }
 }
 
-# TODO these need to be updated manually
 plot_current <- function(countries) {
   plot_alldata(countries)
   plot_pastdays(c(30, 90, 180), countries)
-  plot_years("2010", countries)
-  plot_quarters("2010", 2, countries)
-  plot_months("2010", 4, countries)
+  today <- as.POSIXct(Sys.Date(), tz = "GMT")
+  one_week_ago <- seq(from = today, length = 2, by = "-7 days")[2]
+  year_today <- format(today, "%Y")
+  year_one_week_ago <- format(one_week_ago, "%Y")
+  quarter_today <- 1 + floor((as.numeric(format(today, "%m")) - 1) / 3)
+  quarter_one_week_ago <- 1 + floor((as.numeric(format(one_week_ago,
+    "%m")) - 1) / 3)
+  month_today <- as.numeric(format(today, "%m"))
+  month_one_week_ago <- as.numeric(format(one_week_ago, "%m"))
+  plot_years(union(year_today, year_one_week_ago), countries)
+  if (year_today == year_one_week_ago) {
+    plot_quarters(year_today, union(quarter_today, quarter_one_week_ago),
+      countries)
+  } else {
+    plot_quarters(year_today, quarter_today, countries)
+    plot_quarters(year_one_week_ago, quarter_one_week_ago, countries)
+  }
+  if (year_today == year_one_week_ago) {
+    plot_months(year_today, union(month_today, month_one_week_ago),
+      countries)
+  } else {
+    plot_months(year_today, month_today, countries)
+    plot_months(year_one_week_ago, month_one_week_ago, countries)
+  }
 }
 
 countries <- data.frame(code = c("bh", "cn", "cu", "et", "ir", "mm", "sa",
diff --git a/R/consensus-stats.R b/R/consensus-stats.R
index 1baa7c6..4352361 100644
--- a/R/consensus-stats.R
+++ b/R/consensus-stats.R
@@ -108,12 +108,35 @@ plot_current <- function(directory, filenamePart, titlePart, rows, breaks,
     labels) {
   plot_pastdays(directory, filenamePart, titlePart, c(30, 90, 180), rows,
     breaks, labels)
-  plot_years(directory, filenamePart, titlePart, "2010", rows, breaks,
-    labels)
-  plot_quarters(directory, filenamePart, titlePart, "2010", 2, rows,
-    breaks, labels)
-  plot_months(directory, filenamePart, titlePart, "2010", 4, rows, breaks,
-    labels)
+  today <- as.POSIXct(Sys.Date(), tz = "GMT")
+  one_week_ago <- seq(from = today, length = 2, by = "-7 days")[2]
+  year_today <- format(today, "%Y")
+  year_one_week_ago <- format(one_week_ago, "%Y")
+  quarter_today <- 1 + floor((as.numeric(format(today, "%m")) - 1) / 3)
+  quarter_one_week_ago <- 1 + floor((as.numeric(format(one_week_ago,
+    "%m")) - 1) / 3)
+  month_today <- as.numeric(format(today, "%m"))
+  month_one_week_ago <- as.numeric(format(one_week_ago, "%m"))
+  plot_years(directory, filenamePart, titlePart, union(year_today,
+    year_one_week_ago), rows, breaks, labels)
+  if (year_today == year_one_week_ago) {
+    plot_quarters(directory, filenamePart, titlePart, year_today,
+      union(quarter_today, quarter_one_week_ago), rows, breaks, labels)
+  } else {
+    plot_quarters(directory, filenamePart, titlePart, year_today,
+      quarter_today, rows, breaks, labels)
+    plot_quarters(directory, filenamePart, titlePart, year_one_week_ago,
+      quarter_one_week_ago, rows, breaks, labels)
+  }
+  if (year_today == year_one_week_ago) {
+    plot_months(directory, filenamePart, titlePart, year_today,
+      union(month_today, month_one_week_ago), rows, breaks, labels)
+  } else {
+    plot_months(directory, filenamePart, titlePart, year_today, month_today,
+      rows, breaks, labels)
+    plot_months(directory, filenamePart, titlePart, year_one_week_ago,
+      month_one_week_ago, rows, breaks, labels)
+  }
   plot_all(directory, filenamePart, titlePart, rows, breaks, labels)
 }
 
diff --git a/R/dirreq-stats.R b/R/dirreq-stats.R
index fa02e75..0a48b6f 100644
--- a/R/dirreq-stats.R
+++ b/R/dirreq-stats.R
@@ -118,17 +118,40 @@ plot_months <- function(directory, filenamePart, titlePart, years, months,
   }
 }
 
-# TODO these need to be updated manually
 plot_current <- function(directory, filenamePart, titlePart, data,
     countries) {
   plot_alldata(directory, filenamePart, titlePart, data, countries)
   plot_pastdays(directory, filenamePart, titlePart, c(30, 90, 180), data,
     countries)
-  plot_years(directory, filenamePart, titlePart, "2010", data, countries)
-  plot_quarters(directory, filenamePart, titlePart, "2010", 2, data,
-    countries)
-  plot_months(directory, filenamePart, titlePart, "2010", 4, data,
-    countries)
+  today <- as.POSIXct(Sys.Date(), tz = "GMT")
+  one_week_ago <- seq(from = today, length = 2, by = "-7 days")[2]
+  year_today <- format(today, "%Y")
+  year_one_week_ago <- format(one_week_ago, "%Y")
+  quarter_today <- 1 + floor((as.numeric(format(today, "%m")) - 1) / 3)
+  quarter_one_week_ago <- 1 + floor((as.numeric(format(one_week_ago,
+    "%m")) - 1) / 3)
+  month_today <- as.numeric(format(today, "%m"))
+  month_one_week_ago <- as.numeric(format(one_week_ago, "%m"))
+  plot_years(directory, filenamePart, titlePart, union(year_today,
+    year_one_week_ago), data, countries)
+  if (year_today == year_one_week_ago) {
+    plot_quarters(directory, filenamePart, titlePart, year_today,
+      union(quarter_today, quarter_one_week_ago), data, countries)
+  } else {
+    plot_quarters(directory, filenamePart, titlePart, year_today,
+      quarter_today, data, countries)
+    plot_quarters(directory, filenamePart, titlePart, year_one_week_ago,
+      quarter_one_week_ago, data, countries)
+  }
+  if (year_today == year_one_week_ago) {
+    plot_months(directory, filenamePart, titlePart, year_today,
+      union(month_today, month_one_week_ago), data, countries)
+  } else {
+    plot_months(directory, filenamePart, titlePart, year_today,
+      month_today, data, countries)
+    plot_months(directory, filenamePart, titlePart, year_one_week_ago,
+      month_one_week_ago, data, countries)
+  }
 }
 
 countries <- data.frame(code = c("bh", "cn", "cu", "et", "ir", "mm", "sa",
-- 
1.6.5