Import candidat⋅es législatives 2024
This commit is contained in:
parent
df8c8db32d
commit
ada3941d44
259
alembic/versions/0222cf0ef39b_ajout_modèles_législatives_2024.py
Normal file
259
alembic/versions/0222cf0ef39b_ajout_modèles_législatives_2024.py
Normal file
@ -0,0 +1,259 @@
|
||||
"""ajout modèles législatives 2024
|
||||
|
||||
Revision ID: 0222cf0ef39b
|
||||
Revises: 99948a33112b
|
||||
Create Date: 2024-06-20 16:34:47.315588
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '0222cf0ef39b'
|
||||
down_revision: Union[str, None] = '99948a33112b'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('legislatives_2024_bloc',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('nom', sa.String(length=32), nullable=False),
|
||||
sa.Column('couleur', sa.String(length=7), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('nom')
|
||||
)
|
||||
op.create_table('legislatives_2024_resultats_france',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t2', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_nuance',
|
||||
sa.Column('code', sa.String(length=8), nullable=False),
|
||||
sa.Column('nom', sa.String(length=64), nullable=False),
|
||||
sa.Column('couleur', sa.String(length=7), nullable=False),
|
||||
sa.Column('bloc_id', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['bloc_id'], ['legislatives_2024_bloc.id'], ),
|
||||
sa.PrimaryKeyConstraint('code'),
|
||||
sa.UniqueConstraint('nom')
|
||||
)
|
||||
op.create_table('legislatives_2024_resultats_region',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('region_id', sa.String(length=3), nullable=False),
|
||||
sa.Column('resultats_france_id', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['region_id'], ['region.code_insee'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_france_id'], ['legislatives_2024_resultats_france.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_resultats_departement',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('dpt_id', sa.String(length=3), nullable=False),
|
||||
sa.Column('resultats_region_id', sa.Integer(), nullable=True),
|
||||
sa.Column('inscrits_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['dpt_id'], ['departement.code_insee'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_region_id'], ['legislatives_2024_resultats_region.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_voix_france',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('nuance_id', sa.String(length=8), nullable=False),
|
||||
sa.Column('resultats_france_id', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['nuance_id'], ['legislatives_2024_nuance.code'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_france_id'], ['legislatives_2024_resultats_france.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_voix_region',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('nuance_id', sa.String(length=8), nullable=False),
|
||||
sa.Column('resultats_region_id', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['nuance_id'], ['legislatives_2024_nuance.code'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_region_id'], ['legislatives_2024_resultats_region.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_candidat',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('circonscription_id', sa.String(length=6), nullable=False),
|
||||
sa.Column('numero', sa.Integer(), nullable=False),
|
||||
sa.Column('nuance_id', sa.String(length=8), nullable=False),
|
||||
sa.Column('bloc_id', sa.Integer(), nullable=False),
|
||||
sa.Column('nom', sa.String(length=256), nullable=False),
|
||||
sa.Column('prenom', sa.String(length=256), nullable=False),
|
||||
sa.Column('sexe', sa.Enum('MASCULIN', 'FEMININ', name='genre'), nullable=False),
|
||||
sa.Column('date_naissance', sa.Date(), nullable=False),
|
||||
sa.Column('profession', sa.String(length=256), nullable=False),
|
||||
sa.Column('sortant', sa.Boolean(), nullable=False),
|
||||
sa.Column('nom_suppleance', sa.String(length=256), nullable=False),
|
||||
sa.Column('prenom_suppleance', sa.String(length=256), nullable=False),
|
||||
sa.Column('sexe_suppleance', sa.Enum('MASCULIN', 'FEMININ', name='genre'), nullable=False),
|
||||
sa.Column('date_naissance_suppleance', sa.Date(), nullable=False),
|
||||
sa.Column('sortant_suppleance', sa.Boolean(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['bloc_id'], ['legislatives_2024_bloc.id'], ),
|
||||
sa.ForeignKeyConstraint(['circonscription_id'], ['circonscription.id'], ),
|
||||
sa.ForeignKeyConstraint(['nuance_id'], ['legislatives_2024_nuance.code'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_resultats_circonscription',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('circo_id', sa.String(length=6), nullable=False),
|
||||
sa.Column('resultats_departement_id', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['circo_id'], ['circonscription.id'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_departement_id'], ['legislatives_2024_resultats_departement.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_resultats_commune',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('commune_id', sa.String(length=5), nullable=False),
|
||||
sa.Column('resultats_dpt_id', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['commune_id'], ['commune.code_insee'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_dpt_id'], ['legislatives_2024_resultats_departement.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_voix_departement',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('nuance_id', sa.String(length=8), nullable=False),
|
||||
sa.Column('resultats_departement_id', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['nuance_id'], ['legislatives_2024_nuance.code'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_departement_id'], ['legislatives_2024_resultats_departement.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_resultats_bureau_vote',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('bv_id', sa.String(length=16), nullable=False),
|
||||
sa.Column('resultats_commune_id', sa.Integer(), nullable=False),
|
||||
sa.Column('resultats_circo_id', sa.Integer(), nullable=True),
|
||||
sa.Column('inscrits_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('inscrits_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('votants_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('abstentions_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('exprimes_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('blancs_t2', sa.Integer(), nullable=False),
|
||||
sa.Column('nuls_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['bv_id'], ['bureau_vote.id'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_circo_id'], ['legislatives_2024_resultats_circonscription.id'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_commune_id'], ['legislatives_2024_resultats_commune.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_voix_circonscription',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('candidat_id', sa.Integer(), nullable=False),
|
||||
sa.Column('resultats_circonscription_id', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['candidat_id'], ['legislatives_2024_candidat.id'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_circonscription_id'], ['legislatives_2024_resultats_circonscription.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_voix_commune',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('nuance_id', sa.String(length=8), nullable=False),
|
||||
sa.Column('resultats_commune_id', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['nuance_id'], ['legislatives_2024_nuance.code'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_commune_id'], ['legislatives_2024_resultats_commune.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('legislatives_2024_voix_bureau_vote',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('candidat_id', sa.Integer(), nullable=False),
|
||||
sa.Column('resultats_bureau_vote_id', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t1', sa.Integer(), nullable=False),
|
||||
sa.Column('voix_t2', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['candidat_id'], ['legislatives_2024_candidat.id'], ),
|
||||
sa.ForeignKeyConstraint(['resultats_bureau_vote_id'], ['legislatives_2024_resultats_bureau_vote.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('legislatives_2024_voix_bureau_vote')
|
||||
op.drop_table('legislatives_2024_voix_commune')
|
||||
op.drop_table('legislatives_2024_voix_circonscription')
|
||||
op.drop_table('legislatives_2024_resultats_bureau_vote')
|
||||
op.drop_table('legislatives_2024_voix_departement')
|
||||
op.drop_table('legislatives_2024_resultats_commune')
|
||||
op.drop_table('legislatives_2024_resultats_circonscription')
|
||||
op.drop_table('legislatives_2024_candidat')
|
||||
op.drop_table('legislatives_2024_voix_region')
|
||||
op.drop_table('legislatives_2024_voix_france')
|
||||
op.drop_table('legislatives_2024_resultats_departement')
|
||||
op.drop_table('legislatives_2024_resultats_region')
|
||||
op.drop_table('legislatives_2024_nuance')
|
||||
op.drop_table('legislatives_2024_resultats_france')
|
||||
op.drop_table('legislatives_2024_bloc')
|
||||
# ### end Alembic commands ###
|
@ -2,3 +2,4 @@ from .base import Base
|
||||
from .geographie import *
|
||||
from .legislatives2022 import *
|
||||
from .europeennes2024 import *
|
||||
from .legislatives2024 import *
|
||||
|
@ -17,6 +17,7 @@ class Region(Base):
|
||||
|
||||
resultats_legislatives_2022 = relationship("ResultatsRegionLegislatives2022", back_populates="region")
|
||||
resultats_europeennes_2024 = relationship("ResultatsRegionEuropeennes2024", back_populates="region")
|
||||
resultats_legislatives_2024 = relationship("ResultatsRegionLegislatives2024", back_populates="region")
|
||||
|
||||
|
||||
class Departement(Base):
|
||||
@ -33,6 +34,7 @@ class Departement(Base):
|
||||
|
||||
resultats_legislatives_2022 = relationship("ResultatsDepartementLegislatives2022", back_populates="departement")
|
||||
resultats_europeennes_2024 = relationship("ResultatsDepartementEuropeennes2024", back_populates="departement")
|
||||
resultats_legislatives_2024 = relationship("ResultatsDepartementLegislatives2024", back_populates="departement")
|
||||
|
||||
|
||||
class Commune(Base):
|
||||
@ -48,6 +50,7 @@ class Commune(Base):
|
||||
|
||||
resultats_legislatives_2022 = relationship("ResultatsCommuneLegislatives2022", back_populates="commune")
|
||||
resultats_europeennes_2024 = relationship("ResultatsCommuneEuropeennes2024", back_populates="commune")
|
||||
resultats_legislatives_2024 = relationship("ResultatsCommuneLegislatives2024", back_populates="commune")
|
||||
|
||||
|
||||
class Circonscription(Base):
|
||||
@ -63,9 +66,12 @@ class Circonscription(Base):
|
||||
|
||||
candidats_legislatives_2022 = relationship("CandidatLegislatives2022", back_populates="circonscription")
|
||||
resultats_legislatives_2022 = relationship("ResultatsCirconscriptionLegislatives2022",
|
||||
back_populates="circonscription")
|
||||
back_populates="circonscription")
|
||||
resultats_europeennes_2024 = relationship("ResultatsCirconscriptionEuropeennes2024",
|
||||
back_populates="circonscription")
|
||||
candidats_legislatives_2024 = relationship("CandidatLegislatives2024", back_populates="circonscription")
|
||||
resultats_legislatives_2024 = relationship("ResultatsCirconscriptionLegislatives2024",
|
||||
back_populates="circonscription")
|
||||
|
||||
|
||||
class BureauVote(Base):
|
||||
@ -84,3 +90,4 @@ class BureauVote(Base):
|
||||
|
||||
resultats_legislatives_2022 = relationship("ResultatsBureauVoteLegislatives2022", back_populates="bureau_vote")
|
||||
resultats_europeennes_2024 = relationship("ResultatsBureauVoteEuropeennes2024", back_populates="bureau_vote")
|
||||
resultats_legislatives_2024 = relationship("ResultatsBureauVoteLegislatives2024", back_populates="bureau_vote")
|
||||
|
333
nupes/models/legislatives2024.py
Normal file
333
nupes/models/legislatives2024.py
Normal file
@ -0,0 +1,333 @@
|
||||
import enum
|
||||
from datetime import date
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy import Boolean, Date, Enum, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
||||
|
||||
from nupes.models import Base, Region, Departement, Commune, Circonscription
|
||||
|
||||
|
||||
class BlocLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_bloc"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
nom: Mapped[str] = mapped_column(String(32), unique=True)
|
||||
couleur: Mapped[str] = mapped_column(String(7))
|
||||
|
||||
candidats: Mapped[List["CandidatLegislatives2024"]] = relationship("CandidatLegislatives2024",
|
||||
back_populates="bloc")
|
||||
|
||||
nuances: Mapped[List["NuanceLegislatives2024"]] = relationship(
|
||||
"NuanceLegislatives2024", back_populates="bloc")
|
||||
|
||||
|
||||
class NuanceLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_nuance"
|
||||
|
||||
code: Mapped[str] = mapped_column(String(8), primary_key=True)
|
||||
nom: Mapped[str] = mapped_column(String(64), unique=True)
|
||||
couleur: Mapped[str] = mapped_column(String(7))
|
||||
bloc_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_bloc.id"))
|
||||
|
||||
bloc: Mapped[BlocLegislatives2024] = relationship(BlocLegislatives2024, back_populates="nuances")
|
||||
|
||||
candidats: Mapped[List["CandidatLegislatives2024"]] = relationship(
|
||||
"CandidatLegislatives2024", back_populates="nuance")
|
||||
|
||||
resultats_nationaux: Mapped[List["VoixFranceLegislatives2024"]] = relationship(
|
||||
"VoixFranceLegislatives2024", back_populates="nuance")
|
||||
resultats_par_region: Mapped[List["VoixRegionLegislatives2024"]] = relationship(
|
||||
"VoixRegionLegislatives2024", back_populates="nuance")
|
||||
resultats_par_departement: Mapped[List["VoixDepartementLegislatives2024"]] = relationship(
|
||||
"VoixDepartementLegislatives2024", back_populates="nuance")
|
||||
resultats_par_commune: Mapped[List["VoixCommuneLegislatives2024"]] = relationship(
|
||||
"VoixCommuneLegislatives2024", back_populates="nuance")
|
||||
|
||||
|
||||
class CandidatLegislatives2024(Base):
|
||||
class Genre(enum.Enum):
|
||||
MASCULIN = "M"
|
||||
FEMININ = "F"
|
||||
|
||||
__tablename__ = "legislatives_2024_candidat"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
circonscription_id: Mapped[str] = mapped_column(ForeignKey("circonscription.id"))
|
||||
numero: Mapped[int] = mapped_column(Integer())
|
||||
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code"))
|
||||
bloc_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_bloc.id"))
|
||||
nom: Mapped[str] = mapped_column(String(256))
|
||||
prenom: Mapped[str] = mapped_column(String(256))
|
||||
sexe: Mapped[str] = mapped_column(Enum(Genre))
|
||||
date_naissance: Mapped[date] = mapped_column(Date())
|
||||
profession: Mapped[str] = mapped_column(String(256))
|
||||
sortant: Mapped[bool] = mapped_column(Boolean())
|
||||
nom_suppleance: Mapped[str] = mapped_column(String(256))
|
||||
prenom_suppleance: Mapped[str] = mapped_column(String(256))
|
||||
sexe_suppleance: Mapped[str] = mapped_column(Enum(Genre))
|
||||
date_naissance_suppleance: Mapped[date] = mapped_column(Date())
|
||||
sortant_suppleance: Mapped[bool] = mapped_column(Boolean())
|
||||
|
||||
circonscription: Mapped[Circonscription] = relationship(
|
||||
"Circonscription", back_populates="candidats_legislatives_2024")
|
||||
nuance: Mapped[NuanceLegislatives2024] = relationship(NuanceLegislatives2024, back_populates="candidats")
|
||||
bloc: Mapped[BlocLegislatives2024] = relationship(BlocLegislatives2024, back_populates="candidats")
|
||||
resultats_par_circonscription: Mapped[List["VoixCirconscriptionLegislatives2024"]] = relationship(
|
||||
"VoixCirconscriptionLegislatives2024", back_populates="candidat")
|
||||
resultats_par_bureau_vote: Mapped[List["VoixBureauVoteLegislatives2024"]] = relationship(
|
||||
"VoixBureauVoteLegislatives2024", back_populates="candidat")
|
||||
|
||||
|
||||
class ResultatsFranceLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_resultats_france"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
resultats_regions: Mapped[List["ResultatsRegionLegislatives2024"]] = relationship(
|
||||
"ResultatsRegionLegislatives2024", back_populates="resultats_france")
|
||||
voix: Mapped[List["VoixFranceLegislatives2024"]] = relationship(
|
||||
"VoixFranceLegislatives2024", back_populates="resultats_france")
|
||||
|
||||
|
||||
class ResultatsRegionLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_resultats_region"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
region_id: Mapped[str] = mapped_column(ForeignKey("region.code_insee"))
|
||||
resultats_france_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_france.id"))
|
||||
inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
region = relationship(Region, back_populates="resultats_legislatives_2024")
|
||||
resultats_france = relationship(ResultatsFranceLegislatives2024, back_populates="resultats_regions")
|
||||
resultats_departements: Mapped[List["ResultatsDepartementLegislatives2024"]] = relationship(
|
||||
"ResultatsDepartementLegislatives2024", back_populates="resultats_region")
|
||||
voix: Mapped[List["VoixRegionLegislatives2024"]] = relationship(
|
||||
"VoixRegionLegislatives2024", back_populates="resultats_region")
|
||||
|
||||
|
||||
class ResultatsDepartementLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_resultats_departement"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
dpt_id: Mapped[str] = mapped_column(ForeignKey("departement.code_insee"))
|
||||
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_region.id"), nullable=True)
|
||||
inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
departement = relationship(Departement, back_populates="resultats_legislatives_2024")
|
||||
resultats_region = relationship(ResultatsRegionLegislatives2024, back_populates="resultats_departements")
|
||||
resultats_communes: Mapped[List["ResultatsCommuneLegislatives2024"]] = relationship(
|
||||
"ResultatsCommuneLegislatives2024", back_populates="resultats_departement")
|
||||
resultats_circonscriptions: Mapped[List["ResultatsCirconscriptionLegislatives2024"]] = relationship(
|
||||
"ResultatsCirconscriptionLegislatives2024", back_populates="resultats_departement")
|
||||
voix: Mapped[List["VoixDepartementLegislatives2024"]] = relationship(
|
||||
"VoixDepartementLegislatives2024", back_populates="resultats_departement")
|
||||
|
||||
|
||||
class ResultatsCirconscriptionLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_resultats_circonscription"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
circo_id: Mapped[str] = mapped_column(ForeignKey("circonscription.id"))
|
||||
resultats_departement_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_departement.id"))
|
||||
inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
circonscription = relationship("Circonscription", back_populates="resultats_legislatives_2024")
|
||||
resultats_departement = relationship(ResultatsDepartementLegislatives2024,
|
||||
back_populates="resultats_circonscriptions")
|
||||
resultats_bureaux_vote: Mapped[List["ResultatsBureauVoteLegislatives2024"]] = relationship(
|
||||
"ResultatsBureauVoteLegislatives2024", back_populates="resultats_circonscription")
|
||||
voix: Mapped[List["VoixCirconscriptionLegislatives2024"]] = relationship(
|
||||
"VoixCirconscriptionLegislatives2024", back_populates="resultats_circonscription")
|
||||
|
||||
|
||||
class ResultatsCommuneLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_resultats_commune"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
commune_id: Mapped[str] = mapped_column(ForeignKey("commune.code_insee"))
|
||||
resultats_dpt_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_departement.id"))
|
||||
inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
commune = relationship(Commune, back_populates="resultats_legislatives_2024")
|
||||
resultats_departement = relationship(ResultatsDepartementLegislatives2024, back_populates="resultats_communes")
|
||||
resultats_bureaux_vote: Mapped[List["ResultatsBureauVoteLegislatives2024"]] = relationship(
|
||||
"ResultatsBureauVoteLegislatives2024", back_populates="resultats_commune")
|
||||
voix: Mapped[List["VoixCommuneLegislatives2024"]] = relationship(
|
||||
"VoixCommuneLegislatives2024", back_populates="resultats_commune")
|
||||
|
||||
|
||||
class ResultatsBureauVoteLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_resultats_bureau_vote"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
bv_id: Mapped[str] = mapped_column(ForeignKey("bureau_vote.id"))
|
||||
resultats_commune_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_commune.id"))
|
||||
resultats_circo_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_circonscription.id"),
|
||||
nullable=True)
|
||||
inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
bureau_vote = relationship("BureauVote", back_populates="resultats_legislatives_2024")
|
||||
resultats_commune = relationship(ResultatsCommuneLegislatives2024, back_populates="resultats_bureaux_vote")
|
||||
resultats_circonscription = relationship(ResultatsCirconscriptionLegislatives2024,
|
||||
back_populates="resultats_bureaux_vote")
|
||||
voix: Mapped[List["VoixBureauVoteLegislatives2024"]] = relationship(
|
||||
"VoixBureauVoteLegislatives2024", back_populates="resultats_bureau_vote")
|
||||
|
||||
|
||||
class VoixFranceLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_voix_france"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code"))
|
||||
resultats_france_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_france.id"))
|
||||
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
nuance: Mapped[NuanceLegislatives2024] = relationship(
|
||||
NuanceLegislatives2024, back_populates="resultats_nationaux")
|
||||
resultats_france: Mapped[ResultatsFranceLegislatives2024] = relationship(
|
||||
ResultatsFranceLegislatives2024, back_populates="voix")
|
||||
|
||||
|
||||
class VoixRegionLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_voix_region"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code"))
|
||||
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_region.id"))
|
||||
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
nuance: Mapped[NuanceLegislatives2024] = relationship(
|
||||
NuanceLegislatives2024, back_populates="resultats_par_region")
|
||||
resultats_region: Mapped[ResultatsRegionLegislatives2024] = relationship(
|
||||
ResultatsRegionLegislatives2024, back_populates="voix")
|
||||
|
||||
|
||||
class VoixDepartementLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_voix_departement"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code"))
|
||||
resultats_departement_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_departement.id"))
|
||||
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
nuance: Mapped[NuanceLegislatives2024] = relationship(
|
||||
NuanceLegislatives2024, back_populates="resultats_par_departement")
|
||||
resultats_departement: Mapped[ResultatsDepartementLegislatives2024] = relationship(
|
||||
ResultatsDepartementLegislatives2024, back_populates="voix")
|
||||
|
||||
|
||||
class VoixCirconscriptionLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_voix_circonscription"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
candidat_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_candidat.id"))
|
||||
resultats_circonscription_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("legislatives_2024_resultats_circonscription.id"))
|
||||
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
candidat: Mapped[CandidatLegislatives2024] = relationship(
|
||||
CandidatLegislatives2024, back_populates="resultats_par_circonscription")
|
||||
resultats_circonscription: Mapped[ResultatsCirconscriptionLegislatives2024] = relationship(
|
||||
ResultatsCirconscriptionLegislatives2024, back_populates="voix")
|
||||
|
||||
|
||||
class VoixCommuneLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_voix_commune"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code"))
|
||||
resultats_commune_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_commune.id"))
|
||||
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
nuance: Mapped[NuanceLegislatives2024] = relationship(
|
||||
NuanceLegislatives2024, back_populates="resultats_par_commune")
|
||||
resultats_commune: Mapped[ResultatsCommuneLegislatives2024] = relationship(
|
||||
ResultatsCommuneLegislatives2024, back_populates="voix")
|
||||
|
||||
|
||||
class VoixBureauVoteLegislatives2024(Base):
|
||||
__tablename__ = "legislatives_2024_voix_bureau_vote"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
candidat_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_candidat.id"))
|
||||
resultats_bureau_vote_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_bureau_vote.id"))
|
||||
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
candidat: Mapped[CandidatLegislatives2024] = relationship(CandidatLegislatives2024,
|
||||
back_populates="resultats_par_bureau_vote")
|
||||
resultats_bureau_vote: Mapped[ResultatsBureauVoteLegislatives2024] = relationship(
|
||||
ResultatsBureauVoteLegislatives2024, back_populates="voix")
|
@ -0,0 +1 @@
|
||||
from . import import_candidats
|
@ -3,6 +3,7 @@ import datetime
|
||||
|
||||
from sqlalchemy import Engine, select
|
||||
from sqlalchemy.orm import Session
|
||||
from tqdm import tqdm
|
||||
|
||||
from nupes.cache import get_file
|
||||
from nupes.models.legislatives2024 import BlocLegislatives2024, NuanceLegislatives2024, CandidatLegislatives2024
|
||||
@ -30,36 +31,36 @@ def creer_blocs(engine: Engine, verbose: bool = False) -> None:
|
||||
|
||||
def creer_nuances(engine: Engine, verbose: bool = False) -> None:
|
||||
nuances = [
|
||||
{"code": "EXG", "nom": "Extrême gauche", "couleur": "#BB0000", "bloc": 1},
|
||||
{"code": "COM", "nom": "Parti communiste français", "couleur": "#DD0000", "bloc": 1},
|
||||
{"code": "FI", "nom": "La France insoumise", "couleur": "#CC2443", "bloc": 1},
|
||||
{"code": "SOC", "nom": "Parti socialiste", "couleur": "#FF8080", "bloc": 1},
|
||||
{"code": "UG", "nom": "Union de la gauche", "couleur": "#E4032E", "bloc": 1},
|
||||
{"code": "PRG", "nom": "Parti radical de gauche", "couleur": "#FFD1DC", "bloc": 1},
|
||||
{"code": "VEC", "nom": "Les Écologistes", "couleur": "#00C000", "bloc": 1},
|
||||
{"code": "DVG", "nom": "Divers gauche", "couleur": "#FFC0C0", "bloc": 1},
|
||||
{"code": "ECO", "nom": "Écologistes", "couleur": "#77FF77", "bloc": 5},
|
||||
{"code": "REG", "nom": "Régionalistes", "couleur": "#DCBFA3", "bloc": 5},
|
||||
{"code": "DIV", "nom": "Divers", "couleur": "#DCDCDC", "bloc": 5},
|
||||
{"code": "REN", "nom": "Renaissance", "couleur": "#FFEB00", "bloc": 2},
|
||||
{"code": "ENS", "nom": "Ensemble ! (Majorité présidentielle)", "couleur": "#45B3AB", "bloc": 2},
|
||||
{"code": "MDM", "nom": "Modem", "couleur": "#FF9900", "bloc": 2},
|
||||
{"code": "HOR", "nom": "Horizons", "couleur": "#0001B8", "bloc": 2},
|
||||
{"code": "DVC", "nom": "Divers centre", "couleur": "#FAC577", "bloc": 2},
|
||||
{"code": "UDI", "nom": "Union des Démocrates et Indépendants", "couleur": "#00FFFF", "bloc": 3},
|
||||
{"code": "LR", "nom": "Les Républicains", "couleur": "#0066CC", "bloc": 3},
|
||||
{"code": "DVD", "nom": "Divers droite", "couleur": "#26C4EC", "bloc": 3},
|
||||
{"code": "DSV", "nom": "Droite souverainiste", "couleur": "#8040C0", "bloc": 4},
|
||||
{"code": "RN", "nom": "Rassemblement national", "couleur": "#0D378A", "bloc": 4},
|
||||
{"code": "REC", "nom": "Reconquête !", "couleur": "#404040", "bloc": 4},
|
||||
{"code": "EXD", "nom": "Extrême droite", "couleur": "#404040", "bloc": 4},
|
||||
{"code": "UXD", "nom": "Union de l'extrême droite", "couleur": "#404040", "bloc": 4},
|
||||
{"code": "EXG", "nom": "Extrême gauche", "couleur": "#BB0000", "bloc_id": 1},
|
||||
{"code": "COM", "nom": "Parti communiste français", "couleur": "#DD0000", "bloc_id": 1},
|
||||
{"code": "FI", "nom": "La France insoumise", "couleur": "#CC2443", "bloc_id": 1},
|
||||
{"code": "SOC", "nom": "Parti socialiste", "couleur": "#FF8080", "bloc_id": 1},
|
||||
{"code": "RDG", "nom": "Parti radical de gauche", "couleur": "#FFD1DC", "bloc_id": 1},
|
||||
{"code": "UG", "nom": "Union de la gauche", "couleur": "#E4032E", "bloc_id": 1},
|
||||
{"code": "VEC", "nom": "Les Écologistes", "couleur": "#00C000", "bloc_id": 1},
|
||||
{"code": "DVG", "nom": "Divers gauche", "couleur": "#FFC0C0", "bloc_id": 1},
|
||||
{"code": "ECO", "nom": "Écologistes", "couleur": "#77FF77", "bloc_id": 5},
|
||||
{"code": "REG", "nom": "Régionalistes", "couleur": "#DCBFA3", "bloc_id": 5},
|
||||
{"code": "DIV", "nom": "Divers", "couleur": "#DCDCDC", "bloc_id": 5},
|
||||
{"code": "REN", "nom": "Renaissance", "couleur": "#FFEB00", "bloc_id": 2},
|
||||
{"code": "ENS", "nom": "Ensemble ! (Majorité présidentielle)", "couleur": "#45B3AB", "bloc_id": 2},
|
||||
{"code": "MDM", "nom": "Modem", "couleur": "#FF9900", "bloc_id": 2},
|
||||
{"code": "HOR", "nom": "Horizons", "couleur": "#0001B8", "bloc_id": 2},
|
||||
{"code": "DVC", "nom": "Divers centre", "couleur": "#FAC577", "bloc_id": 2},
|
||||
{"code": "UDI", "nom": "Union des Démocrates et Indépendants", "couleur": "#00FFFF", "bloc_id": 3},
|
||||
{"code": "LR", "nom": "Les Républicains", "couleur": "#0066CC", "bloc_id": 3},
|
||||
{"code": "DVD", "nom": "Divers droite", "couleur": "#26C4EC", "bloc_id": 3},
|
||||
{"code": "DSV", "nom": "Droite souverainiste", "couleur": "#8040C0", "bloc_id": 4},
|
||||
{"code": "RN", "nom": "Rassemblement national", "couleur": "#0D378A", "bloc_id": 4},
|
||||
{"code": "REC", "nom": "Reconquête !", "couleur": "#404040", "bloc_id": 4},
|
||||
{"code": "EXD", "nom": "Extrême droite", "couleur": "#404040", "bloc_id": 4},
|
||||
{"code": "UXD", "nom": "Union de l'extrême droite", "couleur": "#404040", "bloc_id": 4},
|
||||
]
|
||||
|
||||
with Session(engine) as session:
|
||||
for nuance_dict in nuances:
|
||||
if nuance := session.execute(select(NuanceLegislatives2024)
|
||||
.filter_by(code=nuance_dict["code"])).scalar_one_or_none():
|
||||
.filter_by(code=nuance_dict["code"])).scalar_one_or_none():
|
||||
nuance.nom = nuance_dict["nom"]
|
||||
nuance.couleur = nuance_dict["couleur"]
|
||||
else:
|
||||
@ -68,6 +69,90 @@ def creer_nuances(engine: Engine, verbose: bool = False) -> None:
|
||||
session.commit()
|
||||
|
||||
|
||||
def importer_candidats(engine: Engine, verbose: bool = False) -> None:
|
||||
DATASET_URL = "https://www.data.gouv.fr/fr/datasets/r/e02a62a1-9f4b-49d6-bb32-05dc4da8c581"
|
||||
file = get_file(DATASET_URL, "candidats_legislatives_2024.csv")
|
||||
|
||||
with file.open('r') as f:
|
||||
with Session(engine) as session:
|
||||
reader = csv.DictReader(f)
|
||||
for line in tqdm(reader, desc="Candidat⋅es", disable=not verbose):
|
||||
line: dict[str, str]
|
||||
numero_panneau = int(line.get("Numéro de panneau"))
|
||||
code_dpt = line.get("Code département").zfill(2)
|
||||
|
||||
match code_dpt:
|
||||
case "ZA":
|
||||
code_dpt = "971"
|
||||
case "ZB":
|
||||
code_dpt = "972"
|
||||
case "ZC":
|
||||
code_dpt = "973"
|
||||
case "ZD":
|
||||
code_dpt = "974"
|
||||
case "ZS":
|
||||
code_dpt = "975"
|
||||
case "ZM":
|
||||
code_dpt = "976"
|
||||
case "ZX":
|
||||
code_dpt = "977"
|
||||
case "ZW":
|
||||
code_dpt = "986"
|
||||
case "ZP":
|
||||
code_dpt = "987"
|
||||
case "ZN":
|
||||
code_dpt = "988"
|
||||
|
||||
code_circo = line.get("Code circonscription")[-2:]
|
||||
circo_id = f"{code_dpt}-{code_circo}"
|
||||
|
||||
nuance_id = line.get("Code nuance")
|
||||
nuance = session.execute(select(NuanceLegislatives2024).filter_by(code=nuance_id)).scalar_one()
|
||||
|
||||
if candidat := session.execute(select(CandidatLegislatives2024)
|
||||
.filter_by(circonscription_id=circo_id, numero=numero_panneau)) \
|
||||
.scalar_one_or_none():
|
||||
candidat.nuance_id = nuance_id
|
||||
candidat.bloc_id = nuance.bloc_id
|
||||
candidat.nom = line['Nom du candidat']
|
||||
candidat.prenom = line['Prénom du candidat']
|
||||
candidat.sexe = CandidatLegislatives2024.Genre(line['Sexe du candidat'])
|
||||
candidat.date_naissance = datetime.datetime.strptime(line['Date de naissance du candidat'],
|
||||
"%d/%m/%Y").date()
|
||||
candidat.profession = line['Profession']
|
||||
candidat.sortant = line['Sortant'] == "OUI"
|
||||
candidat.nom_suppleance = line['Nom remplaçant']
|
||||
candidat.prenom_suppleance = line['Prénom remplaçant']
|
||||
candidat.sexe_suppleance = CandidatLegislatives2024.Genre(line['Sexe remplaçant'])
|
||||
candidat.date_naissance_suppleance = datetime.datetime.strptime(
|
||||
line['Date de naissance remplaçant'], "%d/%m/%Y").date()
|
||||
candidat.sortant = line['Sortant remplaçant'] == "OUI"
|
||||
else:
|
||||
candidat = CandidatLegislatives2024(
|
||||
circonscription_id=circo_id,
|
||||
numero=numero_panneau,
|
||||
nuance_id=nuance_id,
|
||||
bloc_id=nuance.bloc_id,
|
||||
nom=line['Nom du candidat'],
|
||||
prenom=line['Prénom du candidat'],
|
||||
sexe=CandidatLegislatives2024.Genre(line['Sexe du candidat']).name,
|
||||
date_naissance=datetime.datetime.strptime(line['Date de naissance du candidat'],
|
||||
"%d/%m/%Y").date(),
|
||||
profession=line['Profession'],
|
||||
sortant=line['Sortant'] == "OUI",
|
||||
nom_suppleance=line['Nom remplaçant'],
|
||||
prenom_suppleance=line['Prénom remplaçant'],
|
||||
sexe_suppleance=CandidatLegislatives2024.Genre(line['Sexe remplaçant']).name,
|
||||
date_naissance_suppleance=datetime.datetime.strptime(line['Date de naissance remplaçant'],
|
||||
"%d/%m/%Y").date(),
|
||||
sortant_suppleance=line['Sortant remplaçant'] == "OUI",
|
||||
)
|
||||
session.add(candidat)
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
def run(engine: Engine, verbose: bool = False) -> None:
|
||||
creer_blocs(engine, verbose)
|
||||
creer_nuances(engine, verbose)
|
||||
importer_candidats(engine, verbose)
|
||||
|
Loading…
Reference in New Issue
Block a user