fix: close remaining task 2 review findings
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
|
||||
from sqlalchemy import and_, case, func, or_, select
|
||||
from sqlalchemy import Numeric, and_, case, cast, func, or_, select
|
||||
|
||||
from .config import settings
|
||||
from .events import list_events
|
||||
@@ -46,7 +47,9 @@ def _health_expression(now):
|
||||
def _fiscal_completion_expression():
|
||||
total = func.coalesce(AgentSnapshot.total_products, 0)
|
||||
complete = func.coalesce(AgentSnapshot.fiscally_complete, 0)
|
||||
raw = case((total > 0, complete * 100.0 / total), else_=func.coalesce(AgentSnapshot.coverage_percent, 0))
|
||||
numeric_total = cast(total, Numeric(18, 6))
|
||||
numeric_complete = cast(complete * 100, Numeric(18, 6))
|
||||
raw = case((total > 0, numeric_complete / numeric_total), else_=cast(func.coalesce(AgentSnapshot.coverage_percent, 0), Numeric(18, 6)))
|
||||
return func.round(case((raw < 0, 0), (raw > 100, 100), else_=raw), 1)
|
||||
|
||||
|
||||
@@ -54,8 +57,10 @@ def _fiscal_completion(snapshot) -> float:
|
||||
total = int(getattr(snapshot, "total_products", 0) or 0)
|
||||
complete = int(getattr(snapshot, "fiscally_complete", 0) or 0)
|
||||
if total:
|
||||
return round(max(0, min(total, complete)) * 100 / total, 1)
|
||||
return round(max(0, min(100, float(getattr(snapshot, "coverage_percent", 0) or 0))), 1)
|
||||
value = Decimal(max(0, min(total, complete)) * 100) / Decimal(total)
|
||||
else:
|
||||
value = Decimal(str(max(0, min(100, float(getattr(snapshot, "coverage_percent", 0) or 0)))))
|
||||
return float(value.quantize(Decimal("0.1"), rounding=ROUND_HALF_UP))
|
||||
|
||||
|
||||
def _fiscal_status(snapshot) -> str:
|
||||
@@ -357,7 +362,7 @@ def dashboard_summary(session, now=None):
|
||||
outdated_query = installation_query.where(version_filter).order_by(Installation.id.asc()).limit(ATTENTION_CANDIDATE_LIMIT)
|
||||
outdated_agents = [installation_view(i, a, t, s, now=now) for i, a, t, s in session.execute(outdated_query).all()]
|
||||
|
||||
blocker_query = select(BlockedProduct, Tenant, Installation, Agent, AgentSnapshot).join(Tenant, Tenant.id == BlockedProduct.tenant_id).outerjoin(Installation, Installation.id == BlockedProduct.installation_id).outerjoin(Agent, Agent.id == Installation.agent_id).outerjoin(AgentSnapshot, AgentSnapshot.installation_id == Installation.id).where(open_filter, BlockedProduct.field.in_(BLOCKER_FIELDS[:-1])).order_by(BlockedProduct.last_seen_at.desc(), BlockedProduct.id.desc()).limit(ATTENTION_CANDIDATE_LIMIT)
|
||||
blocker_query = select(BlockedProduct, Tenant, Installation, Agent, AgentSnapshot).join(Tenant, Tenant.id == BlockedProduct.tenant_id).outerjoin(Installation, Installation.id == BlockedProduct.installation_id).outerjoin(Agent, Agent.id == Installation.agent_id).outerjoin(AgentSnapshot, AgentSnapshot.installation_id == Installation.id).where(open_filter, func.upper(BlockedProduct.field).in_(BLOCKER_FIELDS[:-1])).order_by(BlockedProduct.last_seen_at.desc(), BlockedProduct.id.desc()).limit(ATTENTION_CANDIDATE_LIMIT)
|
||||
blocker_candidates = session.execute(blocker_query).all()
|
||||
|
||||
attention = []
|
||||
|
||||
Reference in New Issue
Block a user