feat: add year selector for SVD components 3-10
- Add _load_mp_vectors_by_party_for_window() to load SVD vectors for specific windows - Add load_party_axis_scores_for_window() cached function - Add year selector UI for components 3-10 similar to components 1-2 - Uses get_uniform_dim_windows() to get available windows
This commit is contained in:
+26
@@ -2931,7 +2931,33 @@ def build_svd_components_tab(db_path: str) -> None:
|
|||||||
else {}
|
else {}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Components 3-10: use SVD vectors with year selection
|
||||||
|
# Get available windows from svd_vectors
|
||||||
|
available_windows = get_uniform_dim_windows(db_path)
|
||||||
|
year_windows = sorted(w for w in available_windows if w != "current_parliament")
|
||||||
|
has_current = "current_parliament" in available_windows
|
||||||
|
svd_windows = year_windows + (["current_parliament"] if has_current else [])
|
||||||
|
|
||||||
|
def _svd_window_label(w: str) -> str:
|
||||||
|
if w == "current_parliament":
|
||||||
|
return "Huidig parlement"
|
||||||
|
return w
|
||||||
|
|
||||||
|
with col1:
|
||||||
|
svd_window = st.selectbox(
|
||||||
|
"Jaar",
|
||||||
|
options=svd_windows,
|
||||||
|
index=len(svd_windows) - 1, # default: current_parliament
|
||||||
|
format_func=_svd_window_label,
|
||||||
|
key=f"svd_window_{comp_sel}",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Load party scores for the selected window
|
||||||
|
if svd_window == "current_parliament":
|
||||||
party_scores = party_scores_default
|
party_scores = party_scores_default
|
||||||
|
else:
|
||||||
|
party_scores = load_party_axis_scores_for_window(db_path, svd_window)
|
||||||
|
|
||||||
# For components 3-10, compute MP counts from party_mp_vectors
|
# For components 3-10, compute MP counts from party_mp_vectors
|
||||||
party_mp_counts = (
|
party_mp_counts = (
|
||||||
{p: len(v) for p, v in party_mp_vectors.items()} if party_mp_vectors else {}
|
{p: len(v) for p, v in party_mp_vectors.items()} if party_mp_vectors else {}
|
||||||
|
|||||||
Reference in New Issue
Block a user