-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_confirmed.py
58 lines (47 loc) · 1.54 KB
/
process_confirmed.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 csv
import json
import math
LOG_DEVIATION = 0.45 # valid on 0<n<1: 0 => log(x), 1 => xlog(x)
LIN_SCALING = 0.00025
def scale(cases):
if cases < 0: # domain{log(x+1)}
cases = 0
z = ((cases**LOG_DEVIATION)*(math.log(cases+1)))
return (z * LIN_SCALING)
csvfile_confirmed_global = open('time_series_covid19_confirmed_global.csv', 'r')
csvfile_confirmed_US = open('time_series_covid19_confirmed_US.csv', 'r')
jsonfile = open('globe/covid19_confirmed.json', 'w')
jsonfile.write('[\n')
# write global confirmed cases data to json
jsonfile.write(' [\n \"Confirmed\", [')
reader = csv.DictReader(csvfile_confirmed_global)
rows = []
for row in reader:
if row.get('Country/Region') == 'US':
continue # omit US (added separately)
cases = float(row.get(next(reversed(row))))
coords = [row.get('Lat'), row.get('Long')]
if coords == ['', '']:
coords = ['0', '0']
s = coords[0] + ', ' + coords[1] + ', ' + str(scale(cases))
rows.append(s)
t = ', '.join(rows)
jsonfile.write(t)
jsonfile.write(', ')
# write US confirmed cases data to json
reader = csv.DictReader(csvfile_confirmed_US)
rows = []
for row in reader:
cases = float(row.get(next(reversed(row))))
coords = [row.get('Lat'), row.get('Long_')]
if coords == ['', '']:
coords = ['0', '0']
s = coords[0] + ', ' + coords[1] + ', ' + str(scale(cases))
rows.append(s)
t = ', '.join(rows)
jsonfile.write(t)
jsonfile.write(']\n ]\n')
jsonfile.write(']')
csvfile_confirmed_global.close()
csvfile_confirmed_US.close()
jsonfile.close()