Improve the frontend
This commit is contained in:
@@ -9,6 +9,8 @@ Provides intelligent time estimation for training jobs based on:
|
||||
from typing import List, Optional
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import structlog
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
logger = structlog.get_logger()
|
||||
|
||||
@@ -256,8 +258,8 @@ def format_time_remaining(seconds: int) -> str:
|
||||
return f"{hours} hour{'s' if hours > 1 else ''}"
|
||||
|
||||
|
||||
def get_historical_average_estimate(
|
||||
db_session,
|
||||
async def get_historical_average_estimate(
|
||||
db_session: AsyncSession,
|
||||
tenant_id: str,
|
||||
lookback_days: int = 30,
|
||||
limit: int = 10
|
||||
@@ -269,7 +271,7 @@ def get_historical_average_estimate(
|
||||
recent historical data and calculate an average.
|
||||
|
||||
Args:
|
||||
db_session: Database session
|
||||
db_session: Async database session
|
||||
tenant_id: Tenant UUID
|
||||
lookback_days: How many days back to look
|
||||
limit: Maximum number of historical records to consider
|
||||
@@ -283,13 +285,19 @@ def get_historical_average_estimate(
|
||||
|
||||
cutoff = datetime.now(timezone.utc) - timedelta(days=lookback_days)
|
||||
|
||||
# Query recent training performance metrics
|
||||
metrics = db_session.query(TrainingPerformanceMetrics).filter(
|
||||
TrainingPerformanceMetrics.tenant_id == tenant_id,
|
||||
TrainingPerformanceMetrics.completed_at >= cutoff
|
||||
).order_by(
|
||||
TrainingPerformanceMetrics.completed_at.desc()
|
||||
).limit(limit).all()
|
||||
# Query recent training performance metrics using SQLAlchemy 2.0 async pattern
|
||||
query = (
|
||||
select(TrainingPerformanceMetrics)
|
||||
.where(
|
||||
TrainingPerformanceMetrics.tenant_id == tenant_id,
|
||||
TrainingPerformanceMetrics.completed_at >= cutoff
|
||||
)
|
||||
.order_by(TrainingPerformanceMetrics.completed_at.desc())
|
||||
.limit(limit)
|
||||
)
|
||||
|
||||
result = await db_session.execute(query)
|
||||
metrics = result.scalars().all()
|
||||
|
||||
if not metrics:
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user