Skip to content

Commit d707c0f

Browse files
authored
fix: GBFS duplicated versions (#1275)
1 parent f00a829 commit d707c0f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

functions-python/gbfs_validator/src/gbfs_data_processor.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,18 @@ def create_validation_report_entities(
405405
]
406406
return validation_report
407407

408+
def validate_gbfs_endpoint_url(self, endpoint_url: str) -> bool:
409+
"""Checks if a gbfs endpoint exists across all versions with the specified URL."""
410+
for version in self.gbfs_versions:
411+
version_id = f"{self.stable_id}_{version.version}_{version.extracted_from}"
412+
endpoints = self.gbfs_endpoints.get(version_id, [])
413+
if any(endpoint.url == endpoint_url for endpoint in endpoints):
414+
return True
415+
return False
416+
408417
def extract_endpoints_for_all_versions(self):
409418
"""Extract endpoints for all versions of the GBFS feed."""
419+
version_delete_list = []
410420
for version in self.gbfs_versions:
411421
version_id = f"{self.stable_id}_{version.version}_{version.extracted_from}"
412422
if version_id in self.gbfs_endpoints:
@@ -417,9 +427,32 @@ def extract_endpoints_for_all_versions(self):
417427
version.url, "gbfs_versions", latency=False
418428
)
419429
if endpoints:
430+
# Check if the gbfs endpoint is already present in another version
431+
gbfs_endpoint_url = next(
432+
(ep.url for ep in endpoints if ep.name == "gbfs"), None
433+
)
434+
if (
435+
gbfs_endpoint_url
436+
and version.extracted_from == "gbfs_versions"
437+
and self.validate_gbfs_endpoint_url(gbfs_endpoint_url)
438+
):
439+
self.logger.warning(
440+
"The 'gbfs' endpoint URL %s is already present in another version.",
441+
gbfs_endpoint_url,
442+
)
443+
version_delete_list.append(version)
444+
continue
445+
420446
self.gbfs_endpoints[version_id] = endpoints
421447
else:
422448
self.logger.error("No endpoints found for version %s.", version.version)
449+
# Remove versions that had no endpoints extracted
450+
for version in version_delete_list:
451+
version_id = f"{self.stable_id}_{version.version}_{version.extracted_from}"
452+
self.logger.warning(
453+
"Removing version %s due to duplicated 'gbfs' endpoint.", version_id
454+
)
455+
self.gbfs_versions.remove(version)
423456

424457
def trigger_location_extraction(self):
425458
"""Trigger the location extraction process."""

0 commit comments

Comments
 (0)