Skip to content

Commit 1b80647

Browse files
authored
🎨 save session state of autogrowth detection (#55)
1 parent 7aece4a commit 1b80647

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

AutoGrowth/2_turbiostat.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,11 @@ def _run_model_fitting_on_df_with_peaks_compat(
197197
key="remove_downward_trending",
198198
)
199199

200-
minimum_peak_height = None
201-
minimum_distance = int(st.session_state.get("turbiostat_distance", 300))
200+
# Automatic peak detection inputs are only persisted across page switches
201+
# once an analysis has actually been run (see the save below the
202+
# "Run Analysis" gate), so unrun edits don't linger after navigating away.
203+
minimum_peak_height = st.session_state.get("turbidostat_min_peak_height")
204+
minimum_distance = int(st.session_state.get("turbidostat_min_distance", 300))
202205
if use_uploaded_peak_times:
203206
meta_label = (
204207
turbidostat_meta_name if turbidostat_meta_name else "uploaded_metadata.csv"
@@ -224,17 +227,16 @@ def _run_model_fitting_on_df_with_peaks_compat(
224227
"series."
225228
),
226229
min_value=0.0,
227-
value=None,
230+
value=minimum_peak_height,
228231
)
229232
minimum_distance = st.number_input(
230233
label=(
231234
"Minimum distance between peaks "
232235
"(in number of measurement timepoints)"
233236
),
234237
min_value=3,
235-
value=300,
238+
value=minimum_distance,
236239
step=1,
237-
key="turbiostat_distance",
238240
)
239241

240242
smoothing_range = get_smoothing_range(len(df_rolling))
@@ -265,6 +267,11 @@ def _run_model_fitting_on_df_with_peaks_compat(
265267

266268
st.session_state["show_error"] = False
267269

270+
# Persist automatic peak detection inputs now that the analysis has run, so
271+
# they're restored when the user navigates away and back to this page.
272+
st.session_state["turbidostat_min_peak_height"] = minimum_peak_height
273+
st.session_state["turbidostat_min_distance"] = minimum_distance
274+
268275
if turbidostat_meta_bytes is not None:
269276
df_meta = pd.read_csv(
270277
BytesIO(turbidostat_meta_bytes), parse_dates=["timestamp_localtime"]

0 commit comments

Comments
 (0)