Improve training code 2
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user