diff --git a/services/forecasting/app/services/forecasting_service.py b/services/forecasting/app/services/forecasting_service.py index 708526e7..6b8c4a85 100644 --- a/services/forecasting/app/services/forecasting_service.py +++ b/services/forecasting/app/services/forecasting_service.py @@ -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, diff --git a/services/forecasting/app/services/prediction_service.py b/services/forecasting/app/services/prediction_service.py index e4cdfbb6..c1d307e9 100644 --- a/services/forecasting/app/services/prediction_service.py +++ b/services/forecasting/app/services/prediction_service.py @@ -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, diff --git a/services/training/app/ml/data_processor.py b/services/training/app/ml/data_processor.py index 47969de2..045c3f13 100644 --- a/services/training/app/ml/data_processor.py +++ b/services/training/app/ml/data_processor.py @@ -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 = {