← Tous les exercices
Les indicateurs du dashboard
Partie 6 · ★★
Le dashboard minimal demande : le nombre total de marchés détectés, le nombre de marchés pertinents, une répartition par priorité, une évolution temporelle des détections et une répartition géographique. Ici « pertinent » signifie niveau différent de faible (hypothèse ajoutée).
Table marche(id, date_pub, localisation, niveau) déjà remplie (8 annonces). Complète : total, pertinents, par_niveau (dict niveau → nombre), par_jour (liste de (date_pub, nombre) triée par date) et par_region (dict localisation → nombre).
import sqlite3 con = sqlite3.connect(":memory:", isolation_level=None) con.executescript(""" CREATE TABLE marche(id INTEGER PRIMARY KEY, date_pub TEXT, localisation TEXT, niveau TEXT); INSERT INTO marche VALUES (1,'2024-03-01','IDF','élevé'),(2,'2024-03-01','Bretagne','faible'), (3,'2024-03-02','Occitanie','moyen'),(4,'2024-03-02','IDF','moyen'),(5,'2024-03-02','IDF','faible'), (6,'2024-03-03','Bretagne','élevé'),(7,'2024-03-03','Occitanie','faible'),(8,'2024-03-04','IDF','élevé'); """) total = con.execute("SELECT ___ FROM marche").fetchone()[0] pertinents = con.execute("SELECT COUNT(*) FROM marche WHERE niveau ___ 'faible'").fetchone()[0] par_niveau = dict(con.execute("SELECT niveau, COUNT(*) FROM marche GROUP BY niveau")) par_jour = con.execute("SELECT date_pub, COUNT(*) FROM marche GROUP BY ___ ORDER BY date_pub").fetchall() par_region = dict(con.execute("SELECT localisation, COUNT(*) FROM marche GROUP BY localisation"))
Ctrl/⌘+Entrée