Affichage des résultats des régions sur une carte
This commit is contained in:
@ -73,6 +73,11 @@ def exporter_resultats_france(engine: Engine, verbose: bool = False) -> None:
|
||||
session.add(resultats_france)
|
||||
|
||||
resultats_dict = {
|
||||
'france': {
|
||||
'regions': [reg.code_insee for reg in session.execute(select(Region)).scalars().all()],
|
||||
'departements': [dpt.code_insee for dpt in session.execute(select(Departement)).scalars().all()],
|
||||
'circonscriptions': [circo.id for circo in session.execute(select(Circonscription)).scalars().all()],
|
||||
},
|
||||
"inscrits": resultats_france.inscrits,
|
||||
"votants": resultats_france.votants,
|
||||
"abstentions": resultats_france.abstentions,
|
||||
@ -105,7 +110,11 @@ def exporter_resultats_regions(engine: Engine, verbose: bool = False) -> None:
|
||||
regions_iterator = tqdm(regions, desc="Régions") if verbose else regions
|
||||
for region in regions_iterator:
|
||||
region_json = {'code_insee': region.code_insee, 'nom': region.libelle,
|
||||
'departements': [dpt.code_insee for dpt in region.departements]}
|
||||
'departements': [dpt.code_insee for dpt in region.departements],
|
||||
'circonscriptions':
|
||||
[circo.id for circo in session.execute(
|
||||
select(Circonscription).join(Departement).filter_by(region_code=region.code_insee))
|
||||
.scalars().all()]}
|
||||
regions_json.append(region_json)
|
||||
|
||||
resultats_region = session.execute(select(ResultatsRegion).filter_by(region_id=region.code_insee)) \
|
||||
@ -318,6 +327,7 @@ 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,
|
||||
'libelle': bureau_vote.libelle,
|
||||
'commune': bureau_vote.commune_code,
|
||||
'circonscription': bureau_vote.circo_code}
|
||||
bureaux_vote_json.append(bureau_vote_json)
|
||||
|
@ -251,7 +251,7 @@ def importer_bureaux_vote(engine: Engine, verbose: bool = False) -> None:
|
||||
numero_circo = int(bv_dict['codeCirconscription'][len(dpt_code):])
|
||||
code_circo = f"{dpt_code}-{numero_circo:02d}"
|
||||
bv_id = bv_dict['id_bv'].split()[0]
|
||||
bv_libelle = f"Bureau {code_bv}"
|
||||
bv_libelle = f"Bureau {code_bv} de {bv_dict['nomCommune']}"
|
||||
|
||||
if not session.execute(select(Commune).filter_by(code_insee=code_commune)).scalar_one_or_none():
|
||||
print("Commune non trouvée avec le code", code_commune, "et le nom", bv_dict['nomCommune'])
|
||||
|
Reference in New Issue
Block a user