-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconflict_analytics.py
426 lines (377 loc) · 13.2 KB
/
conflict_analytics.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
"""
Created on Tue June 30 00:59:25 2022
@author: Hedgar Ajakaiye
"""
from urllib.request import urlopen
import json
import streamlit as st
import matplotlib
import plotly.express as px
from millify import prettify
from data_prep.data_wrang import civil_death_15
from data_prep.data_wrang import civil_death_now
from data_prep.data_wrang import killers_15
from data_prep.data_wrang import killers_now
from data_prep.data_wrang import sum_death_15
from data_prep.data_wrang import sum_death_now
from data_prep.data_wrang import geo_zone_death_15
from data_prep.data_wrang import geo_zone_death_now
from data_prep.data_wrang import state_forces_15
from data_prep.data_wrang import state_forces_now
from data_prep.data_wrang import military_expend_15
from data_prep.data_wrang import military_expend_now
from data_prep.data_wrang import bkp_deaths
from data_prep.data_wrang import souther_kaduna_civilian_death
matplotlib.use("agg")
st.set_page_config(
page_icon=":bomb:",
layout="wide",
initial_sidebar_state="collapsed",
)
st.markdown("<style> body {color: white;}</style>", unsafe_allow_html=True)
st.markdown(
"<h1 style='text-align: center; margin-top: 15px;'>Nigeria Armed Conflict Dashboard</h1>", # noqa
unsafe_allow_html=True,
)
st.markdown(
"<style> .css-18c15ts {padding-top: 1rem; margin-top:-75px;} </style>",
unsafe_allow_html=True,
)
st.markdown(
""" <style>
# MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style> """,
unsafe_allow_html=True,
)
# st.title("NSE Live Dashboard")
st.text(
"Data Sources:1.ACLED https://acleddata.com/, 2.https://sipri.org/databases/milex; Last updated:28-04-2023"
)
def civilian_death_2015():
"""
Visualize innocent citizen murdered over the years
"""
death_cumu_civil = civil_death_15()
civilian_death_till_date = civil_death_now()
pre_bubu, now_bubu = st.columns(2)
with pre_bubu:
fig = px.line(
death_cumu_civil,
x="event_date",
y="fatalities",
title="Innocent Civilians Deaths Trend 1999-2015",
labels={"event_date": "Date", "fatalities": "Deaths"},
)
st.plotly_chart(fig, use_container_width=True)
with now_bubu:
fig = px.line(
civilian_death_till_date,
x="event_date",
y="fatalities",
title="Innocent Civilians Deaths Trend 2015-2023",
labels={"event_date": "Date", "fatalities": "Deaths"},
)
st.plotly_chart(fig, use_container_width=True)
def death_metric():
"""
Number of innocent citizens murdered over the years
"""
sixteen_years_death = sum_death_15()
eight_years_deaths = sum_death_now()
death_metric1, death_metric2 = st.columns(2)
death_metric1.metric(
label="Innocent Civilians Murdered in the past 16 Years",
value=f"{prettify(sixteen_years_death)}",
)
death_metric2.metric(
label="Innocent Civilian Murdered in the past 8 Years",
value=f"{prettify(eight_years_deaths)}",
)
def state_forces_killed_metric():
"""
Number of state forces-military and police that have been murdered over the years
"""
force_15 = state_forces_15()
force_now = state_forces_now()
metric_force_15 = force_15["fatalities"].sum()
metric_force_now = force_now["fatalities"].sum()
state_force_16, state_force_7 = st.columns(2)
state_force_16.metric(
label="State Forces(Military & Police) Murdered in the past 16 years",
value=f"{prettify(metric_force_15)}",
)
state_force_7.metric(
label="State Forces(Military & Police) Murdered in the past 8 years",
value=f"{prettify(metric_force_now)}",
)
def military_expenditure_viz():
"""
Visualize Military expenditure over the years
"""
pre_buhari_regime = military_expend_15()
buhari_regime = military_expend_now()
then_expen, now_expend = st.columns(2)
with then_expen:
fig = px.line(
pre_buhari_regime,
x="calendar_year",
y="amounts",
title="Expenditure on the Military 1999-2014",
labels={"amounts": "Amount", "calendar_year": "Year"},
)
st.plotly_chart(fig)
with now_expend:
fig = px.line(
buhari_regime,
x="calendar_year",
y="amounts",
title="Expenditure on the Military 2015-2021",
labels={"amounts": "Amount", "calendar_year": "Year"},
)
st.plotly_chart(fig)
def military_expend_metric():
"""
Military expenditure metrics
"""
pre_buhari_regime = military_expend_15()
buhari_regime = military_expend_now()
sum_prev_regime_data = pre_buhari_regime["amount"].sum()/1000000000000
sum_current_regime_data = buhari_regime["amount"].sum()/1000000000000
military_spend_metric1, military_spend_metric_2 = st.columns(2)
military_spend_metric1.metric(
label="Amount spent on Military 1999-2014",
value=f"{prettify(round(sum_prev_regime_data,3))} Trillion Naira",
)
military_spend_metric_2.metric(
label="Amount spent on Miliary 2015-2021",
value=f"{prettify(round(sum_current_regime_data,3))} Trillion Naira",
)
def killerz():
"""
Visualize the actors-killers of innocent citizens
"""
pre_bu = killers_15()
bubu = killers_now()
(
prebubu_kilers,
bubu_killers,
) = st.columns(2)
with prebubu_kilers:
fig = px.sunburst(
pre_bu,
path=["state", "actor1"],
values="norm_fatal",
title="Civilian Killers By State 1999-2015",
)
st.plotly_chart(fig, use_container_width=True)
with bubu_killers:
fig = px.sunburst(
bubu,
path=["state", "actor1"],
values="norm_fatal",
title="Civilian Killers By State 2015-2023",
)
st.plotly_chart(fig, use_container_width=True)
def state_forces_killers():
"""
visualize state forces- miliitary and police deaths in armed conflict
"""
force_15 = state_forces_15()
force_now = state_forces_now()
pre_state_killers, now_state_killers = st.columns(2)
with pre_state_killers:
fig = px.sunburst(
force_15,
path=["state", "actor1"],
values="norm_fatal",
title="State Forces Killers by State 1999-2015",
)
st.plotly_chart(fig, use_container_width=True)
with now_state_killers:
fig = px.sunburst(
force_now,
path=["state", "actor1"],
values="norm_fatal",
title="State Forces Killers by State 2015-2023",
)
st.plotly_chart(fig, use_container_width=True)
def killers_sharia_state():
"""
Visualize the impact of sharia status on Fatalities across states
"""
pre_bu = killers_15()
bubu = killers_now()
pre_bubu_sharia, bubu_killers_sharia = st.columns(2)
with pre_bubu_sharia:
fig = px.sunburst(
pre_bu,
path=["sharia_status", "actor1"],
values="norm_fatal",
title="Civilian Killers in States By Sharia Status 1999-2015",
)
st.plotly_chart(fig, use_container_width=True)
with bubu_killers_sharia:
fig = px.sunburst(
bubu,
path=["sharia_status", "actor1"],
values="norm_fatal",
title="Civilian Killers in States By Sharia Status 2015-2023",
)
st.plotly_chart(fig, use_container_width=True)
def geo_risk():
"""
visualize civilian deaths from armed conflict by geopolitical zones and by risk status
"""
geo_15 = geo_zone_death_15()
geo_now = geo_zone_death_now()
geo_16, geo_8 = st.columns(2)
with geo_16:
fig = px.bar(
geo_15,
x="norm_fatal",
y="geopol_zones",
title="Civilian Deaths by Geopolitical Zone 1999-2015",
labels={"geopol_zones": "Zones", "norm_fatal": "Civilian Deaths"},
orientation="h",
)
st.plotly_chart(fig)
with geo_8:
fig = px.bar(
geo_now,
x="norm_fatal",
y="geopol_zones",
title="Civilian Deaths By Geopolitical Zone 2015-2022",
labels={"geopol_zones": "Zones", "norm_fatal": " Civilian Deaths"},
orientation="h",
)
st.plotly_chart(fig)
def bkp_killings():
less_than_2014,greater_than_2015 = bkp_deaths()
bkp_killing_2014,bkp_killing_2015 = st.columns(2)
with bkp_killing_2014:
fig = px.bar(
less_than_2014,
x="fatalities",
y="state",
title="Total Civilian Deaths In (Benue,Kaduna,Plateau) States 1999-2014",
labels={"state": "States", "fatalities": "Civilian Deaths"},
orientation="h",
)
st.plotly_chart(fig)
with bkp_killing_2015:
fig = px.bar(
greater_than_2015,
x="fatalities",
y="state",
title="Total Civilian Deaths In (Benue,Kaduna,Plateau) States 2015-2023",
labels={"state": "State", "fatalities": "Civilian Deaths"},
orientation="h",
)
st.plotly_chart(fig)
def killings_by_southern_lga():
sk_14,sk_15,oters_14,oters_15,met_14,met_15,met_other_14,met_other_15 = souther_kaduna_civilian_death()
southern_kd_killing_14, sothern_kd_killing_15 = st.columns(2)
metric_civilian_2014, metric_civilian_2015 = st.columns(2)
with southern_kd_killing_14:
fig = px.bar(
sk_14,
x="fatalities",
y="lga",
title="Civilians Killed in Southern Kaduna 1999-2014",
labels={'lga':'Local Govt Area', 'fatalities':'Civilian Deaths'},
orientation='h'
)
st.plotly_chart(fig)
metric_civilian_2014.metric(label="Total Southern Kaduna Civilian Killed",value=met_14)
with sothern_kd_killing_15:
fig = px.bar(
sk_15,
x="fatalities",
y="lga",
title="Civilians Killed in Southern Kaduna By LGA 2015-2023",
labels={'lga':'Local Govt Area', 'fatalities':'Civilian Deaths'},
orientation='h'
)
st.plotly_chart(fig)
metric_civilian_2015.metric(label="Total Southern Kaduna Civilian Killed",value=met_15)
otherx_14,otherx_15 = st.columns(2)
metric_other_14, metric_other_15 = st.columns(2)
with otherx_14:
fig = px.bar(
oters_14,
x="fatalities",
y="lga",
title="Civilians Killed in Non-Southern-Kaduna By LGA 1999-2014",
labels={'lga':'Local Govt Area', 'fatalities':'Civilian Deaths'},
orientation='h'
)
st.plotly_chart(fig)
metric_other_14.metric(label="Total Non-Southern Kaduna civilian Killed",value=met_other_14)
with otherx_15:
fig = px.bar(
oters_15,
x="fatalities",
y="lga",
title="Civilians Killed in Non-Southern-Kaduna By LGA 2015-2023",
labels={'lga':'Local Govt Area', 'fatalities':'Civilian Deaths'},
orientation='h'
)
st.plotly_chart(fig)
metric_other_15.metric(label="Total Non-Southern Kaduna civilian Killed",value=met_other_15)
with urlopen(
"https://gist.githubusercontent.com/sdwfrost/6c0ccf457e30963292522dc57ed1fe7a/raw/4023566e3b23d6a518d3c88d35b97ded46756544/nigeria_states.geojson"
) as response:
states = json.load(response)
def conflict_map():
"""
Visualize fatalities across states on the Nigeria Map
"""
pre_bu = killers_15()
bubu = killers_now()
bycounties = pre_bu.groupby("state").agg({"norm_fatal": "sum"}).reset_index()
bycounties_bu = bubu.groupby("state").agg({"norm_fatal": "sum"}).reset_index()
map_prebubu, map_bubu = st.columns(2)
with map_prebubu:
fig = px.choropleth(
bycounties,
geojson=states,
locations="state",
featureidkey="properties.name_1",
color="norm_fatal",
projection="mercator",
color_continuous_scale="Reds",
labels={"norm_fatal": "Civilian Deaths"},
title="Total Civilian Deaths By State 1999-2015",
)
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
st.plotly_chart(fig)
with map_bubu:
fig = px.choropleth(
bycounties_bu,
geojson=states,
locations="state",
featureidkey="properties.name_1",
color="norm_fatal",
projection="mercator",
color_continuous_scale="Reds",
labels={"norm_fatal": "Civilian Deaths"},
title="Total Civilian Deaths By State 2015-2022",
)
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
st.plotly_chart(fig)
if __name__ == "__main__":
civilian_death_2015()
death_metric()
military_expenditure_viz()
military_expend_metric()
state_forces_killed_metric()
killerz()
state_forces_killers()
killers_sharia_state()
geo_risk()
bkp_killings()
killings_by_southern_lga()
conflict_map()