[tor-commits] [sbws/master] chg: scaling: Add filtered bandwidth function

juga at torproject.org juga at torproject.org
Mon Jun 29 07:50:39 UTC 2020


commit 5159662a50b6ae97588e87423d6c56a9014ff91f
Author: juga0 <juga at riseup.net>
Date:   Sat May 16 17:07:19 2020 +0000

    chg: scaling: Add filtered bandwidth function
    
    to calculate the filtered bandwidth for each relay.
---
 sbws/lib/scaling.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/sbws/lib/scaling.py b/sbws/lib/scaling.py
new file mode 100644
index 0000000..0fc3f84
--- /dev/null
+++ b/sbws/lib/scaling.py
@@ -0,0 +1,19 @@
+from statistics import mean
+
+
+def bw_measurements_from_results(results):
+    return [
+        dl['amount'] / dl['duration']
+        for r in results for dl in r.downloads
+    ]
+
+
+def bw_filt(bw_measurements):
+    """Filtered bandwidth for a relay.
+
+    It is the equivalent to Torflow's ``filt_sbw``.
+    ``mu`` in this function is the equivalent to Torflow's ``sbw``.
+    """
+    mu = mean(bw_measurements)
+    bws_gte_mean = filter(lambda bw: bw >= mu, bw_measurements)
+    return mean(bws_gte_mean)





More information about the tor-commits mailing list