diff --git a/explorer.py b/explorer.py index 056a1ae..d770950 100644 --- a/explorer.py +++ b/explorer.py @@ -19,6 +19,7 @@ import logging import os import re import traceback +from datetime import datetime from typing import Dict, List, Optional, Tuple try: @@ -2096,6 +2097,36 @@ def choose_trajectory_title(axis_def: dict, axis: str, threshold: float = 0.65) except Exception: pass debug_enabled = get_debug_trajectories_enabled() + # Add detailed diagnostics to understand why trace_count is 0 + if trace_count == 0: + _last_trajectories_diagnostics.update( + { + "stage": "zero_traces", + "positions_count": sum(len(pos) for pos in positions_by_window.values()) + if positions_by_window + else 0, + "party_map_count": len(party_map) if party_map else 0, + "centroids_count": len(centroids) if centroids else 0, + "selected_parties_count": len(selected_parties) + if selected_parties + else 0, + "timestamp": datetime.now().isoformat(), + } + ) + # Check if there are positions but no centroids (name mismatch) + if positions_by_window and party_map and not centroids: + # Sample some MP names from positions + sample_mps = [] + for window, positions in list(positions_by_window.items())[:1]: + sample_mps = list(positions.keys())[:5] + break + # Check if these MPs are in party_map + matched = sum(1 for mp in sample_mps if mp in party_map) + _last_trajectories_diagnostics["name_match_check"] = { + "sample_mps": sample_mps, + "matched_in_party_map": matched, + "sample_size": len(sample_mps), + } if trace_count == 0: try: st.info(