Files
Fuel-Advisor/clean_targets.py

23 lines
801 B
Python

"""Labels futurs isolés : ce module n'est jamais importé par clean_features."""
from datetime import date, timedelta
from statistics import median
def target(states, prediction_time, horizon):
# Le dernier état disponible à t est celui de la veille (hypothèse J+1).
start = date.fromisoformat(prediction_time) - timedelta(days=1)
end = start + timedelta(days=horizon)
a, b = states.get(start.isoformat()), states.get(end.isoformat())
if not a or not b:
return None
shared = a["prices"].keys() & b["prices"].keys()
if len(shared) < 3:
return None
return dict(
delta_cents=median((b["prices"][s] - a["prices"][s]) * 100 for s in shared),
available_at=b["available_at"],
stations=len(shared),
horizon=horizon,
)