Improve backend
This commit is contained in:
@@ -152,15 +152,46 @@ class ForecastServiceClient(BaseServiceClient):
|
||||
|
||||
Args:
|
||||
tenant_id: Tenant UUID
|
||||
date: Date to validate
|
||||
date: Date to validate (validates this single day)
|
||||
|
||||
Returns:
|
||||
Dict with overall metrics and poor accuracy products list
|
||||
"""
|
||||
params = {
|
||||
"validation_date": date.isoformat()
|
||||
from datetime import datetime, timezone
|
||||
|
||||
# Convert date to datetime with timezone for start/end of day
|
||||
start_datetime = datetime.combine(date, datetime.min.time()).replace(tzinfo=timezone.utc)
|
||||
end_datetime = datetime.combine(date, datetime.max.time()).replace(tzinfo=timezone.utc)
|
||||
|
||||
# Call the new validation endpoint
|
||||
result = await self.post(
|
||||
"forecasting/validation/validate-yesterday",
|
||||
params={"orchestration_run_id": None},
|
||||
tenant_id=tenant_id
|
||||
)
|
||||
|
||||
if not result:
|
||||
return None
|
||||
|
||||
# Transform the new response format to match the expected format
|
||||
overall_metrics = result.get("overall_metrics", {})
|
||||
|
||||
# Get poor accuracy products from the result
|
||||
poor_accuracy_products = result.get("poor_accuracy_products", [])
|
||||
|
||||
return {
|
||||
"overall_mape": overall_metrics.get("mape", 0),
|
||||
"overall_rmse": overall_metrics.get("rmse", 0),
|
||||
"overall_mae": overall_metrics.get("mae", 0),
|
||||
"overall_r2_score": overall_metrics.get("r2_score", 0),
|
||||
"overall_accuracy_percentage": overall_metrics.get("accuracy_percentage", 0),
|
||||
"products_validated": result.get("forecasts_with_actuals", 0),
|
||||
"poor_accuracy_products": poor_accuracy_products,
|
||||
"validation_run_id": result.get("validation_run_id"),
|
||||
"forecasts_evaluated": result.get("forecasts_evaluated", 0),
|
||||
"forecasts_with_actuals": result.get("forecasts_with_actuals", 0),
|
||||
"forecasts_without_actuals": result.get("forecasts_without_actuals", 0)
|
||||
}
|
||||
return await self.post("forecasting/operations/validate-forecasts", params=params, tenant_id=tenant_id)
|
||||
|
||||
async def get_forecast_statistics(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user