-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
318 lines (261 loc) · 10.4 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_gif_component as gif
import plotly.express as px
import plotly.graph_objects as go
import gunicorn
app = dash.Dash(__name__)
server = app.server
ind_with_avg_calls = pd.read_csv('indicators_with_avg.csv')
noncompliance = pd.read_csv('noncompliance.csv')
mgc = pd.read_csv('mgc.csv')
noise_r = pd.read_csv('noiser.csv')
noise_v = pd.read_csv('noisev.csv')
noise_c = pd.read_csv('noisec.csv')
noise_s = pd.read_csv('noises.csv')
street = pd.read_csv('street.csv')
sidewalk = pd.read_csv('sidewalk.csv')
dt = pd.read_csv('dt.csv')
ot = pd.read_csv('ot.csv')
nt = pd.read_csv('nt.csv')
dd = pd.read_csv('dd.csv')
complaint_type_count_df = pd.read_csv('complaint_type_count.csv')
agency_count_df = pd.read_csv('agency_count.csv')
complaint_type_fig = px.bar(complaint_type_count_df, x="Total Calls", y="Complaint Type",
orientation='h',
height=700, color="Total Calls",
color_discrete_sequence=px.colors.sequential.thermal)
complaint_type_fig.update_layout(hovermode='x',
title="Top 30 Most Frequent 311 Complaint Types",
font=dict(family="silom",
size=14, color="#58508d"))
agency_fig = px.bar(agency_count_df, x="Total Calls", y="Agency",
orientation='h',
height=700, color="Total Calls",
color_discrete_sequence=px.colors.sequential.thermal)
agency_fig.update_layout(hovermode='x',
title="311 Call Counts by Agency",
font=dict(family="silom",
size=14, color="#58508d"))
fig2 = px.scatter(ind_with_avg_calls, x="community_board",
y="Avg daily calls per sqmi", color="Borough", height=700,
size='crime_per_1000', size_max=90, color_discrete_sequence=[
"lightsalmon", "lightseagreen",
"lightskyblue", "lightpink",
"lightslategray"])
fig2.update_layout(hovermode='x',
title="Average Daily 311 Calls/Sq Mile",
xaxis_title="Community Board",
font=dict(family="silom",
size=14, color="#58508d",
))
fig2.update_layout(legend=dict(
yanchor="top",
y=0.99,
xanchor="right",
x=0.99
))
fig3 = go.Figure()
fig3.add_trace(go.Scatter(
x=noise_r.Date, y=noise_r['Noise - Residential'],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#003f5c'), name="Noise - Residential",
stackgroup='one'
))
fig3.add_trace(go.Scatter(
x=noise_s.Date, y=noise_s['Noise - Street/Sidewalk'],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#58508d'), name='Noise - Street/Sidewalk',
stackgroup='two'
))
fig3.add_trace(go.Scatter(
x=noise_v.Date, y=noise_v['Noise - Vehicle'],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#bc5090'), name='Noise - Vehicle',
stackgroup='three'
))
fig3.add_trace(go.Scatter(
x=noise_c.Date, y=noise_c['Noise - Commercial'],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#ffa600'), name='Noise - Commercial',
stackgroup='four'
))
fig3.update_layout(legend=dict(
yanchor="top",
y=0.99,
xanchor="right",
x=0.99
))
fig3.update_layout(title="Noise",
xaxis_title="Date",
yaxis_title="Total Calls",
height=700,
font=dict(family="silom",
size=14, color="#58508d"))
fig4 = go.Figure()
fig4.add_trace(go.Scatter(
x=noncompliance.Date, y=noncompliance['Noncompliance With Phased Reopening'],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#FF0000'), name="Noncompliance W/ Phased Reopening",
stackgroup='one'
))
fig4.add_trace(go.Scatter(
x=mgc.Date, y=mgc['Mass Gathering Complaint'],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#000000'), name="Mass Gathering Complaint",
stackgroup='two'
))
fig4.update_layout(legend=dict(
yanchor="top",
y=0.99,
xanchor="right",
x=0.99
))
fig4.update_layout(title="COVID-19",
xaxis_title="Date",
yaxis_title="Total Calls",
height=700,
font=dict(family="silom",
size=14, color="#58508d"))
condition_fig = go.Figure()
condition_fig.add_trace(go.Scatter(
x=street.Date, y=street["Street Condition"],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#22DDD3'), name="Street Condition",
stackgroup='one'
))
condition_fig.add_trace(go.Scatter(
x=sidewalk.Date, y=sidewalk["Sidewalk Condition"],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#6722DD'), name="Sidewalk Condition",
stackgroup='one'
))
condition_fig.update_layout(legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.01
))
condition_fig.update_layout(title="Sidewalk and Street Condition", height=700,
xaxis_title="Date",
yaxis_title="Total Calls",
font=dict(family="silom",
size=14, color="#58508d"))
damaged_tree_fig = go.Figure()
damaged_tree_fig.add_trace(go.Scatter(
x=dt.Date, y=dt["Damaged Tree"],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#228B22'), name="Damaged Trees",
stackgroup='one'
))
damaged_tree_fig.update_layout(title="Damaged Trees", height=700,
xaxis_title="Date",
yaxis_title="Total Calls",
font=dict(family="silom",
size=14, color="#58508d"))
tree_fig = go.Figure()
tree_fig.add_trace(go.Scatter(
x=ot.Date, y=ot["Overgrown Tree/Branches"],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#8B4513'), name="Overgrown Tree/Branches",
stackgroup='two'
))
tree_fig.add_trace(go.Scatter(
x=dd.Date, y=dd["Dead/Dying Tree"],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#C4285F'), name="Dead/Dying Tree",
stackgroup='three'
))
tree_fig.add_trace(go.Scatter(
x=nt.Date, y=nt["New Tree Request"],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5, color='#491BE5'), name="New Tree Request",
stackgroup='four'
))
tree_fig.update_layout(legend=dict(
yanchor="top",
y=0.99,
xanchor="right",
x=0.99
))
tree_fig.update_layout(title="Other Tree-Related Requests", height=700,
xaxis_title="Date",
yaxis_title="Total Calls",
font=dict(family="silom",
size=14, color="#58508d"))
app.layout = html.Div(className='row', children=[
html.H1('NYC 311 Data Explorer (June-November 2020)',
style={'color': '#6b508f', 'fontSize': 50, 'text-align': 'center', 'font-family':'silom'}),
html.H1('About this Dashboard',
style={'color': '#113c3c', 'fontSize': 30, 'text-align': 'left', 'margin-left': 100}),
dcc.Markdown('''
This dashboard hosts interactive plots of recent data obtained from two public sources:
* [NYC OpenData 311 Service Requests from 2010 to Present](https://data.cityofnewyork.us/Social-Services/311-Service-Requests-from-2010-to-Present/erm2-nwe9)
* [NYC Department of City Planning’s Community District Profiles](https://communityprofiles.planning.nyc.gov/)
The 311 data displayed here is limited to calls that were made between June and November 2020.
The community district data consists of information from various sources and collectiod periods.
The code for this dashboard and an analysis of the data can be found in this [GitHub repo](https://github.com/AvonleaFisher/Analyzing-NYC-311-Service-Requests).
''', style={'margin-left': 100, 'margin-right': 150, 'fontSize': 27}),
html.H1('Daily Call Volume by Month',
style={'color': '#113c3c', 'fontSize': 30, 'text-align': 'left', 'margin-left': 100}),
html.Div(
gif.GifPlayer(gif='assets/June.gif', still='assets/June.gif', autoplay=True),
style={'marginLeft': 130, 'width': '31%', 'display': 'inline-block'}
),
html.Div(
gif.GifPlayer(gif='assets/July.gif', still='assets/July.gif', autoplay=True),
style={'width': '31%', 'display': 'inline-block'}
),
html.Div(
gif.GifPlayer(gif='assets/august.gif', still='assets/august.gif', autoplay=True),
style={'width': '31%', 'display': 'inline-block'}
),
html.Div(
gif.GifPlayer(gif='assets/September.gif', still='assets/September.gif', autoplay=True),
style={'marginLeft': 130, 'width': '31%', 'display': 'inline-block'}
),
html.Div(
gif.GifPlayer(gif='assets/October.gif', still='assets/October.gif', autoplay=True),
style={'width': '31%', 'display': 'inline-block'}
),
html.Div(
gif.GifPlayer(gif='assets/November.gif', still='assets/November.gif', autoplay=True),
style={'width': '31%', 'display': 'inline-block'}
),
html.H1('Total Call Counts by Agency and Complaint Type',
style={'color': '#113c3c', 'fontSize': 30, 'text-align': 'left', 'margin-left': 100}),
html.Div(children=[
dcc.Graph(id="graph0", figure=agency_fig),
dcc.Graph(id="graph1", figure=complaint_type_fig),
]),
html.H1('Daily Average Call Counts by Community Board (per sqmi)',
style={'color': '#113c3c', 'fontSize': 30, 'text-align': 'left', 'margin-left': 100}),
html.Div(children=[
dcc.Graph(id="graph2", figure=fig2),
html.H1('Daily Total Calls by Complaint Type',
style={'color': '#113c3c', 'fontSize': 30, 'text-align': 'left', 'margin-left': 100}),
]),
html.Div(children=[
dcc.Graph(id="graph3", figure=fig3),
dcc.Graph(id="graph4", figure=fig4),
dcc.Graph(id="graph5", figure=condition_fig),
dcc.Graph(id="graph6", figure=damaged_tree_fig),
dcc.Graph(id="graph7", figure=tree_fig)
])
])
if __name__ == '__main__':
app.run_server(debug=True)