feat: auto-compute flip directions for all SVD components (Task 6)

main
Sven Geboers 4 weeks ago
parent bda803089a
commit ba24ad4fe6
  1. 13
      explorer.py

@ -2877,6 +2877,19 @@ def build_svd_components_tab(db_path: str) -> None:
{p: len(v) for p, v in party_mp_vectors.items()} if party_mp_vectors else {}
)
# Auto-compute flip directions for all components based on party centroids
# This ensures right-wing parties consistently appear on the right side
try:
from analysis.svd_labels import compute_flip_direction
for comp in range(1, 11):
flip = compute_flip_direction(comp, party_scores)
if comp in SVD_THEMES:
SVD_THEMES[comp]["flip"] = flip
except Exception:
# If flip computation fails, keep existing flip values in SVD_THEMES
pass
# Convert party_scores (possibly [x,y] lists or legacy vectors) into explicit (x,y) coords
party_coords: dict = {}
for p, v in party_scores.items():

Loading…
Cancel
Save