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

[or-cvs] [ernie/master] Write monthly user numbers to .csv files.



Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon, 17 May 2010 14:53:26 +0200
Subject: Write monthly user numbers to .csv files.
Commit: 5ddca612748788c2037caeee5cba77a4e1b8b6c9

---
 R/graphs.R        |    1 +
 R/monthly-users.R |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
 create mode 100644 R/monthly-users.R

diff --git a/R/graphs.R b/R/graphs.R
index b6114d7..bcf6b3a 100644
--- a/R/graphs.R
+++ b/R/graphs.R
@@ -4,4 +4,5 @@ source("R/bridge-stats.R");
 source("R/descriptor-stats.R");
 source("R/torperf.R");
 source("R/gettor.R");
+source("R/monthly-users.R");
 
diff --git a/R/monthly-users.R b/R/monthly-users.R
new file mode 100644
index 0000000..46e6d57
--- /dev/null
+++ b/R/monthly-users.R
@@ -0,0 +1,53 @@
+options(warn = -1)
+suppressPackageStartupMessages(library("ggplot2"))
+
+# Read direct user numbers
+dirreq <- read.csv("stats/dirreq-stats", header = TRUE,
+  stringsAsFactors = FALSE)
+trustedSub <- subset(dirreq,
+  directory %in% "8522EB98C91496E80EC238E732594D1509158E77")
+trustedSub[na.omit(trustedSub$share) == 0,3:length(trustedSub)] <- NA
+trusted <- data.frame(date = trustedSub$date,
+  floor(trustedSub[3:(length(trustedSub) - 1)] / trustedSub$share * 10))
+
+# Read bridge user numbers
+bridge <- read.csv("stats/bridge-stats", header = TRUE,
+  stringsAsFactors = FALSE)
+bridge <- bridge[1:length(bridge$date)-1,]
+bridge <- data.frame(date = bridge[,1],
+  floor(bridge[,2:length(bridge[1,])]))
+
+# Melt both data frames and append them
+bridge_melted <- data.frame(melt(bridge, id.vars = "date", na.rm = TRUE),
+  source = "bridge")
+direct_melted <- data.frame(melt(trusted, id.vars = "date", na.rm = TRUE),
+  source = "direct")
+both_melted <- rbind(bridge_melted, direct_melted)
+
+# Merge data source (bridge or direct)
+country_day <- aggregate(both_melted$value,
+  by = list(date = both_melted$date, country = both_melted$variable), sum)
+
+# Merge months
+month_mean <- aggregate(country_day$x,
+  by = list(month = substr(country_day$date, 1, 7),
+  country = country_day$country), mean)
+month_max <- aggregate(country_day$x,
+  by = list(month = substr(country_day$date, 1, 7),
+  country = country_day$country), max)
+
+# Convert to final matrices
+month_peak <- t(matrix(month_max$x,
+  ncol = length(unique(month_max$country)),
+  dimnames = list(unique(month_max$month),
+  as.vector(unique(month_max$country)))))
+month_avg <- t(matrix(floor(month_mean$x),
+  ncol = length(unique(month_mean$country)),
+  dimnames = list(unique(month_mean$month),
+  as.vector(unique(month_mean$country)))))
+
+# Write to disk
+write.csv(month_peak, "website/csv/monthly-users-peak.csv", quote = FALSE)
+write.csv(month_avg, "website/csv/monthly-users-average.csv",
+  quote = FALSE)
+
-- 
1.6.5