Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
88bfb57
chargement et passage en pkl de la db de la police
m4riu Apr 30, 2022
f670f50
le jupyter
m4riu May 8, 2022
b83342f
les datas
m4riu May 8, 2022
45b227c
[energies] plot map
OrpheeLonie May 8, 2022
021bad4
Merge branch 'exploration' of github.com:OrpheeLonie/delta into explo…
OrpheeLonie May 8, 2022
dd3539c
[energies] correct collor
OrpheeLonie May 8, 2022
4877e6f
[energies] select month
OrpheeLonie May 8, 2022
b7e4503
[energies] month is not disabled
OrpheeLonie May 8, 2022
0f95617
[energies] add crime button
OrpheeLonie May 8, 2022
2c3f6c1
[gitignore] ignore vim swp files
OrpheeLonie May 9, 2022
a485fb1
[energies] remove useless data
OrpheeLonie May 9, 2022
0f0bfed
[energies] give only usefull info to update_graph
OrpheeLonie May 9, 2022
a9c2272
[energies] recenter map
OrpheeLonie May 9, 2022
bc0c2b2
[energies] add a TODO in the markdown
OrpheeLonie May 9, 2022
24584db
[energies] split month and year
OrpheeLonie May 9, 2022
801453d
[energies] remove line setting month and year to 'disabled'
OrpheeLonie May 9, 2022
f4b12fc
[energies] split month and year
OrpheeLonie May 9, 2022
462c39e
[energies] correct crime
OrpheeLonie May 9, 2022
ca85eeb
[energies] remove France_Métro and France_Entière from df
OrpheeLonie May 9, 2022
3539f72
[energies] add log scaling
OrpheeLonie May 9, 2022
ce29cd8
[energies] add slider
OrpheeLonie May 9, 2022
0785a7a
[energies] udpate slider
OrpheeLonie May 9, 2022
fa46382
[energies] get date from slider
OrpheeLonie May 9, 2022
2adf70f
[energies] remove useless label
OrpheeLonie May 9, 2022
3a88197
[energies] setup auto stepper
OrpheeLonie May 9, 2022
4ca5a1e
[energies] add button but it does not work
OrpheeLonie May 9, 2022
a6fead2
[energies] add style to the button (warning! useless)
OrpheeLonie May 9, 2022
6a4826e
[energies] button is working now
OrpheeLonie May 9, 2022
4c49840
[energies] remove RadioItems and move Buttons
OrpheeLonie May 9, 2022
aefdd1f
[data] remove our xlsx and pkl files
OrpheeLonie May 9, 2022
c34f2b7
[data] remove data folder
OrpheeLonie May 9, 2022
6df2f36
[get_data] add a first version
OrpheeLonie May 9, 2022
39ba4b8
[get_data] download pkl in data/
OrpheeLonie May 9, 2022
594e317
[get_data] download xlsx files in data folder
OrpheeLonie May 9, 2022
4c38b81
[gitignore] ignore data folder
OrpheeLonie May 9, 2022
53ce78f
[delta] comment call to deces and population
OrpheeLonie May 9, 2022
3afc096
[energies] get data from data folder
OrpheeLonie May 9, 2022
59e60b5
[energies] rename Energies to Map (and nrg to map)
OrpheeLonie May 9, 2022
ba779fc
[map] rename energies to map
OrpheeLonie May 9, 2022
a21b01b
[map] update text
OrpheeLonie May 9, 2022
232c950
[chart] add chart panel
OrpheeLonie May 9, 2022
d6aad52
[delta] remove deces and popultation
OrpheeLonie May 9, 2022
a5fb7a5
add explications on map
m4riu May 9, 2022
cc325a3
Merge branch 'exploration' of github.com:OrpheeLonie/delta into explo…
m4riu May 9, 2022
57dd13a
[chart] add evolution
OrpheeLonie May 9, 2022
78a3450
changement du nom de l'êchelle et mise a jour en fonction de log ou l…
m4riu May 9, 2022
663d045
dernier ajout a la description du site pour la map
m4riu May 9, 2022
522bdb8
Merge branch 'exploration' of github.com:OrpheeLonie/delta into explo…
m4riu May 9, 2022
2e549c6
[chart] put the two chart side by side
OrpheeLonie May 9, 2022
60fe3d2
Merge branch 'exploration' of github.com:OrpheeLonie/delta into explo…
m4riu May 9, 2022
114f0f5
[chart] add checklist
OrpheeLonie May 9, 2022
09f9bea
map now use ts_db
m4riu May 9, 2022
0b7426a
[map] correct slider when at max value
OrpheeLonie May 9, 2022
e28b744
Merge branch 'exploration' of github.com:OrpheeLonie/delta into explo…
OrpheeLonie May 9, 2022
ace9e18
[chart] update correlation
OrpheeLonie May 9, 2022
8926428
[chart] correct evolution
OrpheeLonie May 9, 2022
857ce56
[chart] add legend to the checklist
OrpheeLonie May 9, 2022
b942d75
[chart][map] markdown fever! è_é
OrpheeLonie May 9, 2022
ae53d04
[delta] correct link to source
OrpheeLonie May 9, 2022
019d3f7
[clean] remove useless files
OrpheeLonie May 9, 2022
d0d168e
[map] update log on df[crime]
OrpheeLonie May 9, 2022
8cb6619
[chart] titre pour la matrice de corrélation
m4riu May 9, 2022
23170eb
[README] update README
OrpheeLonie May 9, 2022
f0dd68c
Merge branch 'exploration' of github.com:OrpheeLonie/delta into explo…
OrpheeLonie May 9, 2022
4794367
[project] move our project in sub folder
OrpheeLonie May 9, 2022
1dc1715
[delta] revert project to leave it unmoved
OrpheeLonie May 9, 2022
1ddf9e1
Merge branch 'main' of https://github.com/oricou/delta into oricou-main
OrpheeLonie May 9, 2022
b8f9711
Merge branch 'oricou-main' into main
OrpheeLonie May 9, 2022
76efbdb
[gitignore] revert to first version
OrpheeLonie May 9, 2022
ef19e17
[LICENSE] revert LICENSE
OrpheeLonie May 9, 2022
d980f3a
[revert] revert assets and requirements.txt
OrpheeLonie May 9, 2022
23ae11c
[requirements] add statsmodels
OrpheeLonie May 9, 2022
b10daa4
gitignore data
m4riu Jun 3, 2022
d5789d2
add link to our project in delta.py
m4riu Jun 3, 2022
354bd8a
manu me les pompe avec son -a
m4riu Jun 3, 2022
f091f33
update git ignore
m4riu Jun 3, 2022
6af0ad3
remove useless import
m4riu Jun 3, 2022
862a831
Merge branch 'main' of github.com:oricou/delta into main
OrpheeLonie Jun 4, 2022
568e8fe
[PATH] perpend 'EMMH_' to the url of our project
OrpheeLonie Jun 4, 2022
494b15a
correct path in delta.py + remove EMMH_Etudes_evolution_des_crimes_en…
OrpheeLonie Jun 4, 2022
e74bd67
[get_data] put main in function main, and call it from chart and map
OrpheeLonie Jun 4, 2022
e3da65e
add comments
OrpheeLonie Jun 4, 2022
5ba9951
Merge branch 'main' into main
m4riu Jun 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
661 changes: 661 additions & 0 deletions EMMH_Etudes_evolution_des_crimes_en_France_depuis_1996/LICENSE

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
html { background-color: papayawhip; }
body {
min-height: 100vh;
max-width: 1600px;
background-color: papayawhip;
margin: 0 auto;
margin-top: 10px;
}

h1, h2, h3, h4, h5, h6 {
color: #222222;
}

.checkbox {
column-count: 2;
}
136 changes: 136 additions & 0 deletions EMMH_Etudes_evolution_des_crimes_en_France_depuis_1996/chart/chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import sys
import dash
import flask
from dash import dcc
from dash import html
import pandas as pd
import numpy as np
import plotly.graph_objs as go
import plotly.express as px
import dateutil as du

from urllib.request import urlopen
import json

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import get_data

class Chart():

def __init__(self, application = None):
# download data if needed
get_data.main()
self.ts_df = pd.read_pickle('data/ts_db.pkl')
self.all_france = self.ts_df[(self.ts_df['Département'] == 'France_Entière')]

self.main_layout = html.Div(children=[
html.H3(children='Graphiques sur l\'évolution du nombre de crimes en France.'),
html.A(children='lien vers la carte (première partie)', href='/EMMH_map'),
html.Div(
[
dcc.Graph(id='chart-heatmap'),
dcc.Graph(id='chart-evolution'),
],
style={
'display':'flex',
'flexDirection':'row',
'justifyContent':'flex-start',
}
),

html.Div([
html.Div([ html.Div('Sélectionner catégorie'),
dcc.Checklist(
id='chart-items-crimes',
options=[{'label': self.ts_df.columns[i], 'value': i }
for i in range(len(self.ts_df.columns) - 1)],
value=[0, 1, 2, 3],
inline=False),],
style={'margin':"0px 0px 0px 40px"}),
html.Div([ html.Div('Échelle en y'),
dcc.RadioItems(
id='chart-xaxis-type',
options=[{'label': i, 'value': i != 'Linéaire'} for i in ['Linéaire', 'Logarithmique']],
value=True,
labelStyle={'display':'block'},
)
], style={'width': '15em', 'margin':"0px 0px 0px 40px"} ), # bas D haut G
html.Div(style={'width':'2em'}),
], style={
'padding': '10px 50px',
'display':'flex',
'flexDirection':'row',
'justifyContent':'flex-start',
}),
html.Br(),
dcc.Markdown("""
Le graphique est interactif. En passant la souris sur les courbes vous avez une infobulle.
En sélectionnant les différentes catégories, vous pouvez choisir
celles corréllées et affichées sur les graphiques.

#### À propos

Cette base de donnée est mise à jour mensuellement, aussi nous avons fait attention à ce que notre site tienne compte de nouvels ajouts de données.

* Sources :
* [data.gouv.fr](https://www.data.gouv.fr/datasets/chiffres-departementaux-mensuels-relatifs-aux-crimes-et-delits-enregistres-par-les-services-de-police-et-de-gendarmerie-depuis-janvier-1996/)
chiffres departementaux mensuels relatifs aux crimes et delits enregistres par les services de police et de gendarmerie depuis janvier 1996
* (c) 2022 Olivier Ricou
""")
], style={
'backgroundColor': 'white',
'padding': '10px 50px 10px 50px',
}
)

if application:
self.app = application
# application should have its own layout and use self.main_layout as a page or in a component
else:
self.app = dash.Dash(__name__)
self.app.layout = self.main_layout

self.app.callback(
dash.dependencies.Output('chart-heatmap', 'figure'),
dash.dependencies.Input('chart-items-crimes', 'value'),
)(self.update_heatmap)

self.app.callback(
dash.dependencies.Output('chart-evolution', 'figure'),
dash.dependencies.Input('chart-items-crimes', 'value'),
dash.dependencies.Input('chart-xaxis-type', 'value'),
)(self.update_evolution)

def update_heatmap(self, items):
df = self.all_france[self.ts_df.columns[items]]
corr = df.sort_index().corr(method='pearson')
fig = px.imshow(
corr,
zmin = -1,
zmax = 1,
title = "Mise en corrélation des différents crimes",
)
fig.update_yaxes(matches=None, visible=False)
fig.update_xaxes(matches=None, visible=False)

return fig

def update_evolution(self, items, xaxis_type):
df = self.all_france[self.ts_df.columns[items]]
if xaxis_type:
df = np.log(df+1)

fig = px.line(
df,
title="Evolution au cours du temps",
)

fig.update(layout_showlegend=False)

return fig


if __name__ == '__main__':
chart = Chart()
chart.app.run_server(debug=True, port=8051)
1,673 changes: 1,673 additions & 0 deletions EMMH_Etudes_evolution_des_crimes_en_France_depuis_1996/explo_data.ipynb

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions EMMH_Etudes_evolution_des_crimes_en_France_depuis_1996/get_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pandas as pd
import re
import pathlib
import requests

def read_excel_sheets(xls_path):
"""Read all sheets of an Excel workbook and return a single DataFrame"""
print(f'Loading {xls_path} into pandas')
xl = pd.ExcelFile(xls_path)
df = list()
for idx, name in enumerate(xl.sheet_names):
# print(f'Reading sheet #{idx}: {name}')

sheet = xl.parse(name,
index_col=[0],
skiprows=[96, 97, 99, 100],
usecols=lambda x : x != 'Index').T
sheet.index = sheet.index.map(lambda x: pd.to_datetime(x + '_1', format="_%Y_%m_%d"))
sheet['Département'] = name

df.append(sheet)
return pd.concat(df)

def main():
data_dir = pathlib.Path('data')
if not data_dir.is_dir():
data_dir.mkdir()

url = "https://www.data.gouv.fr/api/1/datasets/chiffres-departementaux-mensuels-relatifs-aux-crimes-et-delits-enregistres-par-les-services-de-police-et-de-gendarmerie-depuis-janvier-1996/"
crimes_resources = requests.get(url).json()

prog = re.compile(".*\.xlsx")
filenames = {
d['title']:d['url']
for d in crimes_resources['resources']
if prog.match(d['title'])
}


dfs = {}
for k, v in filenames.items():
name_db = f'{v[-7:-5]}_db'
if pathlib.Path(f'data/{name_db}.pkl').is_file():
dfs[name_db] = pd.read_pickle(f'data/{name_db}.pkl')
else:
if not pathlib.Path('data/' + k).is_file():
with open('data/' + k, 'wb') as file:
file.write(requests.get(v).content)
dfs[name_db] = read_excel_sheets('data/' + k)
dfs[name_db].to_pickle(f'data/{name_db}.pkl')

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
html { background-color: papayawhip; }
body {
min-height: 100vh;
max-width: 1600px;
background-color: papayawhip;
margin: 0 auto;
margin-top: 10px;
}

h1, h2, h3, h4, h5, h6 {
color: #222222;
}

.checkbox {
column-count: 2;
}
Loading