-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate_stats.py
58 lines (46 loc) · 1.8 KB
/
generate_stats.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
50
51
52
53
54
55
56
57
58
import json
import pandas as pd
from service.writer import Writer
with open('regions.json') as regions_json:
regions = json.load(regions_json)
output = {}
centre_count = 0
supported_centre_count = 0
dose_count = 0
for region in regions:
region_code = str(
region['code']) if region['code'] > 9 else "0" + str(region['code'])
with open('{}.json'.format(region_code)) as region_json:
appointments = json.load(region_json)
# Number of vaccination centres that have available vaccines
centre_count_by_region = len(appointments['centres_disponibles'])
centre_count += centre_count_by_region
# Number of vaccine doses available
df_appointments = pd.DataFrame.from_dict(
appointments['centres_disponibles'])
if not df_appointments.empty:
dose_count_by_region = df_appointments['appointment_count'].sum()
dose_count += dose_count_by_region
else:
dose_count_by_region = 0
# Number of vaccination centres supported
df_all_centres = df_appointments.append(pd.DataFrame.from_dict(
appointments['centres_indisponibles']),
ignore_index=True)
if not df_all_centres.empty:
supported_centre_count_by_region = (
~df_all_centres['appointment_by_phone_only']).sum()
supported_centre_count += supported_centre_count_by_region
else:
supported_centre_count_by_region = 0
output[region_code] = {
'disponibles': int(centre_count_by_region),
'total': int(supported_centre_count_by_region),
'creneaux': int(dose_count_by_region),
}
output['tout_departement'] = {
'disponibles': int(centre_count),
'total': int(supported_centre_count),
'creneaux': int(dose_count),
}
Writer.write_json(output, 'data/output/stats.json')