Improve the frontend modals
This commit is contained in:
@@ -249,13 +249,35 @@ class ModelRepository(TrainingBaseRepository):
|
||||
)
|
||||
recent_models = recent_result.scalar() or 0
|
||||
|
||||
# Calculate average accuracy from model metrics
|
||||
accuracy_query = text("""
|
||||
SELECT AVG(mape) as average_mape, COUNT(*) as total_models_with_metrics
|
||||
FROM trained_models
|
||||
WHERE tenant_id = :tenant_id
|
||||
AND mape IS NOT NULL
|
||||
AND is_active = true
|
||||
""")
|
||||
|
||||
accuracy_result = await self.session.execute(accuracy_query, {"tenant_id": tenant_id})
|
||||
accuracy_row = accuracy_result.fetchone()
|
||||
|
||||
average_mape = accuracy_row.average_mape if accuracy_row and accuracy_row.average_mape else 0
|
||||
total_models_with_metrics = accuracy_row.total_models_with_metrics if accuracy_row else 0
|
||||
|
||||
# Convert MAPE to accuracy percentage (lower MAPE = higher accuracy)
|
||||
# Use 100 - MAPE as a simple conversion, but cap it at reasonable bounds
|
||||
average_accuracy = max(0, min(100, 100 - float(average_mape))) if average_mape > 0 else 0
|
||||
|
||||
return {
|
||||
"total_models": total_models,
|
||||
"active_models": active_models,
|
||||
"inactive_models": total_models - active_models,
|
||||
"production_models": production_models,
|
||||
"models_by_product": product_stats,
|
||||
"recent_models_30d": recent_models
|
||||
"recent_models_30d": recent_models,
|
||||
"average_accuracy": average_accuracy,
|
||||
"total_models_with_metrics": total_models_with_metrics,
|
||||
"average_mape": float(average_mape) if average_mape > 0 else 0
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
@@ -268,7 +290,10 @@ class ModelRepository(TrainingBaseRepository):
|
||||
"inactive_models": 0,
|
||||
"production_models": 0,
|
||||
"models_by_product": {},
|
||||
"recent_models_30d": 0
|
||||
"recent_models_30d": 0,
|
||||
"average_accuracy": 0,
|
||||
"total_models_with_metrics": 0,
|
||||
"average_mape": 0
|
||||
}
|
||||
|
||||
async def _deactivate_other_production_models(
|
||||
@@ -343,4 +368,4 @@ class ModelRepository(TrainingBaseRepository):
|
||||
logger.error("Failed to get model performance summary",
|
||||
model_id=model_id,
|
||||
error=str(e))
|
||||
return {}
|
||||
return {}
|
||||
|
||||
@@ -11,7 +11,7 @@ alembic==1.17.0
|
||||
psycopg2-binary==2.9.10
|
||||
|
||||
# ML libraries
|
||||
prophet==1.1.6
|
||||
prophet==1.2.1
|
||||
scikit-learn==1.6.1
|
||||
pandas==2.2.3
|
||||
numpy==2.2.2
|
||||
|
||||
Reference in New Issue
Block a user