@@ -302,7 +302,7 @@ def show_curriculums():
302302
303303
304304# ------- Layout starts here -------- #
305- def init (if_load_bpod_data_override = None , if_load_docDB_override = None ):
305+ def init (if_load_bpod_data_override = None , if_load_docDB_override = None , if_load_sessions_older_than_6_month_override = None ):
306306
307307 # Clear specific session state and all filters
308308 for key in st .session_state :
@@ -319,9 +319,25 @@ def init(if_load_bpod_data_override=None, if_load_docDB_override=None):
319319 if 'if_load_bpod_sessions' in st .session_state
320320 else False )
321321 st .session_state .bpod_loaded = _if_load_bpod
322-
322+
323+ _if_load_sessions_older_than_6_month = (
324+ if_load_sessions_older_than_6_month_override
325+ if if_load_sessions_older_than_6_month_override is not None
326+ else (
327+ st .query_params ["if_load_sessions_older_than_6_month" ].lower () == "true"
328+ if "if_load_sessions_older_than_6_month" in st .query_params
329+ else (
330+ st .session_state .if_load_sessions_older_than_6_month
331+ if "if_load_sessions_older_than_6_month" in st .session_state
332+ else False
333+ )
334+ )
335+ )
336+
323337 # --- Load data using aind-analysis-arch-result-access ---
324- df_han = get_session_table (if_load_bpod = _if_load_bpod )
338+ # Convert boolean to months: if True, load all sessions (None), if False, load only recent 6 months
339+ only_recent_n_month = None if _if_load_sessions_older_than_6_month else 6
340+ df_han = get_session_table (if_load_bpod = _if_load_bpod , only_recent_n_month = only_recent_n_month )
325341 df = {'sessions_main' : df_han } # put it in df['session_main'] for backward compatibility
326342
327343 if not len (df ):
@@ -332,38 +348,12 @@ def init(if_load_bpod_data_override=None, if_load_docDB_override=None):
332348 st .session_state [f'df_selected_from_{ source } ' ] = pd .DataFrame (columns = ['subject_id' , 'session' ])
333349
334350 # Load autotrain
335- auto_train_manager , curriculum_manager = load_auto_train ()
336- st .session_state .auto_train_manager = auto_train_manager
351+ _ , curriculum_manager = load_auto_train ()
337352 st .session_state .curriculum_manager = curriculum_manager
338353
339354 # Some ad-hoc modifications on df_sessions
340355 _df = st .session_state .df ['sessions_main' ].copy ()
341356
342-
343- # -- overwrite the `if_stage_overriden_by_trainer`
344- # Previously it was set to True if the trainer changes stage during a session.
345- # But it is more informative to define it as whether the trainer has overridden the curriculum.
346- # In other words, it is set to True only when stage_suggested ~= stage_actual, as defined in the autotrain curriculum.
347- _df .drop (columns = ['if_overriden_by_trainer' ], inplace = True )
348- tmp_auto_train = (
349- auto_train_manager .df_manager .query ("if_closed_loop == True" )[
350- [
351- "subject_id" ,
352- "session_date" ,
353- "current_stage_suggested" ,
354- "if_stage_overriden_by_trainer" ,
355- ]
356- ]
357- .copy ()
358- .drop_duplicates (subset = ["subject_id" , "session_date" ], keep = "first" )
359- )
360- tmp_auto_train ["session_date" ] = pd .to_datetime (tmp_auto_train ["session_date" ])
361- _df = _df .merge (
362- tmp_auto_train ,
363- on = ["subject_id" , "session_date" ],
364- how = 'left' ,
365- )
366-
367357 # --- Load data from docDB ---
368358 if_load_docDb = if_load_docDB_override if if_load_docDB_override is not None else (
369359 st .query_params ['if_load_docDB' ].lower () == 'true'
@@ -439,9 +429,6 @@ def app():
439429 # -- 1. unit dataframe --
440430
441431 cols = st .columns ([4 , 4 , 4 , 1 ])
442- cols [0 ].markdown (f'### Filter the sessions on the sidebar\n '
443- f'##### { len (st .session_state .df_session_filtered )} sessions, '
444- f'{ len (st .session_state .df_session_filtered .subject_id .unique ())} mice filtered' )
445432
446433 with cols [0 ].expander (':bulb: Get the master session table by code' , expanded = False ):
447434 st .code (f'''
@@ -453,6 +440,12 @@ def app():
453440
454441 with cols [1 ]:
455442 with st .form (key = 'load_settings' , clear_on_submit = False ):
443+ if_load_sessions_older_than_6_month = checkbox_wrapper_for_url_query (
444+ st_prefix = st ,
445+ label = 'Include sessions older than 6 months (reload after change)' ,
446+ key = 'if_load_sessions_older_than_6_month' ,
447+ default = False ,
448+ )
456449 if_load_bpod_sessions = checkbox_wrapper_for_url_query (
457450 st_prefix = st ,
458451 label = 'Include old Bpod sessions (reload after change)' ,
@@ -472,6 +465,12 @@ def app():
472465 sync_session_state_to_URL ()
473466 init ()
474467 st .rerun () # Reload the page to apply the changes
468+
469+ cols [0 ].markdown (f'### Filter the sessions on the sidebar\n ' +
470+ f'##### { len (st .session_state .df_session_filtered )} sessions, ' +
471+ f'{ len (st .session_state .df_session_filtered .subject_id .unique ())} mice filtered' +
472+ (f' (recent 6 months only)' if not st .session_state .if_load_sessions_older_than_6_month else '' )
473+ )
475474
476475 table_height = slider_wrapper_for_url_query (st_prefix = cols [- 1 ],
477476 label = 'Table height' ,
@@ -696,4 +695,4 @@ def add_main_tabs():
696695 st .markdown ('#### 1. Reload the page' )
697696 st .markdown ('#### 2. Click this original URL https://foraging-behavior-browser.allenneuraldynamics-test.org/' )
698697 st .markdown ('#### 3. Report your bug here: https://github.com/AllenNeuralDynamics/foraging-behavior-browser/issues (paste your URL and screenshoots)' )
699- raise e
698+ raise e
0 commit comments