fix(trajectory): fix division by zero and None handling in name normalization
This commit is contained in:
+7
-4
@@ -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!")
|
||||
|
||||
Reference in New Issue
Block a user