Préparation de l'analyse de résultats
This commit is contained in:
@ -5,7 +5,7 @@ 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
|
||||
from nupes.models import Base, Region, Departement, Commune
|
||||
|
||||
|
||||
class Bloc(Base):
|
||||
@ -33,12 +33,22 @@ class Liste(Base):
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
nom: Mapped[str] = mapped_column(String(256), unique=True)
|
||||
nom_majuscules: Mapped[str] = mapped_column(String(256), unique=True, nullable=True)
|
||||
numero: Mapped[int] = mapped_column(Integer(), unique=True)
|
||||
nuance_id: Mapped[str] = mapped_column(ForeignKey("nuance2024.code"))
|
||||
bloc_id: Mapped[int] = mapped_column(ForeignKey("bloc2024.id"))
|
||||
|
||||
nuance: Mapped[Nuance] = relationship(Nuance, back_populates="listes")
|
||||
bloc: Mapped[Bloc] = relationship(Bloc, back_populates="listes")
|
||||
candidats: Mapped[List["Candidat"]] = relationship("Candidat", back_populates="liste")
|
||||
|
||||
resultats_nationaux: Mapped[List["VoixListeFrance"]] = relationship("VoixListeFrance", back_populates="liste")
|
||||
resultats_par_region: Mapped[List["VoixListeRegion"]] = relationship("VoixListeRegion", back_populates="liste")
|
||||
resultats_par_departement: Mapped[List["VoixListeDepartement"]] = relationship("VoixListeDepartement",
|
||||
back_populates="liste")
|
||||
resultats_par_commune: Mapped[List["VoixListeCommune"]] = relationship("VoixListeCommune", back_populates="liste")
|
||||
resultats_par_bureau_vote: Mapped[List["VoixListeBureauVote"]] = relationship("VoixListeBureauVote",
|
||||
back_populates="liste")
|
||||
|
||||
|
||||
class Candidat(Base):
|
||||
@ -68,3 +78,157 @@ class Candidat(Base):
|
||||
profession: Mapped[str] = mapped_column(String(256))
|
||||
code_personnalite: Mapped[str] = mapped_column(Enum(Personnalite))
|
||||
sortant: Mapped[bool] = mapped_column(Boolean())
|
||||
|
||||
liste: Mapped[Liste] = relationship(Liste, back_populates="candidats")
|
||||
|
||||
|
||||
class ResultatsFrance(Base):
|
||||
__tablename__ = "resultats2024_france"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
resultats_regions: Mapped[List["ResultatsRegion"]] = relationship("ResultatsRegion",
|
||||
back_populates="resultats_france")
|
||||
voix_listes: Mapped[List["VoixListeFrance"]] = relationship("VoixListeFrance", back_populates="resultats_france")
|
||||
|
||||
|
||||
class ResultatsRegion(Base):
|
||||
__tablename__ = "resultats2024_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("resultats2024_france.id"))
|
||||
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
region = relationship(Region, back_populates="resultats2024")
|
||||
resultats_france = relationship(ResultatsFrance, back_populates="resultats_regions")
|
||||
resultats_departements: Mapped[List["ResultatsDepartement"]] = relationship("ResultatsDepartement",
|
||||
back_populates="resultats_region")
|
||||
voix_listes: Mapped[List["VoixListeRegion"]] = relationship("VoixListeRegion", back_populates="resultats_region")
|
||||
|
||||
|
||||
class ResultatsDepartement(Base):
|
||||
__tablename__ = "resultats2024_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("resultats2024_region.id"))
|
||||
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
departement = relationship(Departement, back_populates="resultats2024")
|
||||
resultats_region = relationship(ResultatsRegion, back_populates="resultats_departements")
|
||||
resultats_communes: Mapped[List["ResultatsCommune"]] = relationship("ResultatsCommune",
|
||||
back_populates="resultats_departement")
|
||||
voix_listes: Mapped[List["VoixListeDepartement"]] = relationship("VoixListeDepartement",
|
||||
back_populates="resultats_departement")
|
||||
|
||||
|
||||
class ResultatsCommune(Base):
|
||||
__tablename__ = "resultats2024_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("resultats2024_departement.id"))
|
||||
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
commune = relationship(Commune, back_populates="resultats2024")
|
||||
resultats_departement = relationship(ResultatsDepartement, back_populates="resultats_communes")
|
||||
resultats_bureaux_vote: Mapped[List["ResultatsBureauVote"]] = relationship("ResultatsBureauVote",
|
||||
back_populates="resultats_commune")
|
||||
voix_listes: Mapped[List["VoixListeCommune"]] = relationship("VoixListeCommune", back_populates="resultats_commune")
|
||||
|
||||
|
||||
class ResultatsBureauVote(Base):
|
||||
__tablename__ = "resultats2024_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("resultats2024_commune.id"))
|
||||
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
blancs: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
nuls: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
bureau_vote = relationship("BureauVote", back_populates="resultats2024")
|
||||
resultats_commune = relationship(ResultatsCommune, back_populates="resultats_bureaux_vote")
|
||||
voix_listes: Mapped[List["VoixListeBureauVote"]] = relationship("VoixListeBureauVote",
|
||||
back_populates="resultats_bureau_vote")
|
||||
|
||||
|
||||
class VoixListeFrance(Base):
|
||||
__tablename__ = "voix2024_france"
|
||||
|
||||
liste_id: Mapped[int] = mapped_column(ForeignKey("liste2024.id"), primary_key=True)
|
||||
resultats_france_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_france.id"), primary_key=True)
|
||||
voix: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
liste: Mapped[Liste] = relationship(Liste, back_populates="resultats_nationaux")
|
||||
resultats_france: Mapped[ResultatsFrance] = relationship(ResultatsFrance, back_populates="voix_listes")
|
||||
|
||||
|
||||
class VoixListeRegion(Base):
|
||||
__tablename__ = "voix2024_region"
|
||||
|
||||
liste_id: Mapped[int] = mapped_column(ForeignKey("liste2024.id"), primary_key=True)
|
||||
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_region.id"), primary_key=True)
|
||||
voix: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
liste: Mapped[Liste] = relationship(Liste, back_populates="resultats_par_region")
|
||||
resultats_region: Mapped[ResultatsRegion] = relationship(ResultatsRegion, back_populates="voix_listes")
|
||||
|
||||
|
||||
class VoixListeDepartement(Base):
|
||||
__tablename__ = "voix2024_departement"
|
||||
|
||||
liste_id: Mapped[int] = mapped_column(ForeignKey("liste2024.id"), primary_key=True)
|
||||
resultats_departement_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_departement.id"), primary_key=True)
|
||||
voix: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
liste: Mapped[Liste] = relationship(Liste, back_populates="resultats_par_departement")
|
||||
resultats_departement: Mapped[ResultatsDepartement] = relationship(ResultatsDepartement,
|
||||
back_populates="voix_listes")
|
||||
|
||||
|
||||
class VoixListeCommune(Base):
|
||||
__tablename__ = "voix2024_commune"
|
||||
|
||||
liste_id: Mapped[int] = mapped_column(ForeignKey("liste2024.id"), primary_key=True)
|
||||
resultats_commune_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_commune.id"), primary_key=True)
|
||||
voix: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
liste: Mapped[Liste] = relationship(Liste, back_populates="resultats_par_commune")
|
||||
resultats_commune: Mapped[ResultatsCommune] = relationship(ResultatsCommune, back_populates="voix_listes")
|
||||
|
||||
|
||||
class VoixListeBureauVote(Base):
|
||||
__tablename__ = "voix2024_bureau_vote"
|
||||
|
||||
liste_id: Mapped[int] = mapped_column(ForeignKey("liste2024.id"), primary_key=True)
|
||||
resultats_bureau_vote_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_bureau_vote.id"), primary_key=True)
|
||||
voix: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
||||
liste: Mapped[Liste] = relationship(Liste, back_populates="resultats_par_bureau_vote")
|
||||
resultats_bureau_vote: Mapped[ResultatsBureauVote] = relationship(ResultatsBureauVote, back_populates="voix_listes")
|
||||
|
@ -15,6 +15,8 @@ class Region(Base):
|
||||
|
||||
departements: Mapped[List["Departement"]] = relationship("Departement", back_populates="region")
|
||||
|
||||
resultats2024 = relationship("ResultatsRegion", back_populates="region")
|
||||
|
||||
|
||||
class Departement(Base):
|
||||
__tablename__ = "departement"
|
||||
@ -27,6 +29,8 @@ class Departement(Base):
|
||||
region: Mapped[Region] = relationship(Region, back_populates="departements")
|
||||
communes: Mapped[List["Commune"]] = relationship("Commune", back_populates="departement")
|
||||
|
||||
resultats2024 = relationship("ResultatsDepartement", back_populates="departement")
|
||||
|
||||
|
||||
class Commune(Base):
|
||||
__tablename__ = "commune"
|
||||
@ -39,6 +43,8 @@ class Commune(Base):
|
||||
departement: Mapped[Departement] = relationship(Departement, back_populates="communes")
|
||||
bureaux_vote: Mapped[List["BureauVote"]] = relationship("BureauVote", back_populates="commune")
|
||||
|
||||
resultats2024 = relationship("ResultatsCommune", back_populates="commune")
|
||||
|
||||
|
||||
class Circonscription(Base):
|
||||
__tablename__ = "circonscription"
|
||||
@ -64,3 +70,5 @@ class BureauVote(Base):
|
||||
|
||||
commune: Mapped[Commune] = relationship(Commune, back_populates="bureaux_vote")
|
||||
circonscription: Mapped[Circonscription] = relationship(Circonscription, back_populates="bureaux_vote")
|
||||
|
||||
resultats2024 = relationship("ResultatsBureauVote", back_populates="bureau_vote")
|
||||
|
Reference in New Issue
Block a user