From f224db258d2974f300d4499ea45a35d7776db6d6 Mon Sep 17 00:00:00 2001 From: cka-y Date: Thu, 3 Jul 2025 09:34:04 -0400 Subject: [PATCH] fix: GBFS duplicated versions --- .../gbfs_validator/src/gbfs_data_processor.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/functions-python/gbfs_validator/src/gbfs_data_processor.py b/functions-python/gbfs_validator/src/gbfs_data_processor.py index 91873a832..01b88cb0a 100644 --- a/functions-python/gbfs_validator/src/gbfs_data_processor.py +++ b/functions-python/gbfs_validator/src/gbfs_data_processor.py @@ -405,8 +405,18 @@ def create_validation_report_entities( ] return validation_report + def validate_gbfs_endpoint_url(self, endpoint_url: str) -> bool: + """Checks if a gbfs endpoint exists across all versions with the specified URL.""" + for version in self.gbfs_versions: + version_id = f"{self.stable_id}_{version.version}_{version.extracted_from}" + endpoints = self.gbfs_endpoints.get(version_id, []) + if any(endpoint.url == endpoint_url for endpoint in endpoints): + return True + return False + def extract_endpoints_for_all_versions(self): """Extract endpoints for all versions of the GBFS feed.""" + version_delete_list = [] for version in self.gbfs_versions: version_id = f"{self.stable_id}_{version.version}_{version.extracted_from}" if version_id in self.gbfs_endpoints: @@ -417,9 +427,32 @@ def extract_endpoints_for_all_versions(self): version.url, "gbfs_versions", latency=False ) if endpoints: + # Check if the gbfs endpoint is already present in another version + gbfs_endpoint_url = next( + (ep.url for ep in endpoints if ep.name == "gbfs"), None + ) + if ( + gbfs_endpoint_url + and version.extracted_from == "gbfs_versions" + and self.validate_gbfs_endpoint_url(gbfs_endpoint_url) + ): + self.logger.warning( + "The 'gbfs' endpoint URL %s is already present in another version.", + gbfs_endpoint_url, + ) + version_delete_list.append(version) + continue + self.gbfs_endpoints[version_id] = endpoints else: self.logger.error("No endpoints found for version %s.", version.version) + # Remove versions that had no endpoints extracted + for version in version_delete_list: + version_id = f"{self.stable_id}_{version.version}_{version.extracted_from}" + self.logger.warning( + "Removing version %s due to duplicated 'gbfs' endpoint.", version_id + ) + self.gbfs_versions.remove(version) def trigger_location_extraction(self): """Trigger the location extraction process."""