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
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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):
        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]]))