-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
84 lines (75 loc) · 3.22 KB
/
main.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
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import sqlite3
from create_map import create_map
app = FastAPI()
app.mount("/templates", StaticFiles(directory="templates"), name="templates")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def read_item(request: Request):
data_filter = request.query_params.get("filter", False)
if not data_filter:
data_filter = "%"
connection = sqlite3.connect("app.db")
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute(
"""
SELECT lum.cond, COUNT(car.num_accident) AS num_accident
FROM caracteristique AS car JOIN vehicule AS veh ON car.num_accident=veh.num_accident
JOIN usager AS us ON us.id_veh=veh.id_veh
JOIN luminosite as lum ON lum.lum=car.lum
JOIN agglomeration as agg ON agg.agg=car.agg
JOIN atmospherique as atm ON atm.atm=car.atm
JOIN gravite as grav ON grav.grav=us.grav
WHERE veh.catv=1 AND grav.cond LIKE ?
GROUP BY lum.cond
ORDER BY num_accident DESC
""",
(data_filter,),
)
rows_luminosite = cursor.fetchall()
cursor.execute(
"""
SELECT agg.cond, COUNT(car.num_accident) AS num_accident
FROM caracteristique AS car JOIN vehicule AS veh ON car.num_accident=veh.num_accident
JOIN usager AS us ON us.id_veh=veh.id_veh
JOIN luminosite as lum ON lum.lum=car.lum
JOIN agglomeration as agg ON agg.agg=car.agg
JOIN atmospherique as atm ON atm.atm=car.atm
JOIN gravite as grav ON grav.grav=us.grav
WHERE veh.catv=1 AND grav.cond LIKE ?
GROUP BY agg.cond
ORDER BY num_accident DESC
""",
(data_filter,),
)
rows_agglomeration = cursor.fetchall()
cursor.execute(
"""
SELECT atm.cond, COUNT(car.num_accident) AS num_accident
FROM caracteristique AS car JOIN vehicule AS veh ON car.num_accident=veh.num_accident
JOIN usager AS us ON us.id_veh=veh.id_veh
JOIN luminosite as lum ON lum.lum=car.lum
JOIN agglomeration as agg ON agg.agg=car.agg
JOIN atmospherique as atm ON atm.atm=car.atm
JOIN gravite as grav ON grav.grav=us.grav
WHERE veh.catv=1 AND grav.cond LIKE ?
GROUP BY atm.cond
ORDER BY num_accident DESC
""",
(data_filter,),
)
rows_atmospherique = cursor.fetchall()
create_map(data_filter)
return templates.TemplateResponse(
"index.html",
{
"request": request,
"luminosite": rows_luminosite,
"agglomeration": rows_agglomeration,
"atmospherique": rows_atmospherique,
},
)