Start fixing forecast service 17

This commit is contained in:
Urtzi Alfaro
2025-07-30 08:29:40 +02:00
parent e5c3375d53
commit c10a745695
3 changed files with 17 additions and 2 deletions

View File

@@ -36,6 +36,8 @@ class ForecastingService:
) -> ForecastResponse:
"""Generate forecast with comprehensive error handling and fallbacks"""
start_time = datetime.now()
try:
logger.info("Generating forecast",
date=request.forecast_date,

View File

@@ -74,8 +74,13 @@ class PredictionService:
# Record metrics
processing_time = (datetime.now() - start_time).total_seconds()
metrics.register_histogram("prediction_processing_time_seconds", processing_time)
metrics.increment_counter("predictions_served_total")
# Record metrics with proper type conversion
try:
metrics.register_histogram("prediction_processing_time_seconds", float(processing_time))
metrics.increment_counter("predictions_served_total")
except Exception as metrics_error:
# Log metrics error but don't fail the prediction
logger.warning("Failed to record metrics", error=str(metrics_error))
logger.info("Prediction generated successfully",
model_id=model_id,

View File

@@ -390,7 +390,15 @@ class BakeryDataProcessor:
if 'date' not in traffic_clean.columns and 'ds' in traffic_clean.columns:
traffic_clean = traffic_clean.rename(columns={'ds': 'date'})
# 🔧 FIX: Ensure timezone awareness before merge
traffic_clean['date'] = pd.to_datetime(traffic_clean['date'])
# If timezone-naive, localize to UTC
if traffic_clean['date'].dt.tz is None:
traffic_clean['date'] = traffic_clean['date'].dt.tz_localize('UTC')
# If already timezone-aware but not UTC, convert to UTC
elif str(traffic_clean['date'].dt.tz) != 'UTC':
traffic_clean['date'] = traffic_clean['date'].dt.tz_convert('UTC')
# Map traffic columns to standard names
traffic_mapping = {