P1-b: don't let LBS/WIFI fixes overwrite a fresh GPS fix in live view
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
6eb6b4716c
commit
9c7b69e395
1 changed files with 16 additions and 0 deletions
|
|
@ -24,6 +24,14 @@ log = structlog.get_logger("projector.live_positions")
|
|||
DRAIN_BATCH = 500
|
||||
PROJECTED_FLAG_KEY = "live_positions_projected_at"
|
||||
|
||||
# Low-accuracy positioning modes (cell-tower / wifi) reported in Tracksolid's
|
||||
# `posType`. These can be kilometres off a real GPS fix, so we don't let one
|
||||
# overwrite a *fresh* GPS fix in the live view (it would teleport the marker).
|
||||
# A GPS fix older than this window does yield to LBS/WIFI, so a genuinely
|
||||
# GPS-dark vehicle still updates rather than freezing forever.
|
||||
LOW_ACCURACY_POS_TYPES = ("LBS", "WIFI")
|
||||
GPS_PREFERENCE_WINDOW_SQL = "interval '10 minutes'"
|
||||
|
||||
|
||||
_PLATE_FROM_DEVICE_NAME = re.compile(r"^.* - (.+?)(?:_cam|_CAM)?$")
|
||||
_CAMERA_NAME_RE = re.compile(r"_cam$", re.IGNORECASE)
|
||||
|
|
@ -190,6 +198,13 @@ async def _project_one(
|
|||
device_name = EXCLUDED.device_name,
|
||||
pos_type = EXCLUDED.pos_type
|
||||
WHERE EXCLUDED.occurred_at > state.live_positions.occurred_at
|
||||
AND NOT COALESCE(
|
||||
EXCLUDED.pos_type = ANY (%s)
|
||||
AND state.live_positions.pos_type = 'GPS'
|
||||
AND state.live_positions.occurred_at
|
||||
> now() - """ + GPS_PREFERENCE_WINDOW_SQL + """,
|
||||
false
|
||||
)
|
||||
""",
|
||||
(
|
||||
imei, vehicle_id, occurred_at, geom_wkt,
|
||||
|
|
@ -204,6 +219,7 @@ async def _project_one(
|
|||
payload.get("satellites"),
|
||||
payload.get("device_name"),
|
||||
payload.get("pos_type"),
|
||||
list(LOW_ACCURACY_POS_TYPES),
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue