merge: clean predictor debt

# Conflicts:
#	predictor/rules.py
This commit is contained in:
dasemu committed 2026-03-13 10:52:48 +01:00
commit a70eff3e45
10 files changed
+266 -64

No files matched your search

+19 -17
View File
@@ -7,7 +7,7 @@ reuse the same pipeline components as ``scripts/collect_daily_data.py``.
from __future__ import annotations
import logging
from datetime import date, datetime, timedelta, timezone
from datetime import date, datetime, timezone
from typing import Any
import pandas as pd
@@ -18,7 +18,9 @@ from pipeline.build_dataset import DatasetBuilder
from pipeline.feature_engineering import FeatureEngineer
from predictor.hybrid_predictor import HybridPredictor
from scripts.collect_daily_data import (
_available_prediction_dates,
_load_prediction_feature_base,
_select_forecast_row_for_date,
_select_feature_anchor_row,
)
from scripts.retrain_model import main as retrain_main
@@ -75,7 +77,7 @@ def run_forecast_cycle(run_hour: int) -> None:
# 3. Scrape station status
scraper = StationScraper()
station_records: list[dict[str, Any]] = []
for station_id in scraper._stations:
for station_id in scraper.station_ids:
try:
record = scraper.scrape_station(station_id)
station_records.append(record)
@@ -116,12 +118,14 @@ def run_forecast_cycle(run_hour: int) -> None:
# 5. Determine forecast dates
base_date = date.today()
if run_hour >= 15:
# Skip today, start from tomorrow
forecast_dates = [base_date + timedelta(days=d) for d in range(1, 8)]
else:
# Include today
forecast_dates = [base_date + timedelta(days=d) for d in range(8)]
forecast_dates = _available_prediction_dates(
weather_by_station,
base_date=base_date,
include_today=run_hour < 15,
)
if not forecast_dates:
logger.error("No usable forecast dates were returned by the weather provider.")
return
# 6. Generate predictions
predictor = HybridPredictor()
@@ -131,16 +135,14 @@ def run_forecast_cycle(run_hour: int) -> None:
for station_id, weather_df in weather_by_station.items():
station_rec = station_map.get(station_id, {})
for target_date in forecast_dates:
days_ahead = (target_date - base_date).days
target_rows = weather_df[weather_df["date"] == target_date]
if target_rows.empty:
idx = max(0, min(days_ahead, len(weather_df) - 1))
target_rows = weather_df.iloc[idx : idx + 1]
if target_rows.empty:
weather_data = _select_forecast_row_for_date(
weather_df,
station_id=station_id,
target_date=target_date,
)
if weather_data is None:
continue
weather_data = target_rows.iloc[0].to_dict()
# Build feature row
features_df = None
if not feature_base_df.empty:
@@ -258,7 +260,7 @@ def _scrape_daily_actuals(store: SQLiteStore, scraper: StationScraper) -> None:
today_iso = date.today().isoformat()
records: list[dict[str, Any]] = []
for station_id in scraper._stations:
for station_id in scraper.station_ids:
try:
data = scraper.scrape_station(station_id)
records.append(