Correction clés étrangères
This commit is contained in:
parent
828becbd4e
commit
58ffe8a46a
|
@ -1,8 +1,8 @@
|
||||||
"""Ajout des modèles de résultats pour les européennes 2024 + géométrie administrative
|
"""initial
|
||||||
|
|
||||||
Revision ID: 42ff9c981be7
|
Revision ID: a2c743418d84
|
||||||
Revises:
|
Revises:
|
||||||
Create Date: 2024-06-08 17:40:27.348858
|
Create Date: 2024-06-09 23:51:19.572272
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from typing import Sequence, Union
|
from typing import Sequence, Union
|
||||||
|
@ -12,7 +12,7 @@ import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision: str = '42ff9c981be7'
|
revision: str = 'a2c743418d84'
|
||||||
down_revision: Union[str, None] = None
|
down_revision: Union[str, None] = None
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
@ -63,7 +63,7 @@ def upgrade() -> None:
|
||||||
op.create_table('liste2024',
|
op.create_table('liste2024',
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('nom', sa.String(length=256), nullable=False),
|
sa.Column('nom', sa.String(length=256), nullable=False),
|
||||||
sa.Column('nom_majuscules', sa.String(length=256), nullable=False),
|
sa.Column('nom_majuscules', sa.String(length=256), nullable=True),
|
||||||
sa.Column('numero', sa.Integer(), nullable=False),
|
sa.Column('numero', sa.Integer(), nullable=False),
|
||||||
sa.Column('nuance_id', sa.String(length=8), nullable=False),
|
sa.Column('nuance_id', sa.String(length=8), nullable=False),
|
||||||
sa.Column('bloc_id', sa.Integer(), nullable=False),
|
sa.Column('bloc_id', sa.Integer(), nullable=False),
|
||||||
|
@ -120,7 +120,7 @@ def upgrade() -> None:
|
||||||
op.create_table('resultats2024_departement',
|
op.create_table('resultats2024_departement',
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('dpt_id', sa.String(length=3), nullable=False),
|
sa.Column('dpt_id', sa.String(length=3), nullable=False),
|
||||||
sa.Column('resultats_region_id', sa.Integer(), nullable=False),
|
sa.Column('resultats_region_id', sa.Integer(), nullable=True),
|
||||||
sa.Column('inscrits', sa.Integer(), nullable=False),
|
sa.Column('inscrits', sa.Integer(), nullable=False),
|
||||||
sa.Column('votants', sa.Integer(), nullable=False),
|
sa.Column('votants', sa.Integer(), nullable=False),
|
||||||
sa.Column('abstentions', sa.Integer(), nullable=False),
|
sa.Column('abstentions', sa.Integer(), nullable=False),
|
|
@ -47,8 +47,8 @@ function ResultatsTable({blocs, nuances, listes, resultats, siegesParListe}) {
|
||||||
<TableCell bgColor={blocs.filter(bloc => bloc.nom === liste.bloc)[0].couleur} sx={{padding: "0.2em"}}></TableCell>
|
<TableCell bgColor={blocs.filter(bloc => bloc.nom === liste.bloc)[0].couleur} sx={{padding: "0.2em"}}></TableCell>
|
||||||
<TableCell>{liste.bloc}</TableCell>
|
<TableCell>{liste.bloc}</TableCell>
|
||||||
<TableCell>{voix_listes[liste.numero] || 0}</TableCell>
|
<TableCell>{voix_listes[liste.numero] || 0}</TableCell>
|
||||||
<TableCell>{(100 * (voix_listes[liste.numero] || 0) / resultats.exprimes).toFixed(2)} %</TableCell>
|
|
||||||
<TableCell>{(100 * (voix_listes[liste.numero] || 0) / resultats.inscrits).toFixed(2)} %</TableCell>
|
<TableCell>{(100 * (voix_listes[liste.numero] || 0) / resultats.inscrits).toFixed(2)} %</TableCell>
|
||||||
|
<TableCell>{(100 * (voix_listes[liste.numero] || 0) / resultats.exprimes).toFixed(2)} %</TableCell>
|
||||||
<TableCell>{siegesParListe[liste.numero]}</TableCell>
|
<TableCell>{siegesParListe[liste.numero]}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -123,7 +123,7 @@ class ResultatsDepartement(Base):
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(primary_key=True)
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||||||
dpt_id: Mapped[str] = mapped_column(ForeignKey("departement.code_insee"))
|
dpt_id: Mapped[str] = mapped_column(ForeignKey("departement.code_insee"))
|
||||||
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_region.id"))
|
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_region.id"), nullable=True)
|
||||||
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
|
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
|
||||||
votants: Mapped[int] = mapped_column(Integer(), default=0)
|
votants: Mapped[int] = mapped_column(Integer(), default=0)
|
||||||
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
|
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
|
||||||
|
|
|
@ -149,8 +149,12 @@ def importer_resultats_departements(engine: Engine, debug: bool = False) -> None
|
||||||
resultats_departement.nuls = resultats["nuls"]
|
resultats_departement.nuls = resultats["nuls"]
|
||||||
resultats_departement.exprimes = resultats["exprimes"]
|
resultats_departement.exprimes = resultats["exprimes"]
|
||||||
else:
|
else:
|
||||||
|
resultats_region = session.execute(select(ResultatsRegion).filter_by(region_id=reg_code)) \
|
||||||
|
.scalar_one_or_none()
|
||||||
|
|
||||||
resultats_departement = ResultatsDepartement(
|
resultats_departement = ResultatsDepartement(
|
||||||
dpt_id=dpt_code,
|
dpt_id=dpt_code,
|
||||||
|
resultats_region_id=resultats_region.id if resultats_region else None,
|
||||||
inscrits=resultats["inscrits"],
|
inscrits=resultats["inscrits"],
|
||||||
abstentions=resultats["abstentions"],
|
abstentions=resultats["abstentions"],
|
||||||
votants=resultats["votants"],
|
votants=resultats["votants"],
|
||||||
|
|
Loading…
Reference in New Issue