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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# Notes:
|
5 |
+
#
|
6 |
+
# Les scores de responsabilité varient de -4 à 4 et définissent la propreté du point de vu des agents sanitaires ou des foyers. -4 implique que la slubrité est due aux foyers tandis que 4 implique la salubrité est due aux agents.
|
7 |
+
#
|
8 |
+
# Le score propreté quant à lui décris le niveau de propreté global en faisant une moyenne des scores des deux parties.
|
9 |
+
|
10 |
+
# In[1]:
|
11 |
+
|
12 |
+
|
13 |
+
get_ipython().system(' pip install geopandas plotly pandas folium')
|
14 |
+
|
15 |
+
|
16 |
+
# ## Generating dummy data
|
17 |
+
|
18 |
+
# In[2]:
|
19 |
+
|
20 |
+
|
21 |
+
import numpy as np
|
22 |
+
import pandas as pd
|
23 |
+
import random
|
24 |
+
import json
|
25 |
+
import plotly.express as px
|
26 |
+
|
27 |
+
|
28 |
+
# Données de test: Il y a 4 foyers par quartier et 10 quartiers répartis dans 2 communes pour faire les test.
|
29 |
+
#
|
30 |
+
# NB: En nomenclature, communauté est confondue avec région et quartier avec préfecture.
|
31 |
+
|
32 |
+
# In[3]:
|
33 |
+
|
34 |
+
|
35 |
+
DATA = [
|
36 |
+
{'foyer': 1, 'quartier_id':1, "community_id": 0, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
37 |
+
{'foyer': 2, 'quartier_id':1, "community_id": 0, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
38 |
+
{'foyer': 3, 'quartier_id':1, "community_id": 0, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
39 |
+
{'foyer': 4, 'quartier_id':1, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
40 |
+
{'foyer': 5, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4},
|
41 |
+
{'foyer': 1, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
42 |
+
{'foyer': 2, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
43 |
+
{'foyer': 3, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
44 |
+
{'foyer': 4, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
45 |
+
{'foyer': 1, 'quartier_id':3, "community_id": 0, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
46 |
+
{'foyer': 2, 'quartier_id':3, "community_id": 0, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 4, 'score': 4},
|
47 |
+
{'foyer': 3, 'quartier_id':3, "community_id": 0, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 2, 'score': 3},
|
48 |
+
{'foyer': 4, 'quartier_id':3, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
49 |
+
{'foyer': 1, 'quartier_id':4, "community_id": 0, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
50 |
+
{'foyer': 2, 'quartier_id':4, "community_id": 0, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
51 |
+
{'foyer': 3, 'quartier_id':4, "community_id": 0, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
52 |
+
{'foyer': 4, 'quartier_id':4, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
53 |
+
|
54 |
+
{'foyer': 1, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
55 |
+
{'foyer': 2, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
56 |
+
{'foyer': 3, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
57 |
+
{'foyer': 4, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
58 |
+
{'foyer': 5, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4},
|
59 |
+
{'foyer': 1, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
60 |
+
{'foyer': 2, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
61 |
+
{'foyer': 3, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
62 |
+
{'foyer': 4, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
63 |
+
{'foyer': 1, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
64 |
+
{'foyer': 2, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 4, 'score': 4},
|
65 |
+
{'foyer': 3, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 2, 'score': 3},
|
66 |
+
{'foyer': 4, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
67 |
+
{'foyer': 1, 'quartier_id':7, "community_id": 4, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
68 |
+
{'foyer': 2, 'quartier_id':7, "community_id": 4, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
69 |
+
{'foyer': 3, 'quartier_id':7, "community_id": 4, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
70 |
+
{'foyer': 4, 'quartier_id':7, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
71 |
+
|
72 |
+
{'foyer': 1, 'quartier_id':8, "community_id": 9, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 2, 'score_foyer': 3, 'score': 5/2},
|
73 |
+
{'foyer': 2, 'quartier_id':8, "community_id": 9, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 0, 'score': 2},
|
74 |
+
{'foyer': 3, 'quartier_id':8, "community_id": 9, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
75 |
+
{'foyer': 4, 'quartier_id':8, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
76 |
+
{'foyer': 5, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4},
|
77 |
+
{'foyer': 1, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
78 |
+
{'foyer': 2, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
79 |
+
{'foyer': 3, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 0, 'score_foyer': 0, 'score': 0},
|
80 |
+
{'foyer': 4, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
81 |
+
{'foyer': 1, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
82 |
+
{'foyer': 2, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 4, 'score': 4},
|
83 |
+
{'foyer': 3, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 2, 'score': 3},
|
84 |
+
{'foyer': 4, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
85 |
+
{'foyer': 1, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 0, 'score_foyer': 0, 'score': 0},
|
86 |
+
{'foyer': 2, 'quartier_id':11, "community_id": 9, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
87 |
+
{'foyer': 3, 'quartier_id':11, "community_id": 9, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 1, 'score_foyer': 1, 'score': 1},
|
88 |
+
{'foyer': 4, 'quartier_id':11, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
89 |
+
|
90 |
+
{'foyer': 1, 'quartier_id':16, "community_id": 5, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
91 |
+
{'foyer': 2, 'quartier_id':16, "community_id": 5, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
92 |
+
{'foyer': 3, 'quartier_id':16, "community_id": 5, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
93 |
+
{'foyer': 4, 'quartier_id':16, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
94 |
+
{'foyer': 5, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4},
|
95 |
+
{'foyer': 1, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
96 |
+
{'foyer': 2, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
97 |
+
{'foyer': 3, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
98 |
+
{'foyer': 4, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
99 |
+
{'foyer': 1, 'quartier_id':31, "community_id": 5, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
100 |
+
{'foyer': 2, 'quartier_id':31, "community_id": 5, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 4, 'score': 4},
|
101 |
+
{'foyer': 3, 'quartier_id':31, "community_id": 5, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 2, 'score': 3},
|
102 |
+
{'foyer': 4, 'quartier_id':31, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
103 |
+
{'foyer': 1, 'quartier_id':24, "community_id": 5, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
104 |
+
{'foyer': 2, 'quartier_id':24, "community_id": 5, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
105 |
+
{'foyer': 3, 'quartier_id':24, "community_id": 5, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
106 |
+
{'foyer': 4, 'quartier_id':24, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
107 |
+
|
108 |
+
{'foyer': 1, 'quartier_id':17, "community_id": 6, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 1, 'score_foyer': 3, 'score': 1},
|
109 |
+
{'foyer': 2, 'quartier_id':17, "community_id": 6, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
110 |
+
{'foyer': 3, 'quartier_id':17, "community_id": 6, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
111 |
+
{'foyer': 4, 'quartier_id':17, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
112 |
+
{'foyer': 5, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4},
|
113 |
+
{'foyer': 1, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 1, 'score_foyer': 5, 'score': 5},
|
114 |
+
{'foyer': 2, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
115 |
+
{'foyer': 3, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
116 |
+
{'foyer': 4, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 3, 'score': 3},
|
117 |
+
{'foyer': 1, 'quartier_id':32, "community_id": 6, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
118 |
+
{'foyer': 2, 'quartier_id':32, "community_id": 6, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 4, 'score': 4},
|
119 |
+
{'foyer': 3, 'quartier_id':32, "community_id": 6, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 2, 'score': 3},
|
120 |
+
{'foyer': 4, 'quartier_id':32, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3},
|
121 |
+
{'foyer': 1, 'quartier_id':23, "community_id": 6, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
122 |
+
{'foyer': 2, 'quartier_id':23, "community_id": 6, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5},
|
123 |
+
{'foyer': 3, 'quartier_id':24, "community_id": 6, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1},
|
124 |
+
{'foyer': 4, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 2, 'score_foyer': 3, 'score': 3},
|
125 |
+
]
|
126 |
+
|
127 |
+
|
128 |
+
# In[4]:
|
129 |
+
|
130 |
+
|
131 |
+
data = pd.DataFrame(DATA)
|
132 |
+
data.head()
|
133 |
+
|
134 |
+
|
135 |
+
# In[5]:
|
136 |
+
|
137 |
+
|
138 |
+
data['score'] = (data['score_sanitaire'] + data['score_foyer']) / 2
|
139 |
+
data.head(2)
|
140 |
+
|
141 |
+
|
142 |
+
# In[6]:
|
143 |
+
|
144 |
+
|
145 |
+
data['score responsabilité'] = data['score_sanitaire'] - data['score_foyer']
|
146 |
+
|
147 |
+
|
148 |
+
# In[7]:
|
149 |
+
|
150 |
+
|
151 |
+
data.head()
|
152 |
+
|
153 |
+
|
154 |
+
# In[8]:
|
155 |
+
|
156 |
+
|
157 |
+
np.average(data['score'], axis=0, weights=data.index)
|
158 |
+
|
159 |
+
|
160 |
+
# In[9]:
|
161 |
+
|
162 |
+
|
163 |
+
def moyenne_par_quartier(quartiers, id, scoring="score"):
|
164 |
+
quartier = quartiers[quartiers.quartier_id == id]
|
165 |
+
return quartier[scoring].mean()
|
166 |
+
|
167 |
+
|
168 |
+
# In[10]:
|
169 |
+
|
170 |
+
|
171 |
+
moyenne_par_quartier(data, 2)
|
172 |
+
|
173 |
+
|
174 |
+
# Moyenne pondérée pour les quartiers qui ont peu de foyers enrégistrés dans une communauté.
|
175 |
+
|
176 |
+
# In[11]:
|
177 |
+
|
178 |
+
|
179 |
+
def moyenne_par_communaute(data, community_id, scoring="score"):
|
180 |
+
community = data[data.community_id == community_id]
|
181 |
+
avg = np.average(community[scoring], axis=0, weights=community.index)
|
182 |
+
return avg
|
183 |
+
|
184 |
+
|
185 |
+
# In[12]:
|
186 |
+
|
187 |
+
|
188 |
+
moyenne_par_communaute(data, 4)
|
189 |
+
|
190 |
+
|
191 |
+
# In[13]:
|
192 |
+
|
193 |
+
|
194 |
+
def moyenne_par_mois_par_communaute(data, community_id, month, scoring="score"):
|
195 |
+
filtered = data[(data.community_id == community_id) & (data.mois == month)]
|
196 |
+
avg = np.average(filtered[scoring], axis=0, weights=filtered.index)
|
197 |
+
return avg
|
198 |
+
|
199 |
+
|
200 |
+
# In[14]:
|
201 |
+
|
202 |
+
|
203 |
+
def moyenne_par_mois_par_quartier(data, quartier_id, month, scoring="score"):
|
204 |
+
filtered = data[(data.quartier_id == quartier_id) & (data.mois == month)]
|
205 |
+
avg = np.average(filtered[scoring], axis=0, weights=filtered.index)
|
206 |
+
return avg
|
207 |
+
|
208 |
+
|
209 |
+
# In[15]:
|
210 |
+
|
211 |
+
|
212 |
+
def moyenne_par_annee_par_communaute(data, community_id, year, scoring="score"):
|
213 |
+
filtered = data[(data.community_id == community_id) & (data.annee == year)]
|
214 |
+
avg = np.average(filtered[scoring], axis=0, weights=filtered.index)
|
215 |
+
return avg
|
216 |
+
|
217 |
+
|
218 |
+
# In[16]:
|
219 |
+
|
220 |
+
|
221 |
+
def moyenne_par_annee_par_quartier(data, quartier_id, year, scoring="score"):
|
222 |
+
filtered = data[(data.quartier_id == quartier_id) & (data.mois == year)]
|
223 |
+
avg = np.average(filtered[scoring], axis=0, weights=filtered.index)
|
224 |
+
return avg
|
225 |
+
|
226 |
+
|
227 |
+
# ##Plot Map
|
228 |
+
|
229 |
+
# In[17]:
|
230 |
+
|
231 |
+
|
232 |
+
import plotly.io as pio
|
233 |
+
pio.renderers.default = 'browser'
|
234 |
+
|
235 |
+
|
236 |
+
# In[18]:
|
237 |
+
|
238 |
+
|
239 |
+
import geopandas as gpd
|
240 |
+
import folium
|
241 |
+
from IPython.display import display
|
242 |
+
|
243 |
+
# Specify the path to your GeoJSON file
|
244 |
+
geojson_file_path = 'BNDA_TGO_2017-06-29_lastupdate.geojson'
|
245 |
+
geojson_data = json.load(open(geojson_file_path, "r"))
|
246 |
+
# Read the GeoJSON file using geopandas
|
247 |
+
gdf = gpd.read_file(geojson_file_path)
|
248 |
+
|
249 |
+
|
250 |
+
# On définit ici quelques outils pour faire la correspondance id vers quartier et communauté (vice-versa).
|
251 |
+
|
252 |
+
# In[19]:
|
253 |
+
|
254 |
+
|
255 |
+
id_quartier = {}
|
256 |
+
|
257 |
+
for row in gdf.iterrows():
|
258 |
+
id_quartier[row[0]] = row[1][4]
|
259 |
+
#id_quartier
|
260 |
+
|
261 |
+
|
262 |
+
# In[20]:
|
263 |
+
|
264 |
+
|
265 |
+
quartier_id = {}
|
266 |
+
|
267 |
+
for row in gdf.iterrows():
|
268 |
+
quartier_id[row[1][4]] = row[0]
|
269 |
+
|
270 |
+
|
271 |
+
# In[21]:
|
272 |
+
|
273 |
+
|
274 |
+
id_regions = {}
|
275 |
+
|
276 |
+
for row in gdf.iterrows():
|
277 |
+
if row[1][3] not in id_regions.values():
|
278 |
+
id_regions[row[0]] = row[1][3]
|
279 |
+
|
280 |
+
|
281 |
+
# In[22]:
|
282 |
+
|
283 |
+
|
284 |
+
id_regions
|
285 |
+
|
286 |
+
|
287 |
+
# In[23]:
|
288 |
+
|
289 |
+
|
290 |
+
data['quartier_name'] = data['quartier_id'].apply(lambda x: id_quartier[x])
|
291 |
+
data['community_name'] = data['community_id'].apply(lambda x: id_regions[x])
|
292 |
+
data.head()
|
293 |
+
|
294 |
+
|
295 |
+
# In[ ]:
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
+
|
300 |
+
|
301 |
+
# In[25]:
|
302 |
+
|
303 |
+
|
304 |
+
quartiers = data['quartier_name'].unique().tolist()
|
305 |
+
|
306 |
+
|
307 |
+
# In[26]:
|
308 |
+
|
309 |
+
|
310 |
+
qm = {}
|
311 |
+
for q in quartiers:
|
312 |
+
qm[q] = moyenne_par_quartier(data, quartier_id[q])
|
313 |
+
|
314 |
+
#qm
|
315 |
+
|
316 |
+
|
317 |
+
# In[27]:
|
318 |
+
|
319 |
+
|
320 |
+
ids = [quartier_id[q] for q in quartiers]
|
321 |
+
|
322 |
+
|
323 |
+
# In[28]:
|
324 |
+
|
325 |
+
|
326 |
+
quartiers = list(qm.keys())
|
327 |
+
|
328 |
+
|
329 |
+
# In[29]:
|
330 |
+
|
331 |
+
|
332 |
+
scores = list(qm.values())
|
333 |
+
|
334 |
+
|
335 |
+
# #Scores de propreté - Par quartiers (préfectures)
|
336 |
+
|
337 |
+
# In[30]:
|
338 |
+
|
339 |
+
|
340 |
+
new_df = pd.DataFrame(data={
|
341 |
+
'quartier': quartiers,
|
342 |
+
'scores': scores,
|
343 |
+
"quartier_id": ids
|
344 |
+
})
|
345 |
+
new_df.head()
|
346 |
+
|
347 |
+
|
348 |
+
# In[31]:
|
349 |
+
|
350 |
+
|
351 |
+
new_df.to_csv('new_df.csv', index=False)
|
352 |
+
|
353 |
+
|
354 |
+
# In[39]:
|
355 |
+
|
356 |
+
|
357 |
+
qs = new_df['quartier'].tolist()
|
358 |
+
new_gdf_q = gdf[gdf.adm2nm.isin(qs)]
|
359 |
+
|
360 |
+
|
361 |
+
# In[59]:
|
362 |
+
|
363 |
+
|
364 |
+
gdf_merged_q = pd.merge(new_gdf_q, new_df, how='left', left_on="adm2nm", right_on="quartier")
|
365 |
+
|
366 |
+
|
367 |
+
# In[60]:
|
368 |
+
|
369 |
+
|
370 |
+
gdf_merged_q.head()
|
371 |
+
|
372 |
+
|
373 |
+
# In[61]:
|
374 |
+
|
375 |
+
|
376 |
+
geojson = gdf_merged_q.__geo_interface__
|
377 |
+
|
378 |
+
|
379 |
+
# In[109]:
|
380 |
+
|
381 |
+
|
382 |
+
geojson
|
383 |
+
|
384 |
+
|
385 |
+
# In[75]:
|
386 |
+
|
387 |
+
|
388 |
+
gdf_merged_q[gdf_merged_q['adm2nm'] == "Blitta"]
|
389 |
+
|
390 |
+
|
391 |
+
# # Map Scores de propreté pour les Préfectures du Togo
|
392 |
+
|
393 |
+
# Note: la carte est centrée. Il faut zoomer en arrière pour avoir le rendu.
|
394 |
+
|
395 |
+
# In[86]:
|
396 |
+
|
397 |
+
|
398 |
+
fig = px.choropleth_mapbox(gdf_merged_q,
|
399 |
+
geojson=geojson,
|
400 |
+
locations=gdf_merged_q.index,
|
401 |
+
color='scores',
|
402 |
+
mapbox_style="carto-positron",
|
403 |
+
title="Scores de Propreté Pour Les Préfectures Du Togo",
|
404 |
+
hover_name="adm2nm",
|
405 |
+
color_continuous_scale="Viridis"
|
406 |
+
)
|
407 |
+
fig.update_layout(margin={'r':0, 't':0, "l": 0, 'r': 0})
|
408 |
+
fig.show()
|
409 |
+
|
410 |
+
|
411 |
+
# In[101]:
|
412 |
+
|
413 |
+
|
414 |
+
gdf_merged_q.to_csv('merged_q.csv', index=False)
|
415 |
+
|
416 |
+
|
417 |
+
# In[ ]:
|
418 |
+
|
419 |
+
|
420 |
+
|
421 |
+
|
422 |
+
|
423 |
+
# # Scores de propreté - par régions
|
424 |
+
|
425 |
+
# In[78]:
|
426 |
+
|
427 |
+
|
428 |
+
id_regions
|
429 |
+
|
430 |
+
|
431 |
+
# In[79]:
|
432 |
+
|
433 |
+
|
434 |
+
regions_id = list(id_regions.keys())
|
435 |
+
scores = list()
|
436 |
+
|
437 |
+
|
438 |
+
# In[80]:
|
439 |
+
|
440 |
+
|
441 |
+
rm = {}
|
442 |
+
for q in regions_id:
|
443 |
+
print(q)
|
444 |
+
rm[q] = moyenne_par_communaute(data, q)
|
445 |
+
|
446 |
+
rm
|
447 |
+
|
448 |
+
|
449 |
+
# In[81]:
|
450 |
+
|
451 |
+
|
452 |
+
regions = [id_regions[i] for i in regions_id]
|
453 |
+
scores = list(rm.values())
|
454 |
+
|
455 |
+
|
456 |
+
# In[82]:
|
457 |
+
|
458 |
+
|
459 |
+
region_df = pd.DataFrame({
|
460 |
+
'region_id': regions_id,
|
461 |
+
'region': regions,
|
462 |
+
'scores': scores
|
463 |
+
})
|
464 |
+
|
465 |
+
region_df.head()
|
466 |
+
|
467 |
+
|
468 |
+
# In[ ]:
|
469 |
+
|
470 |
+
|
471 |
+
|
472 |
+
|
473 |
+
|
474 |
+
# # Score de responsabilité - par quartiers (Préfectures)
|
475 |
+
|
476 |
+
# In[93]:
|
477 |
+
|
478 |
+
|
479 |
+
qm = {}
|
480 |
+
for q in quartiers:
|
481 |
+
qm[q] = moyenne_par_quartier(data, quartier_id[q], scoring="score responsabilité")
|
482 |
+
|
483 |
+
|
484 |
+
# In[94]:
|
485 |
+
|
486 |
+
|
487 |
+
ids = [quartier_id[q] for q in quartiers]
|
488 |
+
quartiers = list(qm.keys())
|
489 |
+
scores = list(qm.values())
|
490 |
+
|
491 |
+
|
492 |
+
# In[95]:
|
493 |
+
|
494 |
+
|
495 |
+
respon_df = pd.DataFrame(data={
|
496 |
+
'quartier': quartiers,
|
497 |
+
'scores': scores,
|
498 |
+
"quartier_id": ids
|
499 |
+
})
|
500 |
+
respon_df.head()
|
501 |
+
|
502 |
+
|
503 |
+
# In[102]:
|
504 |
+
|
505 |
+
|
506 |
+
gdf_merged_q_r = pd.merge(new_gdf_q, respon_df, left_on="adm2nm", right_on="quartier", how='left')
|
507 |
+
gdf_merged_q_r.to_csv('merged_q_r.csv', index=False)
|
508 |
+
gdf_merged_q_r.head()
|
509 |
+
|
510 |
+
|
511 |
+
# In[ ]:
|
512 |
+
|
513 |
+
|
514 |
+
|
515 |
+
|
516 |
+
|
517 |
+
# In[100]:
|
518 |
+
|
519 |
+
|
520 |
+
fig = px.choropleth_mapbox(gdf_merged_q_r,
|
521 |
+
geojson=geojson,
|
522 |
+
locations=gdf_merged_q.index,
|
523 |
+
color='scores',
|
524 |
+
mapbox_style="carto-positron",
|
525 |
+
title="Scores de Propreté Pour Les Préfectures Du Togo",
|
526 |
+
hover_name="adm2nm",
|
527 |
+
color_continuous_scale="Viridis"
|
528 |
+
)
|
529 |
+
fig.update_layout(margin={'r':0, 't':0, "l": 0, 'r': 0})
|
530 |
+
fig.show()
|
531 |
+
|
532 |
+
|
533 |
+
# In[ ]:
|
534 |
+
|
535 |
+
|
536 |
+
|
537 |
+
|