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

Commit

Permalink
new: v3bwfile: Include consensus count header
Browse files Browse the repository at this point in the history
The total number of consensuses seen in the last days.

Part of #28566.
  • Loading branch information
juga0 committed Mar 7, 2019
1 parent 26daa7f commit d775f42
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sbws/lib/v3bwfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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]]))
Expand Down

0 comments on commit d775f42

Please sign in to comment.