Commit 0501e202 authored by juga's avatar juga
Browse files

Implement methods to filter results

* to have at least min num results
* to have results that are more recent that x secs
* to have results that are away from each other x secs
parent 54ccf2ce
......@@ -312,6 +312,33 @@ class V3BWLine(object):
bw_line = cls(node_id, bw, **kwargs)
return bw_line
def min_num_results(results, min_num=0):
if len(results) > min_num:
return results
return None
def results_away_each_other(results, secs_away=None):
if secs_away is None or len(results) < 2:
return results
# the last one should be the most recent
results_away = [results[-1]]
# iterate over the rest of the results in reverse order
for r in reversed(results[:-1]):
if abs(results_away[0].time - r.time) > secs_away:
results_away.insert(0, r)
return results_away
def results_recent_than(results, secs_recent=None):
if secs_recent is None:
return results
results_recent = filter(
lambda x: (now_unixts() - x.time) < secs_recent,
return list(results_recent)
def bw_bs_median_from_results(results):
return max(round(median([dl['amount'] / dl['duration']
Supports Markdown
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