fix(trajectory): fix division by zero and None handling in name normalization

main
Sven Geboers 1 month ago
parent 0b79709847
commit 8e67b89a1d
  1. 5
      explorer.py

@ -1653,7 +1653,7 @@ def build_trajectories_tab(db_path: str, window_size: str) -> None:
def normalize_mp_name(name): def normalize_mp_name(name):
"""Normalize MP name for better matching between data sources.""" """Normalize MP name for better matching between data sources."""
if not name: if not name:
return name return ""
# Remove extra whitespace # Remove extra whitespace
name = name.strip() name = name.strip()
# Ensure consistent spacing after comma # 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()) all_mp_names.update(positions.keys())
matched_names = sum(1 for mp in all_mp_names if mp in party_map) matched_names = sum(1 for mp in all_mp_names if mp in party_map)
if all_mp_names:
logger.info( logger.info(
f"MP name matching: {matched_names}/{len(all_mp_names)} matched ({100 * matched_names / len(all_mp_names):.1f}%)" 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: if matched_names == 0 and len(all_mp_names) > 0:
logger.warning("No MP names matched between positions and party_map!") logger.warning("No MP names matched between positions and party_map!")

Loading…
Cancel
Save