From 8e67b89a1d713d7e3f7b54ed9d6aaf502a69dcbe Mon Sep 17 00:00:00 2001 From: Sven Geboers Date: Wed, 1 Apr 2026 01:46:13 +0200 Subject: [PATCH] fix(trajectory): fix division by zero and None handling in name normalization --- explorer.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/explorer.py b/explorer.py index 8aa6359..4b30368 100644 --- a/explorer.py +++ b/explorer.py @@ -1653,7 +1653,7 @@ def build_trajectories_tab(db_path: str, window_size: str) -> None: def normalize_mp_name(name): """Normalize MP name for better matching between data sources.""" if not name: - return name + return "" # Remove extra whitespace name = name.strip() # Ensure consistent spacing after comma @@ -1678,9 +1678,12 @@ def build_trajectories_tab(db_path: str, window_size: str) -> None: all_mp_names.update(positions.keys()) matched_names = sum(1 for mp in all_mp_names if mp in party_map) - logger.info( - f"MP name matching: {matched_names}/{len(all_mp_names)} matched ({100 * matched_names / len(all_mp_names):.1f}%)" - ) + if all_mp_names: + logger.info( + f"MP name matching: {matched_names}/{len(all_mp_names)} matched ({100 * matched_names / len(all_mp_names):.1f}%)" + ) + else: + logger.info("MP name matching: no MPs found in positions data") if matched_names == 0 and len(all_mp_names) > 0: logger.warning("No MP names matched between positions and party_map!")