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

[tor-commits] [sbws/master] Stop calculating median on empty list



commit fd74a4c4832847b6d77fc0a87788316fa894ffbf
Author: juga0 <juga@xxxxxxxxxx>
Date:   Fri Jul 6 19:49:37 2018 +0000

    Stop calculating median on empty list
---
 sbws/lib/v3bwfile.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 1d7ec61..c1dc890 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -320,13 +320,13 @@ class V3BWLine(object):
         # Note how this isn't some measured-by-us average of bandwidth. It's
         # the first value on the 'bandwidth' line in the relay's server
         # descriptor.
-        relay_average_bw = median([
-            r.relay_average_bandwidth for r in results
-            if r.relay_average_bandwidth is not None])
-        if median_bw > relay_average_bw:
-            bw = relay_average_bw
-        else:
-            bw = median_bw
+        bw = median_bw
+        relay_average_bw = [r.relay_average_bandwidth for r in results
+                            if r.relay_average_bandwidth is not None]
+        if relay_average_bw:
+            median_relay_average_bw = median(relay_average_bw)
+            if median_bw > median_relay_average_bw:
+                bw = median_relay_average_bw
         # convert to KB and ensure it's at least 1
         bw_kb = max(round(bw / 1024), 1)
         return bw_kb



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