feat(dashboard): clarify the fleet status card and swap map locations to project monitoring location coords.
feat: Location no longer assigned directly to unit, locations and coords are assigned to location only, unit only is deployed or benched.
This commit is contained in:
@@ -10,6 +10,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from backend.database import get_db_session
|
||||
from backend.models import Emitter, RosterUnit, IgnoredUnit
|
||||
from backend.services.unit_location import bulk_active_locations
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -137,6 +138,10 @@ def emit_status_snapshot():
|
||||
emitters = {e.id: e for e in db.query(Emitter).all()}
|
||||
ignored = {i.id for i in db.query(IgnoredUnit).all()}
|
||||
|
||||
# Active-assignment location lookup for all roster units (direct only;
|
||||
# modems inherit from their paired device below in the derive loop).
|
||||
active_locs = bulk_active_locations(db, list(roster.values()))
|
||||
|
||||
# SFM event-forwards are now the primary "last seen" signal for
|
||||
# seismographs. Watcher heartbeats stay as a backup — if SFM is down
|
||||
# or hasn't seen a serial, we fall back to Emitter.last_seen.
|
||||
@@ -225,10 +230,13 @@ def emit_status_snapshot():
|
||||
"ip_address": r.ip_address,
|
||||
"phone_number": r.phone_number,
|
||||
"hardware_model": r.hardware_model,
|
||||
# Location for mapping
|
||||
"location": r.location or "",
|
||||
"address": r.address or "",
|
||||
"coordinates": r.coordinates or "",
|
||||
# Location for mapping — sourced from active UnitAssignment
|
||||
# → MonitoringLocation. Empty for benched / unassigned.
|
||||
"address": (active_locs.get(unit_id) or {}).get("address") or "",
|
||||
"coordinates": (active_locs.get(unit_id) or {}).get("coordinates") or "",
|
||||
"location_name": (active_locs.get(unit_id) or {}).get("name") or "",
|
||||
"project_id": (active_locs.get(unit_id) or {}).get("project_id") or "",
|
||||
"location_id": (active_locs.get(unit_id) or {}).get("location_id") or "",
|
||||
}
|
||||
|
||||
# --- Add unexpected emitter-only units ---
|
||||
@@ -267,10 +275,12 @@ def emit_status_snapshot():
|
||||
"ip_address": None,
|
||||
"phone_number": None,
|
||||
"hardware_model": None,
|
||||
# Location fields
|
||||
"location": "",
|
||||
# Location fields — unknown units have no assignment
|
||||
"address": "",
|
||||
"coordinates": "",
|
||||
"location_name": "",
|
||||
"project_id": "",
|
||||
"location_id": "",
|
||||
}
|
||||
|
||||
# --- Derive modem status from paired devices ---
|
||||
@@ -301,6 +311,11 @@ def emit_status_snapshot():
|
||||
unit_data["last"] = paired_unit.get("last")
|
||||
unit_data["last_seen_source"] = paired_unit.get("last_seen_source", "none")
|
||||
unit_data["derived_from"] = paired_unit_id
|
||||
# Inherit deployment location too — modems don't carry
|
||||
# their own UnitAssignment.
|
||||
for k in ("address", "coordinates", "location_name", "project_id", "location_id"):
|
||||
if not unit_data.get(k):
|
||||
unit_data[k] = paired_unit.get(k, "")
|
||||
|
||||
# Separate buckets for UI
|
||||
active_units = {
|
||||
|
||||
Reference in New Issue
Block a user