commit 5159662a50b6ae97588e87423d6c56a9014ff91f Author: juga0 <j...@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) _______________________________________________ tor-commits mailing list tor-commits@lists.torproject.org https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits