-
Notifications
You must be signed in to change notification settings - Fork 1
/
modelmap.py
83 lines (65 loc) · 2.55 KB
/
modelmap.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pandas as pd
import json
import gripql
import datetime
import dash_core_components as dcc
import dash_html_components as html
from app import app
import dash
import plotly.express as px
import plotly.graph_objects as go
# https://towardsdatascience.com/build-an-interactive-choropleth-map-with-plotly-and-dash-1de0de00dce0
conn = gripql.Connection("http://localhost:8201")
G = conn.graph("covid")
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)
curDate = "2020-04-14 23:33:31"
q = G.query().V().hasLabel("SummaryLocation").has(gripql.eq("province_state", "OR")).as_("a")
q = q.out("summary_reports").has(gripql.eq("date", curDate)).as_("b")
q = q.render(["$a._gid", "$b.confirmed", "$b.deaths", "$b.recovered"])
mapData = {}
for i in q:
mapData[i[0]] = {"fips" : i[0], "confirmed" : i[1], "deaths" : i[2], "recovered" : i[3]}
mapDF = pd.DataFrame(mapData).transpose()
fig = px.choropleth_mapbox(mapDF, geojson=countiesSub, locations='fips', color='confirmed',
color_continuous_scale="Viridis",
range_color=(0, 12),
mapbox_style="carto-positron",
zoom=6, center = {"lat": 44.15, "lon": -120.490556},
opacity=0.5
)
q = G.query().V().hasLabel("SummaryLocation").has(gripql.eq("province_state", "OR"))
q = q.render(["$._gid", "$.county"])
countyOptions = list( { "label" : a[1], "value" : a[0] } for a in q )
countyDropDown = dcc.Dropdown(
id='county-dropdown',
options=countyOptions,
value=countyOptions[0]['value']
)
historyGraph = dcc.Graph(id='history-graph')
@app.callback(
dash.dependencies.Output('history-graph', 'figure'),
[dash.dependencies.Input('county-dropdown', 'value')])
def update_county_history(value):
q = G.query().V(value).out("summary_reports")
q = q.render(["$.date", "$.confirmed", "$.deaths", "$.recovered"])
data = {}
for row in q:
d = datetime.datetime.strptime(row[0], "%Y-%m-%d %H:%M:%S")
data[d] = { "confirmed" : row[1], "deaths" : row[2], "recovered" : row[3] }
dates = sorted(data.keys())
return {
"data" : [{
"x" : dates,
"y" : list( data[d]["confirmed"] for d in dates )
}]
}
ModelMap = html.Div([
#dcc.Graph(figure=fig),
countyDropDown,
historyGraph
])