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

[tor-commits] [ooni-probe/master] Prevent divide by zero bug



commit 442a51799ca892e4dcacd410be386418a754531b
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sun Jan 13 20:18:34 2013 +0100

    Prevent divide by zero bug
---
 ooni/director.py |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/ooni/director.py b/ooni/director.py
index beb9c3a..1ef5aab 100644
--- a/ooni/director.py
+++ b/ooni/director.py
@@ -70,10 +70,16 @@ class Director(object):
 
     @property
     def measurementSuccessRatio(self):
+        if self.totalMeasurements == 0:
+            return 0
+
         return self.successfulMeasurements / self.totalMeasurements
 
     @property
     def measurementFailureRatio(self):
+        if self.totalMeasurements == 0:
+            return 0
+
         return self.failedMeasurements / self.totalMeasurements
 
     @property
@@ -84,6 +90,9 @@ class Director(object):
         This means that fast tests that perform a lot of measurements will
         impact this value quite heavily.
         """
+        if self.totalMeasurementRuntime == 0:
+            return 0
+
         return self.successfulMeasurements / self.totalMeasurementRuntime
 
     @property
@@ -91,6 +100,9 @@ class Director(object):
         """
         The speed at which tests are failing globally.
         """
+        if self.totalMeasurementRuntime == 0:
+            return 0
+
         return self.failedMeasurements / self.totalMeasurementRuntime
 
     def measurementTimedOut(self, measurement):



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