Improve training code 2

This commit is contained in:
Urtzi Alfaro
2025-07-28 20:20:54 +02:00
parent 98f546af12
commit 7cd595df81
6 changed files with 229 additions and 153 deletions

View File

@@ -81,36 +81,26 @@ class TrainingService:
)
# Step 3: Compile final results
final_result = {
"job_id": job_id,
"tenant_id": tenant_id,
"status": "completed",
"training_results": training_results,
"data_summary": {
"sales_records": len(training_dataset.sales_data),
"weather_records": len(training_dataset.weather_data),
"traffic_records": len(training_dataset.traffic_data),
"date_range": {
"start": training_dataset.date_range.start.isoformat(),
"end": training_dataset.date_range.end.isoformat()
},
"data_sources_used": [source.value for source in training_dataset.date_range.available_sources],
"constraints_applied": training_dataset.date_range.constraints
},
"completed_at": datetime.now().isoformat()
}
logger.info(f"Training job {job_id} completed successfully")
return final_result
return {
"job_id": job_id,
"status": "completed", # or "running" if async
"message": "Training job completed successfully",
"tenant_id": tenant_id,
"created_at": datetime.now(),
"estimated_duration_minutes": 5 # reasonable estimate
}
except Exception as e:
logger.error(f"Training job {job_id} failed: {str(e)}")
# Return error response that still matches schema
return {
"job_id": job_id,
"tenant_id": tenant_id,
"status": "failed",
"error_message": str(e),
"failed_at": datetime.now().isoformat()
"message": f"Training job failed: {str(e)}",
"tenant_id": tenant_id,
"created_at": datetime.now(),
"estimated_duration_minutes": 0
}
async def start_single_product_training(