nupes-elections/nupes/models/legislatives2022.py

331 lines
18 KiB
Python
Raw Normal View History

2024-06-20 10:17:56 +00:00
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
2024-06-20 14:48:34 +00:00
from nupes.models.base import Genre
2024-06-20 10:17:56 +00:00
class BlocLegislatives2022(Base):
__tablename__ = "legislatives_2022_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["CandidatLegislatives2022"]] = relationship("CandidatLegislatives2022",
back_populates="bloc")
nuances: Mapped[List["NuanceLegislatives2022"]] = relationship(
"NuanceLegislatives2022", back_populates="bloc")
class NuanceLegislatives2022(Base):
__tablename__ = "legislatives_2022_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_2022_bloc.id"))
bloc: Mapped[BlocLegislatives2022] = relationship(BlocLegislatives2022, back_populates="nuances")
candidats: Mapped[List["CandidatLegislatives2022"]] = relationship(
"CandidatLegislatives2022", back_populates="nuance")
resultats_nationaux: Mapped[List["VoixFranceLegislatives2022"]] = relationship(
"VoixFranceLegislatives2022", back_populates="nuance")
resultats_par_region: Mapped[List["VoixRegionLegislatives2022"]] = relationship(
"VoixRegionLegislatives2022", back_populates="nuance")
resultats_par_departement: Mapped[List["VoixDepartementLegislatives2022"]] = relationship(
"VoixDepartementLegislatives2022", back_populates="nuance")
resultats_par_commune: Mapped[List["VoixCommuneLegislatives2022"]] = relationship(
"VoixCommuneLegislatives2022", back_populates="nuance")
class CandidatLegislatives2022(Base):
__tablename__ = "legislatives_2022_candidat"
id: Mapped[int] = mapped_column(primary_key=True)
circonscription_id: Mapped[str] = mapped_column(ForeignKey("circonscription.id"))
numero: Mapped[int] = mapped_column(Integer())
2024-06-20 12:45:53 +00:00
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2022_nuance.code"))
2024-06-20 10:17:56 +00:00
bloc_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_bloc.id"))
nom: Mapped[str] = mapped_column(String(256))
prenom: Mapped[str] = mapped_column(String(256))
2024-06-20 14:55:16 +00:00
sexe: Mapped[str] = mapped_column(Enum(Genre, name="legislatives_2022_genre"))
2024-06-20 10:17:56 +00:00
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))
2024-06-20 14:55:16 +00:00
sexe_suppleance: Mapped[str] = mapped_column(Enum(Genre, name="legislatives_2022_genre"))
2024-06-20 10:17:56 +00:00
date_naissance_suppleance: Mapped[date] = mapped_column(Date())
sortant_suppleance: Mapped[bool] = mapped_column(Boolean())
circonscription: Mapped[Circonscription] = relationship(
"Circonscription", back_populates="candidats_legislatives_2022")
nuance: Mapped[NuanceLegislatives2022] = relationship(NuanceLegislatives2022, back_populates="candidats")
bloc: Mapped[BlocLegislatives2022] = relationship(BlocLegislatives2022, back_populates="candidats")
resultats_par_circonscription: Mapped[List["VoixCirconscriptionLegislatives2022"]] = relationship(
"VoixCirconscriptionLegislatives2022", back_populates="candidat")
resultats_par_bureau_vote: Mapped[List["VoixBureauVoteLegislatives2022"]] = relationship(
"VoixBureauVoteLegislatives2022", back_populates="candidat")
class ResultatsFranceLegislatives2022(Base):
__tablename__ = "legislatives_2022_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["ResultatsRegionLegislatives2022"]] = relationship(
"ResultatsRegionLegislatives2022", back_populates="resultats_france")
voix: Mapped[List["VoixFranceLegislatives2022"]] = relationship(
"VoixFranceLegislatives2022", back_populates="resultats_france")
class ResultatsRegionLegislatives2022(Base):
__tablename__ = "legislatives_2022_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_2022_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_2022")
resultats_france = relationship(ResultatsFranceLegislatives2022, back_populates="resultats_regions")
resultats_departements: Mapped[List["ResultatsDepartementLegislatives2022"]] = relationship(
"ResultatsDepartementLegislatives2022", back_populates="resultats_region")
voix: Mapped[List["VoixRegionLegislatives2022"]] = relationship(
"VoixRegionLegislatives2022", back_populates="resultats_region")
class ResultatsDepartementLegislatives2022(Base):
__tablename__ = "legislatives_2022_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_2022_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_2022")
resultats_region = relationship(ResultatsRegionLegislatives2022, back_populates="resultats_departements")
resultats_communes: Mapped[List["ResultatsCommuneLegislatives2022"]] = relationship(
"ResultatsCommuneLegislatives2022", back_populates="resultats_departement")
resultats_circonscriptions: Mapped[List["ResultatsCirconscriptionLegislatives2022"]] = relationship(
"ResultatsCirconscriptionLegislatives2022", back_populates="resultats_departement")
voix: Mapped[List["VoixDepartementLegislatives2022"]] = relationship(
"VoixDepartementLegislatives2022", back_populates="resultats_departement")
class ResultatsCirconscriptionLegislatives2022(Base):
__tablename__ = "legislatives_2022_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_2022_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_2022")
resultats_departement = relationship(ResultatsDepartementLegislatives2022,
back_populates="resultats_circonscriptions")
resultats_bureaux_vote: Mapped[List["ResultatsBureauVoteLegislatives2022"]] = relationship(
"ResultatsBureauVoteLegislatives2022", back_populates="resultats_circonscription")
voix: Mapped[List["VoixCirconscriptionLegislatives2022"]] = relationship(
"VoixCirconscriptionLegislatives2022", back_populates="resultats_circonscription")
class ResultatsCommuneLegislatives2022(Base):
__tablename__ = "legislatives_2022_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_2022_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_2022")
resultats_departement = relationship(ResultatsDepartementLegislatives2022, back_populates="resultats_communes")
resultats_bureaux_vote: Mapped[List["ResultatsBureauVoteLegislatives2022"]] = relationship(
"ResultatsBureauVoteLegislatives2022", back_populates="resultats_commune")
voix: Mapped[List["VoixCommuneLegislatives2022"]] = relationship(
"VoixCommuneLegislatives2022", back_populates="resultats_commune")
class ResultatsBureauVoteLegislatives2022(Base):
__tablename__ = "legislatives_2022_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_2022_resultats_commune.id"))
resultats_circo_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_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_2022")
resultats_commune = relationship(ResultatsCommuneLegislatives2022, back_populates="resultats_bureaux_vote")
resultats_circonscription = relationship(ResultatsCirconscriptionLegislatives2022,
back_populates="resultats_bureaux_vote")
voix: Mapped[List["VoixBureauVoteLegislatives2022"]] = relationship(
"VoixBureauVoteLegislatives2022", back_populates="resultats_bureau_vote")
class VoixFranceLegislatives2022(Base):
__tablename__ = "legislatives_2022_voix_france"
id: Mapped[int] = mapped_column(primary_key=True)
2024-06-20 12:45:53 +00:00
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2022_nuance.code"))
resultats_france_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_resultats_france.id"))
2024-06-20 10:17:56 +00:00
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
nuance: Mapped[NuanceLegislatives2022] = relationship(
NuanceLegislatives2022, back_populates="resultats_nationaux")
resultats_france: Mapped[ResultatsFranceLegislatives2022] = relationship(
ResultatsFranceLegislatives2022, back_populates="voix")
class VoixRegionLegislatives2022(Base):
__tablename__ = "legislatives_2022_voix_region"
id: Mapped[int] = mapped_column(primary_key=True)
2024-06-20 12:45:53 +00:00
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2022_nuance.code"))
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_resultats_region.id"))
2024-06-20 10:17:56 +00:00
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
nuance: Mapped[NuanceLegislatives2022] = relationship(
NuanceLegislatives2022, back_populates="resultats_par_region")
resultats_region: Mapped[ResultatsRegionLegislatives2022] = relationship(
ResultatsRegionLegislatives2022, back_populates="voix")
class VoixDepartementLegislatives2022(Base):
__tablename__ = "legislatives_2022_voix_departement"
id: Mapped[int] = mapped_column(primary_key=True)
2024-06-20 12:45:53 +00:00
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2022_nuance.code"))
resultats_departement_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_resultats_departement.id"))
2024-06-20 10:17:56 +00:00
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
nuance: Mapped[NuanceLegislatives2022] = relationship(
NuanceLegislatives2022, back_populates="resultats_par_departement")
resultats_departement: Mapped[ResultatsDepartementLegislatives2022] = relationship(
ResultatsDepartementLegislatives2022, back_populates="voix")
class VoixCirconscriptionLegislatives2022(Base):
__tablename__ = "legislatives_2022_voix_circonscription"
id: Mapped[int] = mapped_column(primary_key=True)
candidat_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_candidat.id"))
resultats_circonscription_id: Mapped[int] = mapped_column(
2024-06-20 12:45:53 +00:00
ForeignKey("legislatives_2022_resultats_circonscription.id"))
2024-06-20 10:17:56 +00:00
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
candidat: Mapped[CandidatLegislatives2022] = relationship(
CandidatLegislatives2022, back_populates="resultats_par_circonscription")
resultats_circonscription: Mapped[ResultatsCirconscriptionLegislatives2022] = relationship(
ResultatsCirconscriptionLegislatives2022, back_populates="voix")
class VoixCommuneLegislatives2022(Base):
__tablename__ = "legislatives_2022_voix_commune"
id: Mapped[int] = mapped_column(primary_key=True)
nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2022_nuance.code"))
2024-06-20 12:45:53 +00:00
resultats_commune_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_resultats_commune.id"))
2024-06-20 10:17:56 +00:00
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
nuance: Mapped[NuanceLegislatives2022] = relationship(
NuanceLegislatives2022, back_populates="resultats_par_commune")
resultats_commune: Mapped[ResultatsCommuneLegislatives2022] = relationship(
ResultatsCommuneLegislatives2022, back_populates="voix")
class VoixBureauVoteLegislatives2022(Base):
__tablename__ = "legislatives_2022_voix_bureau_vote"
id: Mapped[int] = mapped_column(primary_key=True)
candidat_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_candidat.id"))
2024-06-20 12:45:53 +00:00
resultats_bureau_vote_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2022_resultats_bureau_vote.id"))
2024-06-20 10:17:56 +00:00
voix_t1: Mapped[int] = mapped_column(Integer(), default=0)
voix_t2: Mapped[int] = mapped_column(Integer(), default=0)
candidat: Mapped[CandidatLegislatives2022] = relationship(CandidatLegislatives2022,
back_populates="resultats_par_bureau_vote")
resultats_bureau_vote: Mapped[ResultatsBureauVoteLegislatives2022] = relationship(
ResultatsBureauVoteLegislatives2022, back_populates="voix")