commit f3f0d49e7164072dd3d94dd3e81abde7aed5326c Author: juga0 juga@riseup.net Date: Fri Nov 23 09:46:50 2018 +0000
v3bwfile: refactor, get desc_bw_avg from method
This way it can be obtained in a different way (for instance, the mean, not the last) and it also avoids not obtaining any value in case the last is None. --- sbws/lib/v3bwfile.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py index a050744..657e1e3 100644 --- a/sbws/lib/v3bwfile.py +++ b/sbws/lib/v3bwfile.py @@ -327,8 +327,6 @@ class V3BWLine(object): if not len(results_recent) >= min_num: # log.debug('The number of results is less than %s', min_num) return None - kwargs['desc_bw_avg'] = \ - results_recent[-1].relay_average_bandwidth rtt = cls.rtt_from_results(results_recent) if rtt: kwargs['rtt'] = rtt @@ -336,6 +334,8 @@ class V3BWLine(object): kwargs['bw_mean'] = cls.bw_mean_from_results(results_recent) kwargs['bw_median'] = cls.bw_median_from_results( results_recent) + kwargs['desc_bw_avg'] = \ + cls.desc_bw_avg_from_results(results_recent) kwargs['desc_bw_obs_last'] = \ cls.desc_bw_obs_last_from_results(results_recent) kwargs['desc_bw_obs_mean'] = \ @@ -420,6 +420,14 @@ class V3BWLine(object): return rt_dict
@staticmethod + def desc_bw_avg_from_results(results): + """Obtain the last descriptor bandwidth average from the results.""" + for r in reversed(results): + if r.relay_average_bandwidth is not None: + return r.relay_average_bandwidth + return None + + @staticmethod def desc_bw_obs_mean_from_results(results): desc_bw_obs_ls = [] for r in results: