Ensure last_heard never precedes position time (#31)

This commit is contained in:
l5y
2025-09-14 17:53:37 +02:00
committed by GitHub
parent 2ca87eb847
commit 6094609a86
2 changed files with 15 additions and 2 deletions
+9 -1
View File
@@ -37,6 +37,14 @@ def upsert_node(node_id, n):
met = _get(n, "deviceMetrics") or {}
pos = _get(n, "position") or {}
lh = _get(n, "lastHeard")
pt = _get(pos, "time")
now = int(time.time())
if lh is not None and lh > now:
lh = now
if pt is not None and pt > now:
pt = now
if pt is not None and (lh is None or lh < pt):
lh = pt
row = (
node_id,
_get(n, "num"),
@@ -57,7 +65,7 @@ def upsert_node(node_id, n):
_get(met, "channelUtilization"),
_get(met, "airUtilTx"),
_get(met, "uptimeSeconds"),
_get(pos, "time"),
pt,
_get(pos, "locationSource"),
_get(pos, "latitude"),
_get(pos, "longitude"),
+6 -1
View File
@@ -45,6 +45,11 @@ def upsert_node(db, node_id, n)
pos = n["position"] || {}
role = user["role"] || "CLIENT"
lh = n["lastHeard"]
pt = pos["time"]
now = Time.now.to_i
lh = now if lh && lh > now
pt = now if pt && pt > now
lh = pt if pt && (!lh || lh < pt)
row = [
node_id,
n["num"],
@@ -65,7 +70,7 @@ def upsert_node(db, node_id, n)
met["channelUtilization"],
met["airUtilTx"],
met["uptimeSeconds"],
pos["time"],
pt,
pos["locationSource"],
pos["latitude"],
pos["longitude"],