Start fixing forecast service 17
This commit is contained in:
@@ -36,6 +36,8 @@ class ForecastingService:
|
|||||||
) -> ForecastResponse:
|
) -> ForecastResponse:
|
||||||
"""Generate forecast with comprehensive error handling and fallbacks"""
|
"""Generate forecast with comprehensive error handling and fallbacks"""
|
||||||
|
|
||||||
|
start_time = datetime.now()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.info("Generating forecast",
|
logger.info("Generating forecast",
|
||||||
date=request.forecast_date,
|
date=request.forecast_date,
|
||||||
|
|||||||
@@ -74,8 +74,13 @@ class PredictionService:
|
|||||||
|
|
||||||
# Record metrics
|
# Record metrics
|
||||||
processing_time = (datetime.now() - start_time).total_seconds()
|
processing_time = (datetime.now() - start_time).total_seconds()
|
||||||
metrics.register_histogram("prediction_processing_time_seconds", processing_time)
|
# Record metrics with proper type conversion
|
||||||
metrics.increment_counter("predictions_served_total")
|
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",
|
logger.info("Prediction generated successfully",
|
||||||
model_id=model_id,
|
model_id=model_id,
|
||||||
|
|||||||
@@ -390,8 +390,16 @@ class BakeryDataProcessor:
|
|||||||
if 'date' not in traffic_clean.columns and 'ds' in traffic_clean.columns:
|
if 'date' not in traffic_clean.columns and 'ds' in traffic_clean.columns:
|
||||||
traffic_clean = traffic_clean.rename(columns={'ds': 'date'})
|
traffic_clean = traffic_clean.rename(columns={'ds': 'date'})
|
||||||
|
|
||||||
|
# 🔧 FIX: Ensure timezone awareness before merge
|
||||||
traffic_clean['date'] = pd.to_datetime(traffic_clean['date'])
|
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
|
# Map traffic columns to standard names
|
||||||
traffic_mapping = {
|
traffic_mapping = {
|
||||||
'traffic_volume': ['traffic_volume', 'traffic_intensity', 'trafico', 'intensidad', 'volume'],
|
'traffic_volume': ['traffic_volume', 'traffic_intensity', 'trafico', 'intensidad', 'volume'],
|
||||||
|
|||||||
Reference in New Issue
Block a user