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

[tor-commits] [onionoo/master] Don't compress weights values with missing values.



commit 78a7a626aa135d9cd7414e7610b4713a67b83266
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Sun Jun 15 10:37:30 2014 +0200

    Don't compress weights values with missing values.
    
    When compressing weights status lines, we simply combined adjacent
    intervals by calculating arithmetic means.  But we did not consider
    missing values, which were encoded as 0.0.  As a result the result was
    lower than it should really have been.  Now that missing values are
    encoded as -1.0, it becomes even more apparent that this approach was
    wrong with negative weights values of, e.g., -0.127320915201.  As a fix,
    avoid compressing intervals with missing values for certain weights.
    
    Example of an old combined line:
    
    2008-08-20 20:00:00 2008-08-29 00:00:00 0.000261225507 -0.127320915201
      -1.000000000000 -1.000000000000 -1.000000000000 76374.857142857120
      65.306122448979
    
    The -0.127320915201 part is wrong there.
    
    Example of the same data, not combined:
    
    2008-08-20 20:00:00 2008-08-21 21:00:00 0.000245451671 -1.000000000000
      -1.000000000000 -1.000000000000 -1.000000000000 73466.880000000000
      -1.000000000000
    2008-08-21 21:00:00 2008-08-29 00:00:00 0.000263531623 0.000263746320
      -1.000000000000 -1.000000000000 -1.000000000000 76800.000000000000
      75.000000000000
    
    Found in the context of implementing #11388.
---
 src/org/torproject/onionoo/WeightsStatusUpdater.java |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/org/torproject/onionoo/WeightsStatusUpdater.java b/src/org/torproject/onionoo/WeightsStatusUpdater.java
index 24c98ff..5932da6 100644
--- a/src/org/torproject/onionoo/WeightsStatusUpdater.java
+++ b/src/org/torproject/onionoo/WeightsStatusUpdater.java
@@ -257,6 +257,7 @@ public class WeightsStatusUpdater implements DescriptorListener,
     long lastStartMillis = 0L, lastEndMillis = 0L;
     double[] lastWeights = null;
     String lastMonthString = "1970-01";
+    int lastMissingValues = -1;
     for (Map.Entry<long[], double[]> e : history.entrySet()) {
       long startMillis = e.getKey()[0], endMillis = e.getKey()[1];
       double[] weights = e.getValue();
@@ -277,10 +278,17 @@ public class WeightsStatusUpdater implements DescriptorListener,
       }
       String monthString = DateTimeHelper.format(startMillis,
           DateTimeHelper.ISO_YEARMONTH_FORMAT);
+      int missingValues = 0;
+      for (int i = 0; i < weights.length; i++) {
+        if (weights[i] < -0.5) {
+          missingValues += 1 << i;
+        }
+      }
       if (lastEndMillis == startMillis &&
           ((lastEndMillis - 1L) / intervalLengthMillis) ==
           ((endMillis - 1L) / intervalLengthMillis) &&
-          lastMonthString.equals(monthString)) {
+          lastMonthString.equals(monthString) &&
+          lastMissingValues == missingValues) {
         double lastIntervalInHours = (double) ((lastEndMillis
             - lastStartMillis) / DateTimeHelper.ONE_HOUR);
         double currentIntervalInHours = (double) ((endMillis
@@ -303,6 +311,7 @@ public class WeightsStatusUpdater implements DescriptorListener,
         lastWeights = weights;
       }
       lastMonthString = monthString;
+      lastMissingValues = missingValues;
     }
     if (lastStartMillis > 0L) {
       compressedHistory.put(new long[] { lastStartMillis, lastEndMillis },

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