Skip to content
This repository was archived by the owner on May 4, 2021. It is now read-only.

Commit d775f42

Browse files
committed
new: v3bwfile: Include consensus count header
The total number of consensuses seen in the last days. Part of #28566.
1 parent 26daa7f commit d775f42

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

sbws/lib/v3bwfile.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ def from_results(cls, results, scanner_country=None,
229229
kwargs = dict()
230230
latest_bandwidth = cls.latest_bandwidth_from_results(results)
231231
earliest_bandwidth = cls.earliest_bandwidth_from_results(results)
232+
# NOTE: Blocking, reads file
232233
generator_started = cls.generator_started_from_file(state_fpath)
234+
consensus_count = cls.consensus_count_from_file(state_fpath)
233235
timestamp = str(latest_bandwidth)
234236
kwargs['latest_bandwidth'] = unixts_to_isodt_str(latest_bandwidth)
235237
kwargs['earliest_bandwidth'] = unixts_to_isodt_str(earliest_bandwidth)
@@ -240,6 +242,8 @@ def from_results(cls, results, scanner_country=None,
240242
kwargs['scanner_country'] = scanner_country
241243
if destinations_countries is not None:
242244
kwargs['destinations_countries'] = destinations_countries
245+
if consensus_count is not None:
246+
kwargs['recent_consensus_count'] = str(consensus_count)
243247
h = cls(timestamp, **kwargs)
244248
return h
245249

@@ -296,6 +300,14 @@ def generator_started_from_file(state_fpath):
296300
else:
297301
return None
298302

303+
@staticmethod
304+
def consensus_count_from_file(state_fpath):
305+
state = State(state_fpath)
306+
if 'consensus_count' in state:
307+
return state['consensus_count']
308+
else:
309+
return None
310+
299311
@staticmethod
300312
def latest_bandwidth_from_results(results):
301313
return round(max([r.time for fp in results for r in results[fp]]))

0 commit comments

Comments
 (0)