From d775f42e72567297ec2c5d5e4028c30059fcc8a1 Mon Sep 17 00:00:00 2001 From: juga0 Date: Fri, 15 Feb 2019 16:54:10 +0000 Subject: [PATCH] new: v3bwfile: Include consensus count header The total number of consensuses seen in the last days. Part of #28566. --- sbws/lib/v3bwfile.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py index d827029b..fa05fbcb 100644 --- a/sbws/lib/v3bwfile.py +++ b/sbws/lib/v3bwfile.py @@ -229,7 +229,9 @@ def from_results(cls, results, scanner_country=None, kwargs = dict() latest_bandwidth = cls.latest_bandwidth_from_results(results) earliest_bandwidth = cls.earliest_bandwidth_from_results(results) + # NOTE: Blocking, reads file generator_started = cls.generator_started_from_file(state_fpath) + consensus_count = cls.consensus_count_from_file(state_fpath) timestamp = str(latest_bandwidth) kwargs['latest_bandwidth'] = unixts_to_isodt_str(latest_bandwidth) kwargs['earliest_bandwidth'] = unixts_to_isodt_str(earliest_bandwidth) @@ -240,6 +242,8 @@ def from_results(cls, results, scanner_country=None, kwargs['scanner_country'] = scanner_country if destinations_countries is not None: kwargs['destinations_countries'] = destinations_countries + if consensus_count is not None: + kwargs['recent_consensus_count'] = str(consensus_count) h = cls(timestamp, **kwargs) return h @@ -296,6 +300,14 @@ def generator_started_from_file(state_fpath): else: return None + @staticmethod + def consensus_count_from_file(state_fpath): + state = State(state_fpath) + if 'consensus_count' in state: + return state['consensus_count'] + else: + return None + @staticmethod def latest_bandwidth_from_results(results): return round(max([r.time for fp in results for r in results[fp]]))