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

[tor-commits] [metrics-tasks/master] Add graphing code for bandwidth by version (13634).



commit f0b12e1198afb38a8f72f68d855fbee6d0e73367
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon Nov 3 10:18:31 2014 +0100

    Add graphing code for bandwidth by version (13634).
---
 task-13634/.gitignore    |    8 +++++++
 task-13634/aggregate.R   |   10 +++++++++
 task-13634/plot.R        |    9 ++++++++
 task-13634/src/Main.java |   55 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 82 insertions(+)

diff --git a/task-13634/.gitignore b/task-13634/.gitignore
new file mode 100644
index 0000000..b23a00a
--- /dev/null
+++ b/task-13634/.gitignore
@@ -0,0 +1,8 @@
+.classpath
+.project
+/bin
+/in
+Rplots.pdf
+*.csv
+*.png
+
diff --git a/task-13634/aggregate.R b/task-13634/aggregate.R
new file mode 100644
index 0000000..0c2cf6b
--- /dev/null
+++ b/task-13634/aggregate.R
@@ -0,0 +1,10 @@
+c <- read.csv("cw-by-ver.csv", header = FALSE)
+c <- aggregate(list(cw = c$V3),
+               by = list(datetime = c$V1, version = c$V2),
+               FUN = sum)
+c <- aggregate(list(cw = c$cw),
+               by = list(date = as.character(as.Date(c$datetime)),
+                         version = c$version),
+               FUN = mean)
+write.csv(c, "cw-by-ver-date.csv", row.names = FALSE, quote = FALSE)
+
diff --git a/task-13634/plot.R b/task-13634/plot.R
new file mode 100644
index 0000000..efb84f0
--- /dev/null
+++ b/task-13634/plot.R
@@ -0,0 +1,9 @@
+require(ggplot2)
+c <- read.csv("cw-by-ver-date.csv")
+ggplot(c, aes(x = as.Date(date), y = cw, colour = version)) +
+geom_line() +
+scale_x_date("") +
+scale_y_continuous("") +
+ggtitle("Total consensus weight of running relays by version\n")
+ggsave("cw-by-ver.png", width = 8, height = 5, dpi = 100)
+
diff --git a/task-13634/src/Main.java b/task-13634/src/Main.java
new file mode 100644
index 0000000..7c0ddb0
--- /dev/null
+++ b/task-13634/src/Main.java
@@ -0,0 +1,55 @@
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Iterator;
+import java.util.TimeZone;
+
+import org.torproject.descriptor.Descriptor;
+import org.torproject.descriptor.DescriptorFile;
+import org.torproject.descriptor.DescriptorReader;
+import org.torproject.descriptor.DescriptorSourceFactory;
+import org.torproject.descriptor.NetworkStatusEntry;
+import org.torproject.descriptor.RelayNetworkStatusConsensus;
+
+
+public class Main {
+  public static void main(String[] args) throws Exception {
+    BufferedWriter bw = new BufferedWriter(new FileWriter(
+        "cw-by-ver.csv"));
+    DescriptorReader descriptorReader =
+        DescriptorSourceFactory.createDescriptorReader();
+    descriptorReader.addDirectory(new File("in"));
+    Iterator<DescriptorFile> descriptorFiles =
+        descriptorReader.readDescriptors();
+    while (descriptorFiles.hasNext()) {
+      DescriptorFile descriptorFile = descriptorFiles.next();
+      for (Descriptor descriptor : descriptorFile.getDescriptors()) {
+        if (!(descriptor instanceof RelayNetworkStatusConsensus)) {
+          continue;
+        }
+        RelayNetworkStatusConsensus consensus =
+            (RelayNetworkStatusConsensus) descriptor;
+        DateFormat dateTimeFormat = new SimpleDateFormat(
+            "yyyy-MM-dd HH:mm:ss");
+        dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+        String validAfter = dateTimeFormat.format(
+            consensus.getValidAfterMillis());
+        for (NetworkStatusEntry entry :
+            consensus.getStatusEntries().values()) {
+          String version = entry.getVersion();
+          if (version != null && version.startsWith("Tor ") &&
+              version.length() >= 9) {
+            version = version.substring(4, 9); /* 0.2.5 of Tor 0.2.5.11 */
+          } else {
+            version = "other";
+          }
+          bw.write(validAfter + "," + version + ","
+              + entry.getBandwidth() + "\n");
+        }
+      }
+    }
+    bw.close();
+  }
+}

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits