Commit f3f0d49e authored by juga  's avatar juga
Browse files

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.
parent dca252ae
...@@ -327,8 +327,6 @@ class V3BWLine(object): ...@@ -327,8 +327,6 @@ class V3BWLine(object):
if not len(results_recent) >= min_num: if not len(results_recent) >= min_num:
# log.debug('The number of results is less than %s', min_num) # log.debug('The number of results is less than %s', min_num)
return None return None
kwargs['desc_bw_avg'] = \
results_recent[-1].relay_average_bandwidth
rtt = cls.rtt_from_results(results_recent) rtt = cls.rtt_from_results(results_recent)
if rtt: if rtt:
kwargs['rtt'] = rtt kwargs['rtt'] = rtt
...@@ -336,6 +334,8 @@ class V3BWLine(object): ...@@ -336,6 +334,8 @@ class V3BWLine(object):
kwargs['bw_mean'] = cls.bw_mean_from_results(results_recent) kwargs['bw_mean'] = cls.bw_mean_from_results(results_recent)
kwargs['bw_median'] = cls.bw_median_from_results( kwargs['bw_median'] = cls.bw_median_from_results(
results_recent) results_recent)
kwargs['desc_bw_avg'] = \
cls.desc_bw_avg_from_results(results_recent)
kwargs['desc_bw_obs_last'] = \ kwargs['desc_bw_obs_last'] = \
cls.desc_bw_obs_last_from_results(results_recent) cls.desc_bw_obs_last_from_results(results_recent)
kwargs['desc_bw_obs_mean'] = \ kwargs['desc_bw_obs_mean'] = \
...@@ -419,6 +419,14 @@ class V3BWLine(object): ...@@ -419,6 +419,14 @@ class V3BWLine(object):
for rt in _ResultType]) for rt in _ResultType])
return rt_dict 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 @staticmethod
def desc_bw_obs_mean_from_results(results): def desc_bw_obs_mean_from_results(results):
desc_bw_obs_ls = [] desc_bw_obs_ls = []
......
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