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.

Commit 2924e440 authored by juga  's avatar juga 💬

fix: v3bwfile: Avoid statistics without data

If mean or median argument is empty, they throw an exception.
This can happen when the scanner has stopped and the result is
stored as successful without any downloads.

Closes: #40012
parent 1adce87c
Pipeline #899 failed with stage
in 36 minutes and 56 seconds
......@@ -14,6 +14,10 @@ def bw_filt(bw_measurements):
It is the equivalent to Torflow's ``filt_sbw``.
``mu`` in this function is the equivalent to Torflow's ``sbw``.
"""
mu = 1
if bw_measurements:
mu = mean(bw_measurements)
bws_gte_mean = filter(lambda bw: bw >= mu, bw_measurements)
bws_gte_mean = list(filter(lambda bw: bw >= mu, bw_measurements))
if bws_gte_mean:
return mean(bws_gte_mean)
return 1
......@@ -869,13 +869,19 @@ class V3BWLine(object):
@staticmethod
def bw_median_from_results(results):
return max(round(median([dl['amount'] / dl['duration']
for r in results for dl in r.downloads])), 1)
bws = [dl['amount'] / dl['duration']
for r in results for dl in r.downloads]
if bws:
return max(round(median(bws)), 1)
return 1
@staticmethod
def bw_mean_from_results(results):
return max(round(mean([dl['amount'] / dl['duration']
for r in results for dl in r.downloads])), 1)
bws = [dl['amount'] / dl['duration']
for r in results for dl in r.downloads]
if bws:
return max(round(mean(bws)), 1)
return 1
@staticmethod
def last_time_from_results(results):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment