Commit 50a1c27c authored by Dorian's avatar Dorian
Browse files

added an histogram generation script

parent bac92a4c
This diff is collapsed.
......@@ -110,7 +110,7 @@
} */
.big-potelet{
font-family: "Liberation Serif";
font-family: "Liberation Serif Faux";
font-size: 700pt;
font-weight: bold;
font-style: italic;
......
......@@ -29,7 +29,7 @@
font-weight: normal;
font-style: normal;
}
/* @font-face {
@font-face {
font-family: "Liberation Serif";
src: url("/layout/fonts/liberation-serif/LiberationSerif-Italic.ttf") format("truetype");
font-weight: normal;
......@@ -40,16 +40,17 @@
src: url("/layout/fonts/liberation-serif/LiberationSerif-Bold.ttf") format("truetype");
font-weight: bold;
font-style: normal;
} */
/* @font-face {
}
@font-face {
font-family: "Liberation Serif";
src: url("/layout/fonts/liberation-serif/LiberationSerif-BoldItalic") format("truetype");
font-weight: bold;
font-style: italic;
} */
}
@font-face {
font-family: "Tiny";
src: url("/layout/fonts/TINY5x3-100.otf");
font-family: "Liberation Serif Faux";
src: url("/layout/fonts/liberation-serif/LiberationSerif-Regular.ttf") format("truetype");
font-weight: normal;
font-style: normal;
}
......@@ -129,7 +129,7 @@ li{
}
.cluster table.summary tr,
.cluster table.summary td{
/* break-inside: avoid; */
break-inside: avoid;
}
/* .cluster table.summary tr.False{
color: darkgrey;
......@@ -230,7 +230,7 @@ ul.attachments .date{
/* ___ PICTURES ___*/
ul.attachments li.image{
/* maximum height is the paper sheet */
max-height: calc(29.7cm - calc(2 * 1.6cm));
max-height: calc(29.7cm - calc(1.6cm + 2.4cm));
/* display: flex;
flex-direction: column; */
......@@ -248,7 +248,7 @@ ul.attachments .img-container{
ul.attachments img{
width: 100%;
height: auto;
max-height: calc(calc(29.7cm - calc(2 * 1.6cm)) - 4em);
max-height: calc(calc(29.7cm - calc(1.6cm + 2.4cm)) - 4em);
/* max-height: 100%; */
/* l'image est rogner si trop haute ! */
......
......@@ -3,48 +3,53 @@
@page {
size: A4;
margin-top: 1.6cm;
margin-bottom: 1.6cm;
margin-left: 1.6cm;
margin-right: 1.6cm;
margin-bottom: 2.4cm;
@bottom-right {
content: string(postal);
@top-right{
content: "p. " counter(page);
}
@right-bottom {
/* content: "p. " counter(page); */
/* writing-mode: vertical-rl;
transform-origin: center center;
transform: rotate(-180deg);
margin-left: 0.1em; */
}
/* @page:left{
@left-top {
}
}
@page:right{
@right-top {
content: "p. " counter(page);
}
} */
@page incident{
@bottom-left {
content: string(potelet-id);
content: "⬤\00A0" string(potelet-id) "\00A0\2014\2014\2014\2014\00A0n°" counter(potelet) "\00A0in\00A0";
text-transform: lowercase;
}
@bottom-center {
content: "n°" counter(potelet) " of cluster " counter(cluster);
content: "cluster " counter(cluster);
border-radius: 50%;
border: 1pt solid black;
margin: 0.5cm 0;
width: 3.6cm;
}
@bottom-right {
content: "\00A0\00A0\2014\2014\2014\2014\2014\2014\2014\00A0\00A0of\00A0\00A0\2014\2014\2014\2014\2014\2014\2014\2014\00A0\00A0" string(postal);
}
}
@page cluster{
@bottom-center {
content: "cluster " counter(cluster);
}
/* @bottom-left {
content: none;
}
@bottom-center {
content: none;
border-radius: 50%;
border: 1pt solid black;
margin: 0.5cm 0;
width: 3.6cm;
}
@bottom-right {
content: none;
content: string(postal);
}
@right-bottom {
content: none;
} */
}
@page cover{
......@@ -57,13 +62,25 @@
@bottom-right {
content: none;
}
@right-bottom {
@top-right {
content: none;
}
}
}
/* .fake-margin-bottom{
position: absolute;
bottom: 0;
left: 1.6cm;
right: 1.6cm;
height: 2.4cm;
display: grid;
grid-template-columns: 1fr 1fr 3.6cm 1fr 1fr;
} */
/* ---------- */
:root{
--content-width: calc(var(--pagedjs-pagebox-width) - var(--pagedjs-margin-left) - var(--pagedjs-margin-right));
--content-height: calc(var(--pagedjs-pagebox-height) - var(--pagedjs-margin-top) - var(--pagedjs-margin-bottom));
......@@ -78,5 +95,5 @@ div.pagedjs_page_content div{
height: var(--content-height); */
overflow: auto;
width: calc(21cm - calc(2 * 1.6cm));
height: calc(29.7cm - calc(2 * 1.6cm));
height: calc(29.7cm - calc(1.6cm + 2.4cm));
}
......@@ -10,11 +10,8 @@ from utils.geoUtils import writeGeojson, randomColors
from clusters.addEuclidianCoord import addEuclidianCoord
from clusters.computeClusters import computeClusters
from clusters.getHistogram import getHistogram
DB_PATH = '../data/potelets.db'
GEOJSON_OUT_PATH = "../data/potelets_clustered.geojson"
HISTOGRAM_PATH = "../data/histogram.png"
CENTER_BXL = [ 4.35264587402343, 50.84741037657682 ]
CLUSTER_MAX_DISTANCE = 30
......@@ -59,8 +56,3 @@ if __name__ == '__main__':
addClusterId(conn, potelets)
print("-- Clustedred data saved in ", DB_PATH)
print("")
# Generate Histogram
print("6. Generating Histogram")
getHistogram(clusters, HISTOGRAM_PATH)
print("-- Histogram saved in ", HISTOGRAM_PATH)
import matplotlib.pyplot as plt
import numpy as np
from utils.dbInteraction import (
createConnection,
# getPotelets,
getClusters,
# getAttachments,
# getHistory,
# getLastUpdate
)
from utils.formatingUtils import (
municipalityFilter,
# formatingCluster,
# formatingPotelet,
# format_date,
# addGeojsonToClusters
)
MUNICIPALITIES = {
1000: "Bruxelles-Ville",
1020: "Laeken",
1030: "Schaerbeek",
1040: "Etterbeek",
1050: "Ixelles",
1060: "Saint-Gilles",
1070: "Anderlecht",
1090: "Jette",
1080: "Molenbeek-Saint-Jean",
1081: "Koekelberg",
1082: "Berchem-Sainte-Agathe",
1083: "Ganshoren",
1140: "Evere",
1150: "Woluwe-Saint-Pierre",
1160: "Auderghem",
1170: "Watermael-Boitsfort",
1180: "Uccle",
1190: "Forest",
1200: "Woluwe-Saint-Lambert",
1210: "Saint-Josse-ten-Noode"
}
DB_PATH = '../data/potelets.db'
HISTO_CBI_PATH = "../data/clustersbyincidents.png"
HISTO_CBC_PATH = "../data/clustersbycommunes.png"
HISTO_IBC_PATH = "../data/incidentsbycommunes.png"
def clusterByIncidentHist(data, path):
fig, ax = plt.subplots()
width = 0.8 # width of rectangle
# x = np.arange(len(data.keys())) # an array of equal interval
x = data.keys()
y = data.values() # height of rectangle
ax.bar(x, y, width, color='b')
ax.set_title('Clusters by incidents they contain')
ax.set_ylabel('Number of cluster')
ax.set_xlabel('Number of incidents by cluster')
for key, value in data.items():
plt.text(key, value, str(value), rotation = 45, ha='center')
plt.tight_layout()
plt.savefig(path)
def clusterByCommuneHist(data, path):
fig, ax = plt.subplots()
width = 0.8 # width of rectangle
x = np.arange(len(data.keys())) # an array of equal interval
# x = [i-(width/2) for i in x] # bottom left of rect
y = data.values() # height of rectangle
ax.bar(x, y, width, color='b')
ax.set_title('Clusters by communes')
ax.set_ylabel('Number of clusters')
# ax.set_xlabel('Number of incidents by cluster')
ax.set_xticks(x)
ax.set_xticklabels(data.keys(), rotation = 45, ha="right")
plt.tight_layout()
plt.savefig(path)
def incidentByCommuneHist(data, path):
fig, ax = plt.subplots()
width = 0.8 # width of rectangle
x = np.arange(len(data.keys())) # an array of equal interval
y = data.values() # height of rectangle
ax.bar(x, y, width, color='b')
ax.set_title('Incidents by communes')
ax.set_ylabel('Number of incidents')
# ax.set_xlabel('Number of incidents by cluster')
ax.set_xticks(x)
ax.set_xticklabels(data.keys(), rotation = 45, ha="right")
plt.tight_layout()
plt.savefig(path)
if __name__ == '__main__':
print('1. Getting back the potelets from the db ' + DB_PATH)
conn = createConnection(DB_PATH)
clusters = getClusters(conn)
print("-- Data contains", len(clusters), "clusters")
print("2. Generating", HISTO_CBI_PATH ,"Histogram")
clusterSize = [ len(x["incidents"]) for x in clusters ]
cluster_by_incident = {}
for val in clusterSize:
if val in cluster_by_incident:
cluster_by_incident[val] +=1
else:
cluster_by_incident[val] = 1
# max = max(cluster_by_incident.keys())
# for i in range(max):
# if not i in cluster_by_incident:
# cluster_by_incident[i] = 0
clusterByIncidentHist(cluster_by_incident, HISTO_CBI_PATH)
print("-- Histogram saved in ", HISTO_CBI_PATH)
print('3. Filtering Clusters by municipalities')
clusters_by_commune = {}
incidents_by_commune = {}
for code, name in MUNICIPALITIES.items():
clusters_in_muni = municipalityFilter(clusters, code)
clusters_by_commune[name] = len(clusters_in_muni)
incidents_by_commune[name] = 0
for c in clusters_in_muni:
incidents_by_commune[name] += len(c['incidents'])
# print(clusters_by_commune)
# print(incidents_by_commune)
# print("4. Generating", HISTO_CBC_PATH ,"Histogram")
# clusterByCommuneHist(clusters_by_commune, HISTO_CBC_PATH)
# print("-- Histogram saved in ", HISTO_CBC_PATH)
print("5. Generating", HISTO_IBC_PATH ,"Histogram")
incidentByCommuneHist(incidents_by_commune, HISTO_IBC_PATH)
print("-- Histogram saved in ", HISTO_IBC_PATH)
......@@ -58,7 +58,7 @@ if __name__ == '__main__':
print('1. Getting back the potelets from the db ' + DB_PATH)
conn = createConnection(DB_PATH)
# potelets = getPotelets(conn, 100)
clusters = getClusters(conn, CLUSTER_THRESHOLD)
clusters = getClusters(conn, CLUSTER_THRESHOLD, True)
print("-- Data contains", len(clusters), "clusters with more than", CLUSTER_THRESHOLD, "incidents")
date = format_date(getLastUpdate(conn))
......
......@@ -116,7 +116,7 @@ def getHistory(conn, potelet):
return history
def getClusters(conn, thres=0):
def getClusters(conn, thres=0, getmore=False):
""" return all clusters from the sqlite db
"""
# get a list of all the cluster id
......@@ -141,10 +141,11 @@ def getClusters(conn, thres=0):
cur.execute(potelets_sql, [id])
potelets = [dict(potelet) for potelet in cur.fetchall()]
for potelet in potelets:
# we merge the tables in order to have one dict like object by potelet
potelet["attachments"] = getAttachments(conn, potelet)
potelet["history"] = getHistory(conn, potelet)
if getmore:
for potelet in potelets:
# we merge the tables in order to have one dict like object by potelet
potelet["attachments"] = getAttachments(conn, potelet)
potelet["history"] = getHistory(conn, potelet)
cluster = { "id": id,
"incidents": potelets }
......
......@@ -10,6 +10,19 @@ def getHistogram(clusters, path):
else:
hist[val] = 1
#print(hist)
plt.bar(hist.keys(), hist.values(), 1.0, color='g')
# print(hist)
fig, ax = plt.subplots()
width = 1.0 # width of rectangle
x = [x-(width/2) for x in hist.keys()] # bottom left of rect
y = hist.values() # height of rectangle
ax.bar(x, y, width, color='b')
ax.set_title('Clusters by incidents they contain')
ax.set_ylabel('Number of clusters')
ax.set_xlabel('Number of incidents by cluster')
for index, value in hist.items():
plt.text(index * width, value, "["+str(value)+"]", horizontalalignment='center')
plt.savefig(path)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment