[tor-commits] [sbws/master] Use secs-recent instead of data_period

pastly at torproject.org pastly at torproject.org
Mon Oct 22 13:44:07 UTC 2018


commit 490017be388552f3851628762a6c4d81d7082be2
Author: juga0 <juga at riseup.net>
Date:   Thu Oct 18 11:44:02 2018 +0000

    Use secs-recent instead of data_period
    
    when the arg is provided.
    Also, use list when filtering the results and add debugging lines
---
 sbws/core/generate.py |  8 ++++++--
 sbws/lib/v3bwfile.py  | 13 +++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/sbws/core/generate.py b/sbws/core/generate.py
index 6a6226b..4965066 100644
--- a/sbws/core/generate.py
+++ b/sbws/core/generate.py
@@ -1,3 +1,5 @@
+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(
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 4eecda6..4861af4 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -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):





More information about the tor-commits mailing list