-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.py
executable file
·65 lines (51 loc) · 1.92 KB
/
map.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
59
60
61
62
63
64
65
#!/usr/bin/env python
import json
import datetime
import gripql
import plotly.express as px
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
conn = gripql.Connection("http://localhost:8201")
G = conn.graph("covid")
q = G.query().V().hasLabel("SummaryLocation").has(gripql.eq("province_state", "OR")).as_("a")
q = q.out("summary_reports").as_("b").render(["$a._gid", "$b._data"])
res = list(q)
data = {}
for k, v in res:
if k not in data:
data[k] = {}
date_time_str = v['date']
try:
d = datetime.datetime.strptime(date_time_str, "%Y-%m-%d %H:%M:%S")
except ValueError:
try:
d = datetime.datetime.strptime(date_time_str, "%Y-%m-%d %H:%M")
except ValueError:
d = datetime.datetime.strptime(date_time_str, "%m/%d/%y %H:%M")
data[k][d] = ( v['confirmed'], v['deaths'], v['recovered'] )
mapData = {}
for i in data:
m = max(data[i].keys())
mapData[i] = {"fips" : i, "deaths" : data[i][m][0]}
mapDF = pd.DataFrame(mapData).transpose()
with open("geojson-counties-fips.json") as handle:
counties = json.loads(handle.read())
countiesSub = {"type" : "FeatureCollection", "features":[]}
for c in counties['features']:
if c['properties']['STATE'] == "41":
countiesSub['features'].append(c)
fig = px.choropleth_mapbox(mapDF, geojson=countiesSub, locations='fips', color='deaths',
color_continuous_scale="Viridis",
range_color=(0, 12),
mapbox_style="carto-positron",
zoom=6, center = {"lat": 44.15, "lon": -120.490556},
opacity=0.5,
labels={'unemp':'unemployment rate'}
)
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run_server(debug=True, use_reloader=False) # Turn off reloader if inside Jupyter