From 0541c72bbdec8b836169b6c029c6389e47ceee1c Mon Sep 17 00:00:00 2001 From: Phaeton <808865+Phaeton@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:24:56 -0400 Subject: [PATCH 1/2] Remove image ICAOs without matching DB entry --- scripts/create_db_derivatives.py | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/scripts/create_db_derivatives.py b/scripts/create_db_derivatives.py index 2eecfb83..e321f500 100644 --- a/scripts/create_db_derivatives.py +++ b/scripts/create_db_derivatives.py @@ -109,3 +109,47 @@ logging.info("New ICAOs successfully saved in 'plane_images.csv' file.") else: logging.info("No new ICAOs. Nothing to do.") + + logging.info( + "Check for removed ICAOs in DB files and remove them to the images reference file..." + ) + + if images_df.shape[0] > plane_alert_df.shape[0]: + logging.info( + "Extra ICAOs found ({})".format( + images_df.shape[0] - plane_alert_df.shape[0] + ) + ) + + extra_icao_df = pd.merge( + images_df, plane_alert_df, on="$ICAO", how="left", indicator=True + ) + + extra_icao_df = extra_icao_df.loc[ + extra_icao_df["_merge"] == "left_only" + ].index.tolist() + for item in extra_icao_df: + if "plane_images_df" in locals(): + plane_images_df = plane_images_df.drop(item) + plane_images_df.to_csv( + "plane_images.csv", + mode="wb", + index=False, + header=True, + encoding="utf8", + lineterminator="\n", + ) + else: + images_df = images_df.drop(item) + images_df.to_csv( + "plane_images.csv", + mode="wb", + index=False, + header=True, + encoding="utf8", + lineterminator="\n", + ) + logging.info("Extra ICAOs successfully removed from 'plane_images.csv'") + + else: + logging.info("No extra ICAOs. Nothing to do.") From e4be5db3984b995597c4edd337c17f3ed17124fa Mon Sep 17 00:00:00 2001 From: Phaeton <808865+Phaeton@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:03:54 -0400 Subject: [PATCH 2/2] Update logging verbiage --- scripts/create_db_derivatives.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create_db_derivatives.py b/scripts/create_db_derivatives.py index e321f500..a8214fa7 100644 --- a/scripts/create_db_derivatives.py +++ b/scripts/create_db_derivatives.py @@ -111,7 +111,7 @@ logging.info("No new ICAOs. Nothing to do.") logging.info( - "Check for removed ICAOs in DB files and remove them to the images reference file..." + "Check for removed ICAOs in DB files and also remove them from the images reference file..." ) if images_df.shape[0] > plane_alert_df.shape[0]: