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):
|
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)
|
||||||
logger.info(
|
if all_mp_names:
|
||||||
f"MP name matching: {matched_names}/{len(all_mp_names)} matched ({100 * matched_names / len(all_mp_names):.1f}%)"
|
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:
|
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!")
|
||||||
|
|||||||
Reference in New Issue
Block a user