diff --git a/tasks/flightradar24/ingest/mart/build_mart.py b/tasks/flightradar24/ingest/mart/build_mart.py index 8461421..83acb00 100644 --- a/tasks/flightradar24/ingest/mart/build_mart.py +++ b/tasks/flightradar24/ingest/mart/build_mart.py @@ -126,7 +126,7 @@ def find_fr24_track(conn, flight_number: str, flight_date: date, if not rows: return None - # Prefer route match + # Route match REQUIRED for numeric-only matching (avoids e.g. DP6807 → SU6807) if origin_iata and destination_iata: for row in rows: orig_iata = ICAO_TO_IATA.get(row[2]) @@ -134,8 +134,8 @@ def find_fr24_track(conn, flight_number: str, flight_date: date, if orig_iata == origin_iata and dest_iata == destination_iata: return (row[0], row[1]) - # Fallback: first match by number only - return (rows[0][0], rows[0][1]) + # No route match — do not return a wrong track + return None def find_fa_track(conn, flight_number: str, flight_date: date, @@ -187,6 +187,7 @@ def find_fa_track(conn, flight_number: str, flight_date: date, if not rows: return None + # Route match REQUIRED for numeric-only matching if origin_iata and destination_iata: for row in rows: orig_iata = ICAO_TO_IATA.get(row[2]) @@ -194,7 +195,8 @@ def find_fa_track(conn, flight_number: str, flight_date: date, if orig_iata == origin_iata and dest_iata == destination_iata: return (row[0], row[1]) - return (rows[0][0], rows[0][1]) + # No route match — do not return a wrong track + return None # ── point fetchers ──────────────────────────────────────────── @@ -367,7 +369,7 @@ def update_noise_grid(conn, flight_date: date): round(lon::numeric, 2) AS grid_lon, %s AS period_date, COUNT(DISTINCT flight_id) AS flight_count, - AVG(noise_score) AS noise_score, + AVG(tp.noise_score) AS noise_score, AVG(altitude_m) AS avg_altitude_m, now() FROM fr24_mart.track_points tp @@ -387,6 +389,14 @@ def update_noise_grid(conn, flight_date: date): def update_source_coverage(conn, flight_date: date): """Recalculate source_coverage for the date.""" with conn.cursor() as cur: + cur.execute( + "SELECT count(*), count(*) FILTER(WHERE has_fr24), count(*) FILTER(WHERE has_rtlsdr)" + " FROM fr24_mart.flights WHERE flight_date = %s", + (flight_date,), + ) + row = cur.fetchone() + log.info("source_coverage debug: total=%s fr24=%s rtlsdr=%s", *row) + cur.execute( """ INSERT INTO fr24_mart.source_coverage