fix: skip second trace loop when helper succeeds to avoid duplicate traces

main
Sven Geboers 1 month ago
parent 5d1328f824
commit 69208e0bf6
  1. 66
      explorer.py

@ -1963,6 +1963,7 @@ def build_trajectories_tab(db_path: str, window_size: str) -> None:
fig = go.Figure() fig = go.Figure()
trace_count = 0 trace_count = 0
helper_succeeded = False
# New: delegate plotting selection to helper for testability # New: delegate plotting selection to helper for testability
# Note: select_trajectory_plot_data returns (fig, trace_count, banner_text) # Note: select_trajectory_plot_data returns (fig, trace_count, banner_text)
try: try:
@ -1973,6 +1974,7 @@ def build_trajectories_tab(db_path: str, window_size: str) -> None:
if fig2 is not None: if fig2 is not None:
fig = fig2 fig = fig2
trace_count = trace_count2 trace_count = trace_count2
helper_succeeded = True
if banner_text: if banner_text:
try: try:
st.caption(banner_text) st.caption(banner_text)
@ -2002,38 +2004,40 @@ def build_trajectories_tab(db_path: str, window_size: str) -> None:
st.text_area("select_trajectory_plot_data traceback", tb, height=240) st.text_area("select_trajectory_plot_data traceback", tb, height=240)
except Exception: except Exception:
pass pass
for party in selected_parties: print(f"[TRAJ DEBUG] helper_succeeded={helper_succeeded}")
if party not in centroids: if not helper_succeeded:
continue for party in selected_parties:
wids_sorted = sorted(centroids[party].keys()) if party not in centroids:
xs_raw = [centroids[party][w][0] for w in wids_sorted] continue
ys_raw = [centroids[party][w][1] for w in wids_sorted] wids_sorted = sorted(centroids[party].keys())
xs = _ema_smooth(xs_raw, smooth_alpha) xs_raw = [centroids[party][w][0] for w in wids_sorted]
ys = _ema_smooth(ys_raw, smooth_alpha) ys_raw = [centroids[party][w][1] for w in wids_sorted]
# Preserve raw (unsmoothed) values per-point so hover can show both raw and smoothed xs = _ema_smooth(xs_raw, smooth_alpha)
custom_raw = [(float(rx), float(ry)) for rx, ry in zip(xs_raw, ys_raw)] ys = _ema_smooth(ys_raw, smooth_alpha)
colour = PARTY_COLOURS.get(party, "#9E9E9E") # Preserve raw (unsmoothed) values per-point so hover can show both raw and smoothed
fig.add_trace( custom_raw = [(float(rx), float(ry)) for rx, ry in zip(xs_raw, ys_raw)]
go.Scatter( colour = PARTY_COLOURS.get(party, "#9E9E9E")
x=xs, fig.add_trace(
y=ys, go.Scatter(
mode="lines+markers", x=xs,
name=party, y=ys,
text=wids_sorted, # full window ID for hover mode="lines+markers",
customdata=custom_raw, name=party,
line=dict(color=colour, shape="spline", smoothing=1.3), text=wids_sorted, # full window ID for hover
marker=dict(color=colour, size=8), customdata=custom_raw,
hovertemplate=( line=dict(color=colour, shape="spline", smoothing=1.3),
f"<b>{party}</b><br>" marker=dict(color=colour, size=8),
"venster: %{text}<br>" hovertemplate=(
"x (smoothed): %{x:.3f}<br>" f"<b>{party}</b><br>"
"x (raw): %{customdata[0]:.3f}<br>" "venster: %{text}<br>"
"y (smoothed): %{y:.3f}<br>" "x (smoothed): %{x:.3f}<br>"
"y (raw): %{customdata[1]:.3f}<extra></extra>" "x (raw): %{customdata[0]:.3f}<br>"
), "y (smoothed): %{y:.3f}<br>"
"y (raw): %{customdata[1]:.3f}<extra></extra>"
),
)
) )
) trace_count += 1
trace_count += 1
# For trajectories, the chart spans multiple windows. Use the classifier's # For trajectories, the chart spans multiple windows. Use the classifier's
# per-window confidences aggregated (mean) to decide whether to use the # per-window confidences aggregated (mean) to decide whether to use the

Loading…
Cancel
Save