fix(backend,airflow,ml): cloture la reconciliation entre les deux sources de lectures (#15)
This commit is contained in:
@@ -11,7 +11,7 @@ from enervision_ml.data import (
|
||||
load_from_database,
|
||||
load_recent_from_database,
|
||||
)
|
||||
from tests.conftest import ANCRAGE, insere_lecture, insere_lectures, insere_site
|
||||
from tests.conftest import ANCRAGE, insere_dataset, insere_lecture, insere_lectures, insere_site
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
@@ -39,6 +39,58 @@ def test_load_from_database_joins_the_site_attributes_to_every_reading(
|
||||
assert set(mien["capacity_kw"]) == {250.0}
|
||||
|
||||
|
||||
def test_load_from_database_deduplicates_two_sources_at_the_same_instant(
|
||||
connexion_ml: Connection,
|
||||
) -> None:
|
||||
# `uq_reading_source` autorise deux lignes au meme (site_id, timestamp) des que `source`
|
||||
# differe : le garde-fou vit dans `mock_api_import.py`, pas dans le schema. Le chargeur ML
|
||||
# doit donc imposer lui-meme "une ligne par (site_id, timestamp)", pas la supposer.
|
||||
site_id = insere_site(connexion_ml)
|
||||
dataset_id = insere_dataset(connexion_ml)
|
||||
insere_lecture(
|
||||
connexion_ml, site_id, instant=ANCRAGE, consumption_kwh=10.0, source="api_history"
|
||||
)
|
||||
insere_lecture(
|
||||
connexion_ml,
|
||||
site_id,
|
||||
instant=ANCRAGE,
|
||||
consumption_kwh=99.0,
|
||||
source="csv",
|
||||
dataset_id=dataset_id,
|
||||
)
|
||||
|
||||
frame = load_from_database(connexion_ml)
|
||||
|
||||
mien = frame[frame["site_id"] == site_id]
|
||||
assert len(mien) == 1
|
||||
assert mien["consumption_kwh"].iloc[0] == 99.0
|
||||
|
||||
|
||||
def test_load_recent_from_database_prefers_csv_when_two_sources_share_an_instant(
|
||||
connexion_ml: Connection,
|
||||
) -> None:
|
||||
site_id = insere_site(connexion_ml)
|
||||
dataset_id = insere_dataset(connexion_ml)
|
||||
insere_lecture(
|
||||
connexion_ml, site_id, instant=ANCRAGE, consumption_kwh=10.0, source="api_history"
|
||||
)
|
||||
insere_lecture(
|
||||
connexion_ml,
|
||||
site_id,
|
||||
instant=ANCRAGE,
|
||||
consumption_kwh=99.0,
|
||||
source="csv",
|
||||
dataset_id=dataset_id,
|
||||
)
|
||||
|
||||
frame = load_recent_from_database(
|
||||
connexion_ml, since=ANCRAGE, until=ANCRAGE + timedelta(hours=3)
|
||||
)
|
||||
|
||||
assert len(frame) == 1
|
||||
assert frame["consumption_kwh"].iloc[0] == 99.0
|
||||
|
||||
|
||||
def test_load_recent_from_database_excludes_readings_before_the_since_bound(
|
||||
connexion_ml: Connection,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user