From 5cc10f310632006ce2fb21ee66b2ff92938e56a2 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sun, 16 Jun 2024 08:11:46 +0200 Subject: [PATCH] =?UTF-8?q?L'affichage=20des=20r=C3=A9sultats=20par=20r?= =?UTF-8?q?=C3=A9gion/d=C3=A9partement/circonscription/commune/bureau=20de?= =?UTF-8?q?=20vote=20est=20fonctionnel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nupes-elections-front/src/App.js | 8 ++++++++ nupes-elections-front/src/Elections2024.js | 22 ++++++++++++++++++++-- nupes/scripts/export_resultats_2024.py | 4 +++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/nupes-elections-front/src/App.js b/nupes-elections-front/src/App.js index 4d15ba3..461e7db 100644 --- a/nupes-elections-front/src/App.js +++ b/nupes-elections-front/src/App.js @@ -17,6 +17,10 @@ function App() { path: "/elections/europeennes/2024/region/:zoneId/", element: , }, + { + path: "/elections/europeennes/2024/circonscription/:zoneId/", + element: , + }, { path: "/elections/europeennes/2024/departement/:zoneId/", element: , @@ -25,6 +29,10 @@ function App() { path: "/elections/europeennes/2024/commune/:zoneId/", element: , }, + { + path: "/elections/europeennes/2024/bureau_vote/:zoneId/", + element: , + }, ]) return <> diff --git a/nupes-elections-front/src/Elections2024.js b/nupes-elections-front/src/Elections2024.js index 581a913..266b0c6 100644 --- a/nupes-elections-front/src/Elections2024.js +++ b/nupes-elections-front/src/Elections2024.js @@ -17,7 +17,7 @@ import {useEffect, useState} from "react" highchartsItem(Highcharts) function ResultatsTable({blocs, nuances, listes, resultats, siegesParListe}) { - const voix_listes = resultats.voix_listes + const voix_listes = resultats?.voix_listes ?? {} const listes_triees = listes.toSorted((l1, l2) => { return (voix_listes[l2.numero] || 0) - (voix_listes[l1.numero] || 0) }) @@ -117,6 +117,7 @@ function ParticipationTable({resultats}) { export default function Election2024({typeResultats = "france"}) { const {zoneId} = useParams() + const [zoneName, setZoneName] = useState("France") const [grouperParBloc, setGrouperParBloc] = useState(false) const [retirerSeuil, setRetirerSeuil] = useState(false) const [blocs, setBlocs] = useState([]) @@ -150,6 +151,23 @@ export default function Election2024({typeResultats = "france"}) { } }, [typeResultats, zoneId]) + useEffect(() => { + if (!resultats || resultats.length === 0) + setZoneName("") + else if (typeResultats === "france") + setZoneName("France") + else if (typeResultats === "regions") + setZoneName(`Région ${resultats.region.nom}`) + else if (typeResultats === "departements") + setZoneName(`Département ${resultats.departement.nom}`) + else if (typeResultats === "circonscriptions") + setZoneName(`Circonscription ${resultats.circonscription.nom}`) + else if (typeResultats === "communes") + setZoneName(`Commune ${resultats.commune.nom}`) + else if (typeResultats === "bureaux_vote") + setZoneName(resultats.bureau_vote.libelle) + }, [typeResultats, resultats]) + useEffect(() => { const parBloc = {} const parNuance = {} @@ -301,7 +319,7 @@ export default function Election2024({typeResultats = "france"}) { type: 'column' }, title: { - text: 'Résultats des élections européennes 2024 en France', + text: `Résultats des élections européennes 2024 : ${zoneName}`, }, legend: { labelFormat: '{name} {x}' diff --git a/nupes/scripts/export_resultats_2024.py b/nupes/scripts/export_resultats_2024.py index 40a316c..aea55cd 100644 --- a/nupes/scripts/export_resultats_2024.py +++ b/nupes/scripts/export_resultats_2024.py @@ -317,7 +317,9 @@ def exporter_resultats_bureaux_vote(engine: Engine, verbose: bool = False) -> No iterator = tqdm(bureaux_vote, desc="Bureaux de vote") if verbose else bureaux_vote for bureau_vote in iterator: - bureau_vote_json = {'id': bureau_vote.id, 'commune': bureau_vote.commune_code} + bureau_vote_json = {'id': bureau_vote.id, + 'commune': bureau_vote.commune_code, + 'circonscription': bureau_vote.circo_code} bureaux_vote_json.append(bureau_vote_json) resultats_bureau_vote = session.execute(