Skip to content

Commit

Permalink
🗃️(api) update operational units
Browse files Browse the repository at this point in the history
Given latest assigned codes, we've updated 4 existing operational units
and created 34 new ones.
  • Loading branch information
jmaupetit committed Feb 6, 2025
1 parent b31a917 commit 99d5905
Show file tree
Hide file tree
Showing 4 changed files with 720 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to

### Changed

- Update the list of active operational units
- Upgrade fastapi to `0.115.7`
- Upgrade pydantic to `2.10.6`
- Upgrade pyinstrument to `5.0.1`
Expand Down
181 changes: 162 additions & 19 deletions src/api/qualicharge/fixtures/operational_units.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""QualiCharge operational units fixture.
r"""QualiCharge operational units fixture.
Initial release: 2024/05/17
Expand All @@ -12,6 +12,16 @@
```
Values have been cleaned manually (trimmed and fixed encoding issues).
To update this list:
```
diff old.csv new.csv | \
grep "> FR" | \
sed "s/> \(FR.*\),\(.*\)/Item(\"\\1\", \"\\2\",),/g"
```
And then remove/update Operational units with a new name.
"""

from collections import namedtuple
Expand Down Expand Up @@ -149,10 +159,6 @@
"FRAIR",
"Airbus",
),
Item(
"FRALL",
"Allego Group",
),
Item(
"FRALS",
"ALTENSYS",
Expand Down Expand Up @@ -393,10 +399,6 @@
"FRECN",
"MEA ENERGIES",
),
Item(
"FRECP",
"EcoPhi",
),
Item(
"FREDI",
"EDRI",
Expand Down Expand Up @@ -473,10 +475,6 @@
"FREVC",
"EV Cars",
),
Item(
"FREVE",
"EVE CAR PLUG",
),
Item(
"FREVZ",
"evZen",
Expand Down Expand Up @@ -892,10 +890,6 @@
"FRONE",
"reev",
),
Item(
"FRORV",
"OBORNES",
),
Item(
"FROTH",
"Stations TIERS",
Expand Down Expand Up @@ -1744,9 +1738,158 @@
"FRZUN",
"ZUNDER",
),
# Update: 2025/02/05
Item(
"FR0CU",
"Charge Unix",
),
Item(
"FR190",
"Watt'up",
),
Item(
"FRALL",
"Allego France",
),
Item(
"FRALN",
"ALDI SARL",
),
Item(
"FRBCF",
"BE CHARGE",
),
Item(
"FRBEZ",
"Ville de Béziers",
),
Item(
"FRBFC",
"Citeos pour le compte du réseau de recharge en Bourgogne-Franche-Comté",
),
Item(
"FRBLR",
"MA BORNE LR",
),
Item(
"FRBPE",
"bp pulse",
),
Item(
"FRCG1",
"ChargeGuru",
),
Item(
"FRCVT",
"Covolt",
),
Item(
"FRECP",
"ProperPhi",
),
Item(
"FREKL",
"EKLEO Montlouis-sur-Loire",
),
Item(
"FRELE",
"Electrip",
),
Item(
"FRELT",
"ELTO",
),
Item(
"FREMO",
"E-MOTUM",
),
Item(
"FRENT",
"Enerstock Charging Station",
),
Item(
"FRERA",
"Eranovum e-Mobility",
),
Item(
"FREVE",
"FAROAD",
),
Item(
"FRFZD",
"Fuzed",
),
Item(
"FRHDA",
"Réseau PL de AS24",
),
Item(
"FRHDT",
"Réseau PL de TotalEnergies",
),
Item(
"FRHOP",
"HOPLA POWER CHARGE",
),
Item(
"FRJBA",
"E-MOTUM",
),
Item(
"FRMBX",
"Mercedes-Benz High Power Charging GmbH",
),
Item(
"FRMEI",
"Mob-Energy",
),
Item(
"FRORV",
"O'TERRE",
),
Item(
"FRPLM",
"Prologis Mobility",
),
Item(
"FRPY2",
"AVIA PICOTY",
),
Item(
"FRRVE",
"REVEO",
),
Item(
"FRSLM",
"SPLM Société Publique Lyonnaise de Mobilités",
),
Item(
"FRUB2",
"ubitricity France",
),
Item(
"FRUSC",
"Voltalia Mobility",
),
Item(
"FRVAY",
"vaylens GmbH",
),
Item(
"FRVIR",
"VIRTA Global France",
),
Item(
"FRWII",
"Bornes W:I",
),
Item(
"FRYAW",
"Yaway",
),
Item(
"FRZWO",
"ZE-WATT",
"FRZMR",
"ZEborne Mobility Service - France",
),
]

Expand Down
125 changes: 125 additions & 0 deletions src/api/qualicharge/migrations/versions/3eaef66b7629_ou_data_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""Update operational units data
Revision ID: 3eaef66b7629
Revises: 37189f57d370
Create Date: 2025-02-06 15:37:03.934737
"""

from datetime import datetime, timezone
from typing import Sequence, Union
from uuid import uuid4

from alembic import op
from sqlalchemy import MetaData

from qualicharge.fixtures.operational_units import data as operational_units
from qualicharge.schemas.core import OperationalUnit

# revision identifiers, used by Alembic.
revision: str = "3eaef66b7629"
down_revision: Union[str, None] = "37189f57d370"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

# Legacy names
LEGACY = {
"FRALL": "Allego Group",
"FRECP": "EcoPhi",
"FREVE": "EVE CAR PLUG",
"FRORV": "OBORNES",
}

# New operational units
NEW = {
"FR0CU",
"FR190",
"FRALN",
"FRBCF",
"FRBEZ",
"FRBFC",
"FRBLR",
"FRBPE",
"FRCG1",
"FRCVT",
"FREKL",
"FRELE",
"FRELT",
"FREMO",
"FRENT",
"FRERA",
"FRFZD",
"FRHDA",
"FRHDT",
"FRHOP",
"FRJBA",
"FRMBX",
"FRMEI",
"FRPLM",
"FRPY2",
"FRRVE",
"FRSLM",
"FRUB2",
"FRUSC",
"FRVAY",
"FRVIR",
"FRWII",
"FRYAW",
"FRZMR",
}


def get_table():
"""Get operational units table."""
# Get OperationalUnit table
metadata = MetaData()
metadata.reflect(bind=op.get_bind())
return metadata.tables["operationalunit"]


def upgrade() -> None:
"""Create new entries and update existing ones."""
ou_table = get_table()
now = datetime.now(timezone.utc)

# Bulk insert
op.bulk_insert(
ou_table,
[
{
"id": uuid4().hex,
"created_at": now,
"updated_at": now,
"type": "CHARGING",
}
| ou._asdict()
for ou in operational_units
if ou.code in NEW
],
)

# Updates
to_update = [ou for ou in operational_units if ou.code in LEGACY.keys()]
for ou in to_update:
op.execute(
ou_table.update()
.where(ou_table.c.code == op.inline_literal(ou.code))
.values({"name": op.inline_literal(ou.name), "updated_at": now})
)


def downgrade() -> None:
"""Remove new entries and restore legacy names."""
ou_table = get_table()

# Revert updates
to_update = [ou for ou in operational_units if ou.code in LEGACY.keys()]
for ou in to_update:
op.execute(
ou_table.update()
.where(ou_table.c.code == op.inline_literal(ou.code))
.values({"name": op.inline_literal(LEGACY[ou.code])})
)

# Delete new entries
op.execute(ou_table.delete().where(ou_table.c.code.in_(NEW)))
Loading

0 comments on commit 99d5905

Please sign in to comment.