auto-sync: 2026-04-20 10:10:01

This commit is contained in:
Stream
2026-04-20 10:10:01 +03:00
parent 5c09319618
commit a1956b4075

View File

@@ -203,6 +203,21 @@ def get_or_create_flight(conn, aircraft_id: int, callsign: str | None, observed_
return cur.fetchone()[0]
def update_flight_callsign(conn, aircraft_id: int, callsign: str) -> None:
"""Update callsign on active flight if not already set."""
with conn.cursor() as cur:
cur.execute(
"""
UPDATE fr24.flights
SET callsign = %s
WHERE aircraft_id = %s
AND status = 'active'
AND callsign IS NULL
""",
(callsign, aircraft_id),
)
def get_or_create_track(conn, flight_id: int) -> int:
with conn.cursor() as cur:
cur.execute(
@@ -343,6 +358,10 @@ def process_batch(conn, packets: list, aircraft_state: dict) -> int:
aircraft_id = upsert_aircraft(conn, icao24, callsign, now)
flight_id = get_or_create_flight(conn, aircraft_id, callsign, observed_at)
# update callsign on active flight if MSG1 brought a callsign
if msg_type == "1" and callsign:
update_flight_callsign(conn, aircraft_id, callsign)
# sanity-check: skip obviously invalid coordinates
if lat is not None and lon is not None and not (-90 <= lat <= 90 and -180 <= lon <= 180):
log.warning("Invalid coords icao24=%s lat=%s lon=%s — skipping", icao24, lat, lon)