Commit 0bc03df5 authored by juga  's avatar juga
Browse files

new: v3bwfile: Include consensus count header

The total number of consensuses seen in the last days.

Part of #28566.
parent 6047da5c
......@@ -229,7 +229,9 @@ class V3BWHeader(object):
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 @@ class V3BWHeader(object):
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 @@ class V3BWHeader(object):
return None
def consensus_count_from_file(state_fpath):
state = State(state_fpath)
if 'consensus_count' in state:
return state['consensus_count']
return None
def latest_bandwidth_from_results(results):
return round(max([r.time for fp in results for r in results[fp]]))
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