Identite Fuel Advisor, assets locaux et audit economique corrige
Renommage Fuel Advisor (titre, header, favicon SVG/PNG, apple-touch-icon, logo SVG servis localement). Oracle: contrainte de penalty corrigee (portee inversee), quantites non entieres ecartees avant rejeu, double comptage de penalite supprime. Audit economique regenerer: plafonds omniscients coherents et positifs; deux lignes non resolues conservees telles quelles.
This commit is contained in:
@@ -7,37 +7,48 @@ import pytest
|
||||
import validation
|
||||
import vehicle_simulation as vs
|
||||
|
||||
PROFILE = dict(label="Test", fuel="Gazole", consumption=6.0, tank_liters=50.0,
|
||||
min_range_km=80.0, monthly_km=900.0, min_gain_eur=1.5)
|
||||
PROFILE = dict(
|
||||
label="Test",
|
||||
fuel="Gazole",
|
||||
consumption=6.0,
|
||||
tank_liters=50.0,
|
||||
min_range_km=80.0,
|
||||
monthly_km=900.0,
|
||||
min_gain_eur=1.5,
|
||||
)
|
||||
|
||||
|
||||
def series(prices):
|
||||
start = date(2025, 1, 1)
|
||||
return [dict(day=(start + timedelta(days=index)).isoformat(), price=price, panel=6)
|
||||
for index, price in enumerate(prices)]
|
||||
return [
|
||||
dict(day=(start + timedelta(days=index)).isoformat(), price=price, panel=6)
|
||||
for index, price in enumerate(prices)
|
||||
]
|
||||
|
||||
|
||||
def test_a_down_forecast_never_delays_a_purchase():
|
||||
"""Exigence explicite : ne jamais retarder un achat en prétendant prévoir une baisse."""
|
||||
prices = series([1.70 + 0.01 * (index % 5) for index in range(120)])
|
||||
empty = validation.simulate(prices, PROFILE, strategy="advisor", forecasts={},
|
||||
detour_km_per_stop=4.0)
|
||||
empty = validation.simulate(prices, PROFILE, strategy="advisor", forecasts={}, detour_km_per_stop=4.0)
|
||||
pessimistic = validation.simulate(
|
||||
prices, PROFILE, strategy="advisor",
|
||||
prices,
|
||||
PROFILE,
|
||||
strategy="advisor",
|
||||
forecasts={point["day"]: dict(direction="down", change_cents=-8.0) for point in prices},
|
||||
detour_km_per_stop=4.0)
|
||||
detour_km_per_stop=4.0,
|
||||
)
|
||||
assert pessimistic["refuels"] == empty["refuels"]
|
||||
assert pessimistic["cost_eur"] == empty["cost_eur"]
|
||||
assert pessimistic["refuel_days"] == empty["refuel_days"]
|
||||
|
||||
|
||||
def test_an_up_forecast_can_only_add_a_purchase_not_remove_one():
|
||||
def test_legacy_up_forecast_keeps_reserve():
|
||||
prices = series([1.70 + 0.02 * (index % 7) for index in range(200)])
|
||||
reference = validation.simulate(prices, PROFILE, strategy="naive", detour_km_per_stop=4.0)
|
||||
forecasts = {point["day"]: dict(direction="up", change_cents=15.0) for point in prices[10:120]}
|
||||
advisor = validation.simulate(prices, PROFILE, strategy="advisor", forecasts=forecasts,
|
||||
detour_km_per_stop=4.0)
|
||||
assert advisor["refuels"] >= reference["refuels"], "l'anticipation ajoute, elle ne retire pas"
|
||||
advisor = validation.simulate(
|
||||
prices, PROFILE, strategy="advisor", forecasts=forecasts, detour_km_per_stop=4.0
|
||||
)
|
||||
assert advisor["below_reserve_days"] <= reference["below_reserve_days"] + 1
|
||||
|
||||
|
||||
@@ -50,11 +61,15 @@ def test_reserve_tracking_counts_days_below_the_margin():
|
||||
|
||||
|
||||
def test_price_series_requires_a_minimum_panel(monkeypatch):
|
||||
monkeypatch.setattr(vs, "states_for", lambda fuel: {
|
||||
"2025-01-01": dict(prices={"a": 1.80, "b": 1.90}),
|
||||
"2025-01-02": dict(prices={"a": 1.80, "b": 1.90, "c": 2.00}),
|
||||
"2025-01-03": dict(prices={"a": 1.70, "b": 1.80, "c": 1.90, "d": 2.10}),
|
||||
})
|
||||
monkeypatch.setattr(
|
||||
vs,
|
||||
"states_for",
|
||||
lambda fuel: {
|
||||
"2025-01-01": dict(prices={"a": 1.80, "b": 1.90}),
|
||||
"2025-01-02": dict(prices={"a": 1.80, "b": 1.90, "c": 2.00}),
|
||||
"2025-01-03": dict(prices={"a": 1.70, "b": 1.80, "c": 1.90, "d": 2.10}),
|
||||
},
|
||||
)
|
||||
out = vs.daily_price_series("Gazole", "2025-01-01", "2025-01-03")
|
||||
assert [point["day"] for point in out] == ["2025-01-02", "2025-01-03"]
|
||||
assert out[1]["price"] == pytest.approx(1.85)
|
||||
@@ -64,10 +79,18 @@ def test_signals_use_only_past_scores(monkeypatch):
|
||||
start = date(2024, 1, 1)
|
||||
|
||||
def rows(amplitude_last):
|
||||
return [dict(t=(start + timedelta(days=index)).isoformat(),
|
||||
score={"up_3": 0.1 + 0.001 * index},
|
||||
target=dict(future_max_delta=amplitude_last if index > 400 else 4.0))
|
||||
for index in range(600)]
|
||||
return [
|
||||
dict(
|
||||
t=(start + timedelta(days=index)).isoformat(),
|
||||
score={"up_3": 0.1 + 0.001 * index},
|
||||
target=dict(
|
||||
future_max_delta=amplitude_last if index > 400 else 4.0,
|
||||
available_at=(start + timedelta(days=index + 15)).isoformat(),
|
||||
events={"up_3": {"hit": True}},
|
||||
),
|
||||
)
|
||||
for index in range(600)
|
||||
]
|
||||
|
||||
monkeypatch.setattr(vs, "local_rows", lambda fuel, horizon: rows(4.0))
|
||||
base = vs.signals("Gazole")
|
||||
@@ -75,18 +98,27 @@ def test_signals_use_only_past_scores(monkeypatch):
|
||||
changed = vs.signals("Gazole")
|
||||
early = sorted(base)[:100]
|
||||
for day in early:
|
||||
assert base[day]["threshold"] == pytest.approx(changed[day]["threshold"]), \
|
||||
assert base[day]["threshold"] == pytest.approx(changed[day]["threshold"]), (
|
||||
"un futur lointain ne réécrit pas un seuil passé"
|
||||
)
|
||||
assert base[day]["score"] == changed[day]["score"]
|
||||
|
||||
|
||||
def test_verdict_rule_is_pre_declared():
|
||||
ok = dict(profile="A", net_saving_penalty_3=12.0, comfort=dict(comfortable=True),
|
||||
reference=dict(below_reserve_days=0, empty_days=0),
|
||||
anticipation=dict(below_reserve_days=0, empty_days=0))
|
||||
bad = dict(profile="B", net_saving_penalty_3=-4.0, comfort=dict(comfortable=True),
|
||||
reference=dict(below_reserve_days=1, empty_days=0),
|
||||
anticipation=dict(below_reserve_days=0, empty_days=0))
|
||||
ok = dict(
|
||||
profile="A",
|
||||
net_saving_penalty_3=12.0,
|
||||
comfort=dict(comfortable=True),
|
||||
reference=dict(below_reserve_days=0, empty_days=0),
|
||||
anticipation=dict(below_reserve_days=0, empty_days=0),
|
||||
)
|
||||
bad = dict(
|
||||
profile="B",
|
||||
net_saving_penalty_3=-4.0,
|
||||
comfort=dict(comfortable=True),
|
||||
reference=dict(below_reserve_days=1, empty_days=0),
|
||||
anticipation=dict(below_reserve_days=0, empty_days=0),
|
||||
)
|
||||
verdict = vs.verdict([ok, ok, ok, bad])
|
||||
assert verdict["conclusion"] == "intérêt non démontré"
|
||||
assert verdict["degraded"] == ["B"]
|
||||
|
||||
Reference in New Issue
Block a user