Skip to content

Commit

Permalink
WIP: import operational units from afirev
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaupetit committed May 15, 2024
1 parent df734cc commit 241b3ae
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CURL = $(COMPOSE_RUN) curl

# -- Ressources
IRVE_STATIC_DATASET_URL = https://www.data.gouv.fr/fr/datasets/r/eb76d20a-8501-400e-b336-d85724de5435
AFIREV_CHARGING_DATASET_URL = https://afirev.fr/en/liste-des-identifiants-attribues/
AFIREV_MOBILITY_DATASET_URL = https://afirev.fr/en/liste-des-identifiants-attribues/

# ==============================================================================
# RULES
Expand All @@ -25,6 +27,11 @@ data:
data/irve-statique.csv: data
$(CURL) -L -o /work/data/irve-statique.csv $(IRVE_STATIC_DATASET_URL)

data/afirev-charging.csv: data
@echo "You should download CSV file from $(AFIREV_CHARGING_DATASET_URL)"

data/afirev-mobility.csv: data
@echo "You should download CSV file from $(AFIREV_MOBILITY_DATASET_URL)"

# -- Docker/compose
bootstrap: ## bootstrap the project for development
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""add operational unit data
Revision ID: fda96abb970d
Revises: 9d22385a3ae8
Create Date: 2024-05-15 16:08:19.687606
"""

import json
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from qualicharge.db import get_engine
from qualicharge.schemas import OperationalUnit, OperationalUnitTypeEnum


# revision identifiers, used by Alembic.
revision: str = "fda96abb970d"
down_revision: Union[str, None] = "9d22385a3ae8"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

# Database globals
engine = get_engine()
metadata = sa.MetaData()
metadata.reflect(bind=engine)


def upgrade():
data_upgrades()


def downgrade():
data_downgrades()


def data_upgrades():
"""Add any optional data upgrade migrations here!"""

operational_units = [
OperationalUnit(
code="FR073",
name="ACELEC CHARGE",
type=OperationalUnitTypeEnum.CHARGING,
).model_dump_sa(),
OperationalUnit(
code="FR0NX", name="NEXTENEO", type=OperationalUnitTypeEnum.CHARGING
).model_dump_sa(),
OperationalUnit(
code="FR147", name="E.Z.O", type=OperationalUnitTypeEnum.CHARGING
).model_dump_sa(),
OperationalUnit(
code="FR281", name="WALLCORP", type=OperationalUnitTypeEnum.CHARGING
).model_dump_sa(),
OperationalUnit(
code="FR2AC",
name="SUPERNOVA",
type=OperationalUnitTypeEnum.CHARGING,
).model_dump_sa(),
]
op.bulk_insert(
sa.Table("operationalunit", metadata, autoload_with=engine),
operational_units,
)


def data_downgrades():
"""Add any optional data downgrade migrations here!"""

op.execute("delete from operationalunit")
7 changes: 7 additions & 0 deletions src/api/qualicharge/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ class OperationalUnit(BaseTimestampedSQLModel, table=True):

stations: List["Station"] = Relationship(back_populates="operational_unit")

# FIXME
def model_dump_sa(self, *args, **kwargs):
"""Dump model data for SQLAlchemy."""
d = self.model_dump(*args, **kwargs)
d.update({"type": self.type.name})
return d


class Station(BaseTimestampedSQLModel, table=True):
"""Station table."""
Expand Down

0 comments on commit 241b3ae

Please sign in to comment.