[tor-commits] [onionoo/master] Don't merge intervals across month ends.
karsten at torproject.org
karsten at torproject.org
Tue Mar 11 07:53:28 UTC 2014
commit 26d20b3451a069157e2f8ec962007588fe3b5344
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Thu Mar 6 17:56:35 2014 +0100
Don't merge intervals across month ends.
Prepares for providing monthly relay and bridge statistics (#11041).
---
src/org/torproject/onionoo/BandwidthDataWriter.java | 8 +++++++-
src/org/torproject/onionoo/ClientsDataWriter.java | 8 +++++++-
src/org/torproject/onionoo/WeightsDataWriter.java | 8 +++++++-
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/org/torproject/onionoo/BandwidthDataWriter.java b/src/org/torproject/onionoo/BandwidthDataWriter.java
index 68bf59a..9f2f97e 100644
--- a/src/org/torproject/onionoo/BandwidthDataWriter.java
+++ b/src/org/torproject/onionoo/BandwidthDataWriter.java
@@ -179,6 +179,9 @@ public class BandwidthDataWriter implements DataWriter,
new TreeMap<Long, long[]>(history);
history.clear();
long lastStartMillis = 0L, lastEndMillis = 0L, lastBandwidth = 0L;
+ SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM");
+ dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String lastMonthString = "1970-01";
for (long[] v : uncompressedHistory.values()) {
long startMillis = v[0], endMillis = v[1], bandwidth = v[2];
long intervalLengthMillis;
@@ -195,9 +198,11 @@ public class BandwidthDataWriter implements DataWriter,
} else {
intervalLengthMillis = 10L * 24L * 60L * 60L * 1000L;
}
+ String monthString = dateTimeFormat.format(startMillis);
if (lastEndMillis == startMillis &&
((lastEndMillis - 1L) / intervalLengthMillis) ==
- ((endMillis - 1L) / intervalLengthMillis)) {
+ ((endMillis - 1L) / intervalLengthMillis) &&
+ lastMonthString.equals(monthString)) {
lastEndMillis = endMillis;
lastBandwidth += bandwidth;
} else {
@@ -209,6 +214,7 @@ public class BandwidthDataWriter implements DataWriter,
lastEndMillis = endMillis;
lastBandwidth = bandwidth;
}
+ lastMonthString = monthString;
}
if (lastStartMillis > 0L) {
history.put(lastStartMillis, new long[] { lastStartMillis,
diff --git a/src/org/torproject/onionoo/ClientsDataWriter.java b/src/org/torproject/onionoo/ClientsDataWriter.java
index 9e868a4..b956f59 100644
--- a/src/org/torproject/onionoo/ClientsDataWriter.java
+++ b/src/org/torproject/onionoo/ClientsDataWriter.java
@@ -356,6 +356,9 @@ public class ClientsDataWriter implements DataWriter, DescriptorListener {
SortedSet<ResponseHistory> compressedHistory =
new TreeSet<ResponseHistory>();
ResponseHistory lastResponses = null;
+ SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM");
+ dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String lastMonthString = "1970-01";
for (ResponseHistory responses : history) {
long intervalLengthMillis;
if (this.now - responses.endMillis <=
@@ -367,10 +370,12 @@ public class ClientsDataWriter implements DataWriter, DescriptorListener {
} else {
intervalLengthMillis = 10L * 24L * 60L * 60L * 1000L;
}
+ String monthString = dateTimeFormat.format(responses.startMillis);
if (lastResponses != null &&
lastResponses.endMillis == responses.startMillis &&
((lastResponses.endMillis - 1L) / intervalLengthMillis) ==
- ((responses.endMillis - 1L) / intervalLengthMillis)) {
+ ((responses.endMillis - 1L) / intervalLengthMillis) &&
+ lastMonthString.equals(monthString)) {
lastResponses.addResponses(responses);
} else {
if (lastResponses != null) {
@@ -378,6 +383,7 @@ public class ClientsDataWriter implements DataWriter, DescriptorListener {
}
lastResponses = responses;
}
+ lastMonthString = monthString;
}
if (lastResponses != null) {
compressedHistory.add(lastResponses);
diff --git a/src/org/torproject/onionoo/WeightsDataWriter.java b/src/org/torproject/onionoo/WeightsDataWriter.java
index 81b412c..855e3e9 100644
--- a/src/org/torproject/onionoo/WeightsDataWriter.java
+++ b/src/org/torproject/onionoo/WeightsDataWriter.java
@@ -371,6 +371,9 @@ public class WeightsDataWriter implements DataWriter, DescriptorListener {
new TreeMap<long[], double[]>(history.comparator());
long lastStartMillis = 0L, lastEndMillis = 0L;
double[] lastWeights = null;
+ SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM");
+ dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String lastMonthString = "1970-01";
for (Map.Entry<long[], double[]> e : history.entrySet()) {
long startMillis = e.getKey()[0], endMillis = e.getKey()[1];
double[] weights = e.getValue();
@@ -386,9 +389,11 @@ public class WeightsDataWriter implements DataWriter, DescriptorListener {
} else {
intervalLengthMillis = 10L * 24L * 60L * 60L * 1000L;
}
+ String monthString = dateTimeFormat.format(startMillis);
if (lastEndMillis == startMillis &&
((lastEndMillis - 1L) / intervalLengthMillis) ==
- ((endMillis - 1L) / intervalLengthMillis)) {
+ ((endMillis - 1L) / intervalLengthMillis) &&
+ lastMonthString.equals(monthString)) {
double lastIntervalInHours = (double) ((lastEndMillis
- lastStartMillis) / 60L * 60L * 1000L);
double currentIntervalInHours = (double) ((endMillis
@@ -410,6 +415,7 @@ public class WeightsDataWriter implements DataWriter, DescriptorListener {
lastEndMillis = endMillis;
lastWeights = weights;
}
+ lastMonthString = monthString;
}
if (lastStartMillis > 0L) {
compressedHistory.put(new long[] { lastStartMillis, lastEndMillis },
More information about the tor-commits
mailing list