-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo_breakdown.py
executable file
·49 lines (40 loc) · 1.7 KB
/
geo_breakdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import copy
import csv
import iso
for mode in ('pi',):
# build base dictionary of states
base_states = dict(zip(iso.iso_state.keys(), [0] * len(iso.iso_state.keys())))
base_states[''] = 0
# build base dictionary of countries
base_countries = dict()
for record in csv.DictReader(open('projects_' + mode + '.csv')):
base_countries[record.get('iso_country', '')] = 0
state_list = sorted(base_states.keys())
country_list = sorted(base_countries.keys())
# build containers for each telescope
telescopes = ('GBT', 'VLA', 'VLBA', '', 'all',)
states = dict()
countries = dict()
for tel in telescopes:
states[tel] = copy.deepcopy(base_states)
countries[tel] = copy.deepcopy(base_countries)
# Collect data
for record in csv.DictReader(open('projects_' + mode + '.csv')):
state = record.get('iso_state', '')
country = record.get('iso_country', '')
tel = record.get('tel', '')
quarter = (float(record['hours']))
if country == 'US':
states[tel][state] = states[tel].get(state, 0) + quarter
states['all'][state] = states['all'].get(state, 0) + quarter
countries[tel][country] = countries[tel].get(country, 0) + quarter
countries['all'][country] = countries['all'].get(country, 0) + quarter
# write data to file
country_file = open('projects_countries_' + mode + '.csv', 'w')
country_file.write('tel,iso_country,q4\n')
country_writer = csv.writer(country_file)
for tel in telescopes:
for country in country_list:
country_writer.writerow([tel, country,
'%.02f' % countries[tel][country]])