generated from dssg-pt/mini-projecto-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard_components.py
237 lines (192 loc) · 7.15 KB
/
dashboard_components.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
import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import numpy as np
import copy
from functions import get_data_overview, get_data
layout = dict(
autosize=True,
automargin=True,
margin=dict(l=5, r=5, b=20, t=30),
hovermode="closest",
legend=dict(font=dict(size=10), orientation="h")
)
layout_pie = copy.deepcopy(layout)
data = [
dict(
type="pie",
labels=["Telefónico", "Presencial", "Apoio Online/Email"],
values=[61.6, 19.5, 17.7],
name="TIPO DE CONTACTO",
text=[
"TELEFÓNICO",
"PRESENCIAL",
"APOIO ONLINE/EMAIL",
],
hoverinfo="text+percent",
textinfo="label+percent+name",
hole=0.5,
marker=dict(colors=["#b93685", "#42049d", "#f58f47"])
)
]
layout_pie["title"] = "TIPO DE CONTACTO"
layout_pie["font"] = dict(color="#777777")
layout_pie["legend"] = dict(
font=dict(color="#CCCCCC", size="10"), orientation="h", bgcolor="rgba(0,0,0,0)"
)
contact_type_graph = dict(data=data, layout=layout_pie)
crime_loc_values = [65, 12.9, 8.3, 4.6, 2.4, 5] # to be update with values from APAV database
crime_location = [
dict(
type="pie",
labels=["Residência Comum", "Residência Vítima", "Via Pública",
"Residência Autor", "Local de Trabalho", "Outro"],
values=crime_loc_values,
name="LOCAL DO CRIME",
text=[
"Residência Comum",
"Residência Vítima",
"Via Pública",
"Residência Autor",
"Local de Trabalho",
"Outro"
],
hoverinfo="text+percent",
textinfo="label+percent+name",
hole=0.5,
marker=dict(colors=["#b93685", "#42049d", "#f58f47", "#f9d02b", "#7504a7", "#19058c"
])
)
]
layout_pie2 = copy.deepcopy(layout)
layout_pie2["title"] = "LOCAL DO CRIME"
layout_pie2["margin"] = dict(l=90, r=5, b=20, t=30)
layout_pie2["font"] = dict(color="#777777")
layout_pie2["legend"] = dict(
font=dict(color="#CCCCCC", size="10"), orientation="h", bgcolor="rgba(0,0,0,0)"
)
crime_location_graph = dict(data=crime_location, layout=layout_pie2)
relationship_values = [34.2, 19.7, 15.6, 12.5, 9.2, 8.1] # to be update with values from APAV database
relationship_data = [
dict(
type="pie",
labels=["Cônjuge", "Outro", "Companheiro(a)",
"Filho(a)", "Ex-Companheiro(a)", "Pai/Mãe"],
values=relationship_values,
name="Relação da Vítima com Autor do Crime",
text=["Cônjuge", "Outro", "Companheiro(a)",
"Filho(a)", "Ex-Companheiro(a)", "Pai/Mãe"],
hoverinfo="text+percent",
textinfo="label+percent+name",
hole=0.5,
marker=dict(colors=["#b93685", "#42049d", "#f58f47", "#f9d02b", "#7504a7", "#19058c"
])
)
]
layout_pie3 = copy.deepcopy(layout)
layout_pie3["title"] = "LOCAL DO CRIME"
layout_pie3["font"] = dict(color="#777777")
layout_pie3["legend"] = dict(
font=dict(color="#CCCCCC", size="10"), orientation="h", bgcolor="rgba(0,0,0,0)"
)
layout_pie3["title"] = "RELAÇÃO DA VÍTIMA COM AUTOR DO CRIME"
relationship_chart = dict(data=relationship_data, layout=layout_pie3)
victim_sex_data = [
dict(
type="pie",
labels=["Feminino",
"Masculino"],
values=[5976, 911],
name="Sexo da Vítima",
text=["Feminino", "Masculino"],
hoverinfo="text+percent",
textinfo="label+percent+name",
marker=dict(colors=["#19058c", "#e56a5d"])
)
]
layout_pie4 = copy.deepcopy(layout)
layout_pie4["title"] = "SEXO DA VÍTIMA"
layout_pie4["font"] = dict(color="#777777")
layout_pie4["legend"] = dict(
font=dict(color="#CCCCCC", size="10"), orientation="h", bgcolor="rgba(0,0,0,0)"
)
victim_sex_chart = dict(data=victim_sex_data, layout=layout_pie4)
offender_sex_data = [
dict(
type="pie",
labels=["Feminino",
"Masculino"],
values=[897, 6100],
name="Sexo do Agressor",
text=["Feminino", "Masculino"],
hoverinfo="text+percent",
textinfo="label+percent+name",
marker=dict(colors=["#19058c", "#e56a5d"])
)
]
layout_pie5 = copy.deepcopy(layout)
layout_pie5["title"] = "SEXO DO AGRESSOR"
layout_pie5["font"] = dict(color="#777777")
layout_pie5["legend"] = dict(
font=dict(color="#CCCCCC", size="10"), orientation="h", bgcolor="rgba(0,0,0,0)"
)
offender_sex_chart = dict(data=offender_sex_data, layout=layout_pie5)
drop_down = dcc.Dropdown(
id="lineplot_dropdown",
options=[
{'label': 'Vítima: Feminino', 'value': 'vitimas_feminino'},
{'label': 'Vítima: Maculino', 'value': 'vitimas_masculino'},
{'label': 'Autor do Crime: Feminino', 'value': 'autor_crime_feminino'},
{'label': "Autor do Crime: Masculino", 'value': "autor_crime_masculino"}
],
placeholder="Selecione um indicador",
multi=True,
persistence=True,
persistence_type="memory"
)
data = get_data_overview()
victims_age = ["vitimas_0_10", "vitimas_11_17", "vitimas_18_25", "vitimas_26_35", "vitimas_36_45",
"vitimas_46_55", "vitimas_56_64", "vitimas_65+"
]
aggressors_age = ["autor_crime_0_17", "autor_crime_18_25", "autor_crime_26_35", "autor_crime_36_45",
"autor_crime_46_55", "autor_crime_56_64", "autor_crime_65+"
]
victim_bins = data[data["ano"] == 2017][victims_age].values[0]
aggressor_bins = data[data["ano"] == 2017][aggressors_age].values[0]
aggressor_bins = np.insert(aggressor_bins, 0, 169) # to update once we have data for 0-10 years old
y = list(range(8))
layout_2 = go.Layout(yaxis=go.layout.YAxis(title='Idade', range=[0, 7],
tickvals=[0, 1, 2, 3, 4, 5, 6, 7],
ticktext=["0-10", "10-17", "18-35", "26-35", "36-45",
"46-55", "56-64", "65+"
]
),
margin=dict(l=40, r=40, b=20, t=40),
xaxis=go.layout.XAxis(
range=[-1500, 1500],
tickvals=[-1400, -700, -350, 0, 350, 700, 1400],
ticktext=[1400, 700, 350, 0, 350, 700, 1400],
title='Nº de Casos'),
barmode='overlay')
data_2 = [go.Bar(y=y,
x=aggressor_bins,
orientation='h',
name='Agressores',
hoverinfo='x',
marker=dict(color="#19058c")
),
go.Bar(y=y,
x=-1*victim_bins,
orientation='h',
name='Vítimas',
text=-1 * victim_bins.astype('int'),
hoverinfo='text',
marker=dict(color= "#e56a5d")
)]
layout_2["title"] = "CASOS POR PERFIL/IDADE"
layout_2["font"] = dict(color="#777777")
age_by_sex_graph = (dict(data=data_2, layout=layout_2))