feat: add operational Dashboard
This commit is contained in:
1 parent
4a1959ecd6
commit
b8b741ccee
23 files changed
+1278
-59
No files matched your search
@@ -116,3 +116,13 @@ class MineMapResponse(BaseModel):
|
||||
data: MineMapData
|
||||
meta: MineMapMeta
|
||||
error: None = None
|
||||
|
||||
|
||||
class LocationSummary(BaseModel):
|
||||
sites: int
|
||||
rooms: int
|
||||
positions: int
|
||||
occupied_positions: int
|
||||
empty_positions: int
|
||||
mapped_miners: int | None = None
|
||||
unmapped_miners: int | None = None
|
||||
@@ -201,3 +201,31 @@ class LocationMapRepository:
|
||||
"positions": positions,
|
||||
"virtual_miners": virtual_miners,
|
||||
}
|
||||
|
||||
def summarize_locations(self, *, include_miner_counts: bool) -> dict[str, Any]:
|
||||
miner_counts = (
|
||||
"count(DISTINCT lp.miner_id)::integer AS mapped_miners, "
|
||||
"(SELECT count(*)::integer FROM miners WHERE NOT EXISTS ("
|
||||
"SELECT 1 FROM location_positions assigned "
|
||||
"WHERE assigned.miner_id = miners.id)) AS unmapped_miners"
|
||||
if include_miner_counts
|
||||
else "NULL::integer AS mapped_miners, NULL::integer AS unmapped_miners"
|
||||
)
|
||||
with self._connection_scope() as connection:
|
||||
with connection.cursor(row_factory=dict_row) as cur:
|
||||
cur.execute(
|
||||
f"""
|
||||
SELECT (SELECT count(*)::integer FROM sites) AS sites,
|
||||
(SELECT count(*)::integer FROM rooms) AS rooms,
|
||||
count(lp.id)::integer AS positions,
|
||||
count(lp.id) FILTER (
|
||||
WHERE lp.miner_id IS NOT NULL
|
||||
)::integer AS occupied_positions,
|
||||
count(lp.id) FILTER (
|
||||
WHERE lp.miner_id IS NULL
|
||||
)::integer AS empty_positions,
|
||||
{miner_counts}
|
||||
FROM location_positions AS lp
|
||||
"""
|
||||
)
|
||||
return dict(cur.fetchone())
|
||||
@@ -5,6 +5,7 @@ from typing import Any
|
||||
from uuid import UUID
|
||||
|
||||
from app.locations.models import (
|
||||
LocationSummary,
|
||||
MapActiveRepair,
|
||||
MapPosition,
|
||||
MapRoom,
|
||||
@@ -85,3 +86,10 @@ class LocationMapService:
|
||||
miner_details_included=include_miner_details,
|
||||
),
|
||||
)
|
||||
|
||||
def summarize_locations(self, *, include_miner_counts: bool) -> LocationSummary:
|
||||
return LocationSummary.model_validate(
|
||||
self.repository.summarize_locations(
|
||||
include_miner_counts=include_miner_counts
|
||||
)
|
||||
)
|
||||
Reference in new issue
Block a user