[tor-commits] [sbws/master] Add methods to obtain median/last observed bw

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


commit 5a9be7c58f1f583c5bbc36d0585bd7d02bb7f50e
Author: juga0 <juga at riseup.net>
Date:   Thu Aug 30 13:20:20 2018 +0000

    Add methods to obtain median/last observed bw
---
 sbws/lib/v3bwfile.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index cdcbad8..5ce1423 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -317,6 +317,24 @@ class V3BWLine(object):
                         for rt in _ResultType])
         return rt_dict
 
+    @staticmethod
+    def desc_obs_bw_bs_mean_from_results(results):
+        desc_obs_bws = []
+        for r in results:
+            if r.relay_observed_bandwidth is not None:
+                desc_obs_bws.append(r.relay_observed_bandwidth)
+        if desc_obs_bws:
+            return max(round(mean(desc_obs_bws)), 1)
+        return None
+
+    @staticmethod
+    def desc_obs_bw_bs_last_from_results(results):
+        # the last is at the end of the list
+        for r in reversed(results):
+            if r.relay_observed_bandwidth is not None:
+                return r.relay_observed_bandwidth
+        return None
+
     @property
     def bw_keyvalue_tuple_ls(self):
         """Return list of KeyValue Bandwidth Line tuples."""





More information about the tor-commits mailing list