GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

scaling.py 585 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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``.
    """
17 18 19 20 21 22 23
    mu = 1
    if bw_measurements:
        mu = mean(bw_measurements)
    bws_gte_mean = list(filter(lambda bw: bw >= mu, bw_measurements))
    if bws_gte_mean:
        return mean(bws_gte_mean)
    return 1