commit 56695bcbaa409644b2036c508f4d0cf80796241a Author: Karsten Loesing karsten.loesing@gmx.net Date: Sat Apr 12 18:41:29 2014 +0200
Fix minor bug in writing uptime documents.
When a relay first showed up in the middle of a, say, 4-hour interval, we discounted its uptime in that interval by the number of hours that it wasn't online. We should ignore those hours. --- .../torproject/onionoo/UptimeDocumentWriter.java | 79 +++++++++++--------- 1 file changed, 44 insertions(+), 35 deletions(-)
diff --git a/src/org/torproject/onionoo/UptimeDocumentWriter.java b/src/org/torproject/onionoo/UptimeDocumentWriter.java index 60ca311..14c800d 100644 --- a/src/org/torproject/onionoo/UptimeDocumentWriter.java +++ b/src/org/torproject/onionoo/UptimeDocumentWriter.java @@ -129,14 +129,18 @@ public class UptimeDocumentWriter implements FingerprintListener, this.dataPointIntervals[graphIntervalIndex]; int dataPointIntervalHours = (int) (dataPointInterval / DateTimeHelper.ONE_HOUR); - List<Integer> statusDataPoints = new ArrayList<Integer>(); + List<Integer> uptimeDataPoints = new ArrayList<Integer>(); long intervalStartMillis = ((this.now - graphInterval) / dataPointInterval) * dataPointInterval; - int statusHours = 0; - for (UptimeHistory hist : knownStatuses) { + int uptimeHours = 0; + long firstStatusStartMillis = -1L; + for (UptimeHistory hist : history) { if (hist.isRelay() != relay) { continue; } + if (firstStatusStartMillis < 0L) { + firstStatusStartMillis = hist.getStartMillis(); + } long histEndMillis = hist.getStartMillis() + DateTimeHelper.ONE_HOUR * hist.getUptimeHours(); if (histEndMillis < intervalStartMillis) { @@ -144,38 +148,36 @@ public class UptimeDocumentWriter implements FingerprintListener, } while (hist.getStartMillis() >= intervalStartMillis + dataPointInterval) { - statusDataPoints.add(statusHours * 5 > dataPointIntervalHours - ? statusHours : -1); - statusHours = 0; + if (firstStatusStartMillis < intervalStartMillis + + dataPointInterval) { + uptimeDataPoints.add(uptimeHours); + } else { + uptimeDataPoints.add(-1); + } + uptimeHours = 0; intervalStartMillis += dataPointInterval; } while (histEndMillis >= intervalStartMillis + dataPointInterval) { - statusHours += (int) ((intervalStartMillis + dataPointInterval + uptimeHours += (int) ((intervalStartMillis + dataPointInterval - Math.max(hist.getStartMillis(), intervalStartMillis)) / DateTimeHelper.ONE_HOUR); - statusDataPoints.add(statusHours * 5 > dataPointIntervalHours - ? statusHours : -1); - statusHours = 0; + uptimeDataPoints.add(uptimeHours); + uptimeHours = 0; intervalStartMillis += dataPointInterval; } - statusHours += (int) ((histEndMillis - Math.max( + uptimeHours += (int) ((histEndMillis - Math.max( hist.getStartMillis(), intervalStartMillis)) / DateTimeHelper.ONE_HOUR); } - statusDataPoints.add(statusHours * 5 > dataPointIntervalHours - ? statusHours : -1); - List<Integer> uptimeDataPoints = new ArrayList<Integer>(); + uptimeDataPoints.add(uptimeHours); + List<Integer> statusDataPoints = new ArrayList<Integer>(); intervalStartMillis = ((this.now - graphInterval) / dataPointInterval) * dataPointInterval; - int uptimeHours = 0; - long firstStatusStartMillis = -1L; - for (UptimeHistory hist : history) { + int statusHours = -1; + for (UptimeHistory hist : knownStatuses) { if (hist.isRelay() != relay) { continue; } - if (firstStatusStartMillis < 0L) { - firstStatusStartMillis = hist.getStartMillis(); - } long histEndMillis = hist.getStartMillis() + DateTimeHelper.ONE_HOUR * hist.getUptimeHours(); if (histEndMillis < intervalStartMillis) { @@ -183,28 +185,35 @@ public class UptimeDocumentWriter implements FingerprintListener, } while (hist.getStartMillis() >= intervalStartMillis + dataPointInterval) { - if (firstStatusStartMillis < intervalStartMillis - + dataPointInterval) { - uptimeDataPoints.add(uptimeHours); - } else { - uptimeDataPoints.add(-1); - } - uptimeHours = 0; + statusDataPoints.add(statusHours * 5 > dataPointIntervalHours + ? statusHours : -1); + statusHours = -1; intervalStartMillis += dataPointInterval; } while (histEndMillis >= intervalStartMillis + dataPointInterval) { - uptimeHours += (int) ((intervalStartMillis + dataPointInterval - - Math.max(hist.getStartMillis(), intervalStartMillis)) + if (statusHours < 0) { + statusHours = 0; + } + statusHours += (int) ((intervalStartMillis + dataPointInterval + - Math.max(Math.max(hist.getStartMillis(), + firstStatusStartMillis), intervalStartMillis)) / DateTimeHelper.ONE_HOUR); - uptimeDataPoints.add(uptimeHours); - uptimeHours = 0; + statusDataPoints.add(statusHours * 5 > dataPointIntervalHours + ? statusHours : -1); + statusHours = -1; intervalStartMillis += dataPointInterval; } - uptimeHours += (int) ((histEndMillis - Math.max( - hist.getStartMillis(), intervalStartMillis)) - / DateTimeHelper.ONE_HOUR); + if (statusHours < 0) { + statusHours = 0; + } + statusHours += (int) ((histEndMillis - Math.max(Math.max( + hist.getStartMillis(), firstStatusStartMillis), + intervalStartMillis)) / DateTimeHelper.ONE_HOUR); + } + if (statusHours > 0) { + statusDataPoints.add(statusHours * 5 > dataPointIntervalHours + ? statusHours : -1); } - uptimeDataPoints.add(uptimeHours); List<Double> dataPoints = new ArrayList<Double>(); for (int dataPointIndex = 0; dataPointIndex < statusDataPoints.size(); dataPointIndex++) {
tor-commits@lists.torproject.org