[tor-commits] [sbws/master] Return bw in kb if not scaled

juga at torproject.org juga at torproject.org
Tue Sep 18 09:26:11 UTC 2018


commit 32b2014a248bf87ab1344c3aaeaf4b8c059347e5
Author: juga0 <juga at riseup.net>
Date:   Wed Aug 29 19:16:31 2018 +0000

    Return bw in kb if not scaled
---
 sbws/lib/v3bwfile.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index eff87f8..bd8f5d6 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -359,14 +359,23 @@ class V3BWFile(object):
                      scale_constant=None):
         bw_lines = [V3BWLine.from_results(results[fp]) for fp in results]
         bw_lines = sorted(bw_lines, key=lambda d: d.bw, reverse=True)
-        if scale_constant:
+        if scale_constant is not None:
             bw_lines = cls.bw_sbws_scale(bw_lines, scale_constant)
             cls.warn_if_not_accurate_enough(bw_lines, scale_constant)
+        else:
+            bw_lines = cls.bw_kb(bw_lines)
         header = V3BWHeader.from_results(results, state_fpath)
         f = cls(header, bw_lines)
         return f
 
     @staticmethod
+    def bw_kb(bw_lines, reverse=False):
+        bw_lines_scaled = copy.deepcopy(bw_lines)
+        for l in bw_lines_scaled:
+            l.bw = max(round(l.bw / 1000), 1)
+        return sorted(bw_lines_scaled, key=lambda x: x.bw, reverse=reverse)
+
+    @staticmethod
     def bw_sbws_scale(bw_lines, scale_constant=SCALE_CONSTANT,
                       reverse=False):
         """Return a new V3BwLine list scaled using sbws method.





More information about the tor-commits mailing list