Ticket #6329: stats.py

File stats.py, 662 bytes (added by lunar, 7 years ago)

PoC to get percentages of consensus weight of running relays by country

Line 
1import json
2
3data = json.load(file('/tmp/details.json'))
4running_relays = []
5for relay in data['relays']:
6    if 'Running' in relay['flags']:
7        running_relays.append(relay)
8
9total_consensus_weight = 0
10for relay in running_relays:
11    if not 'Running' in relay['flags']:
12        continue
13    total_consensus_weight += relay['consensus_weight']
14
15countries = {}
16for relay in running_relays:
17    country = relay['country']
18    if country not in countries:
19      countries[country] = 0
20    countries[country] += relay['consensus_weight']
21
22for country, weight in countries.iteritems():
23    print "%3.2f%% %s" % (weight * 100.0 / total_consensus_weight, country)