Commit 490017be authored by juga  's avatar juga
Browse files

Use secs-recent instead of data_period

when the arg is provided.
Also, use list when filtering the results and add debugging lines
parent 8f4c5b8a
from math import ceil
from sbws.globals import (fail_hard, SBWS_SCALE_CONSTANT, TORFLOW_SCALING,
SBWS_SCALING, TORFLOW_BW_MARGIN, TORFLOW_ROUND_DIG,
DAY_SECS, NUM_MIN_RESULTS)
......@@ -79,8 +81,10 @@ def main(args, conf):
scaling_method = None
else:
scaling_method = TORFLOW_SCALING
fresh_days = conf.getint('general', 'data_period')
if args.secs_recent:
fresh_days = ceil(args.secs_recent / 24 / 60 / 60)
else:
fresh_days = conf.getint('general', 'data_period')
reset_bw_ipv4_changes = conf.getboolean('general', 'reset_bw_ipv4_changes')
reset_bw_ipv6_changes = conf.getboolean('general', 'reset_bw_ipv6_changes')
results = load_recent_results_in_datadir(
......
......@@ -286,10 +286,7 @@ class V3BWLine(object):
return None
results_recent = cls.results_recent_than(results_away, secs_recent)
if not results_recent:
log.debug("There are no results that are more recent than {}"
" secs".format(secs_recent))
return None
# the most recent should be the last
kwargs['desc_avg_bw_bs'] = \
results_recent[-1].relay_average_bandwidth
kwargs['rtt'] = cls.rtt_from_results(results_recent)
......@@ -348,10 +345,14 @@ class V3BWLine(object):
def results_recent_than(results, secs_recent=None):
if secs_recent is None:
return results
results_recent = filter(
results_recent = list(filter(
lambda x: (now_unixts() - x.time) < secs_recent,
results)
return list(results_recent)
results))
# if not results_recent:
# log.debug("Results are NOT more recent than %ss: %s",
# secs_recent,
# [unixts_to_isodt_str(r.time) for r in results])
return results_recent
@staticmethod
def bw_bs_median_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