feat: add operational Dashboard
This commit is contained in:
1 parent
4a1959ecd6
commit
b8b741ccee
23 files changed
+1278
-59
No files matched your search
@@ -314,3 +314,31 @@ class RepairCenterRepository:
|
||||
finally:
|
||||
connection.close()
|
||||
return {"items": items, "summary": summary, "location_options": options}
|
||||
|
||||
def summarize_active_repairs(self) -> dict[str, Any]:
|
||||
"""Return exact active counts without loading Repair Center rows."""
|
||||
ctes = self._ctes(show_miners=False, show_locations=False)
|
||||
connection = self._connection_factory()
|
||||
try:
|
||||
with connection.cursor(row_factory=dict_row) as cur:
|
||||
cur.execute(
|
||||
f"""
|
||||
{ctes}, active_rows AS (
|
||||
SELECT repair_status FROM candidates WHERE active
|
||||
)
|
||||
SELECT count(*)::integer AS active,
|
||||
COALESCE((SELECT jsonb_object_agg(
|
||||
status_rows.repair_status,
|
||||
status_rows.status_count
|
||||
) FROM (
|
||||
SELECT repair_status,
|
||||
count(*)::integer AS status_count
|
||||
FROM active_rows
|
||||
GROUP BY repair_status
|
||||
) AS status_rows), '{{}}'::jsonb) AS status_counts
|
||||
FROM active_rows
|
||||
"""
|
||||
)
|
||||
return dict(cur.fetchone())
|
||||
finally:
|
||||
connection.close()
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from app.repairs.center_repository import RepairCenterRepository
|
||||
from app.repairs.models import (
|
||||
ActiveRepairSummary,
|
||||
RepairCenterAccess,
|
||||
RepairCenterCapabilities,
|
||||
RepairCenterFilters,
|
||||
@@ -94,3 +95,8 @@ class RepairCenterService:
|
||||
location_options=location_options,
|
||||
),
|
||||
)
|
||||
|
||||
def summarize_active_repairs(self) -> ActiveRepairSummary:
|
||||
return ActiveRepairSummary.model_validate(
|
||||
self.repository.summarize_active_repairs()
|
||||
)
|
||||
@@ -389,6 +389,11 @@ class RepairCenterSummary(BaseModel):
|
||||
error_counts: dict[str, int] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class ActiveRepairSummary(BaseModel):
|
||||
active: int
|
||||
status_counts: dict[str, int] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class RepairCenterLocationOption(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
|
||||
Reference in new issue
Block a user