Skip to content

Commit

Permalink
Merge pull request #67 from AllenNeuralDynamics/han_#36_query_all_fil…
Browse files Browse the repository at this point in the history
…ters

feat: #36 query all filters
  • Loading branch information
hanhou authored Apr 15, 2024
2 parents e1ccfc7 + da8cfe3 commit 138bff6
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 1,072 deletions.
74 changes: 8 additions & 66 deletions code/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

__ver__ = 'v2.2.2'
__ver__ = 'v2.3.0'

import pandas as pd
import streamlit as st
Expand All @@ -35,66 +35,14 @@
show_debug_info,
)
from util.url_query_helper import (
sync_widget_with_query, slider_wrapper_for_url_query, checkbox_wrapper_for_url_query
sync_URL_to_session_state, sync_session_state_to_URL,
slider_wrapper_for_url_query, checkbox_wrapper_for_url_query
)

from aind_auto_train.curriculum_manager import CurriculumManager
from aind_auto_train.auto_train_manager import DynamicForagingAutoTrainManager


# Sync widgets with URL query params
# https://blog.streamlit.io/how-streamlit-uses-streamlit-sharing-contextual-apps/
# dict of "key": default pairs
# Note: When creating the widget, add argument "value"/"index" as well as "key" for all widgets you want to sync with URL
to_sync_with_url_query = {
'if_load_bpod_sessions': False,

'filter_subject_id': '',
'filter_session': [0.0, None],
'filter_finished_trials': [0.0, None],
'filter_foraging_eff': [0.0, None],
'filter_task': ['all'],

'table_height': 300,

'tab_id': 'tab_session_x_y',
'x_y_plot_xname': 'session',
'x_y_plot_yname': 'foraging_performance_random_seed',
'x_y_plot_group_by': 'h2o',
'x_y_plot_if_show_dots': True,
'x_y_plot_if_aggr_each_group': True,
'x_y_plot_aggr_method_group': 'lowess',
'x_y_plot_if_aggr_all': True,
'x_y_plot_aggr_method_all': 'mean +/- sem',
'x_y_plot_smooth_factor': 5,
'x_y_plot_if_use_x_quantile_group': False,
'x_y_plot_q_quantiles_group': 20,
'x_y_plot_if_use_x_quantile_all': False,
'x_y_plot_q_quantiles_all': 20,
'x_y_plot_if_show_diagonal': False,
'x_y_plot_dot_size': 10,
'x_y_plot_dot_opacity': 0.3,
'x_y_plot_line_width': 2.0,
'x_y_plot_figure_width': 1300,
'x_y_plot_figure_height': 900,
'x_y_plot_font_size_scale': 1.0,
'x_y_plot_selected_color_map': 'Plotly',

'x_y_plot_size_mapper': 'finished_trials',
'x_y_plot_size_mapper_gamma': 1.0,
'x_y_plot_size_mapper_range': [3, 20],

'session_plot_mode': 'sessions selected from table or plot',

'auto_training_history_x_axis': 'session',
'auto_training_history_sort_by': 'subject_id',
'auto_training_history_sort_order': 'descending',
'auto_training_curriculum_name': 'Uncoupled Baiting',
'auto_training_curriculum_version': '1.0',
'auto_training_curriculum_schema_version': '1.0',
}


try:
st.set_page_config(layout="wide",
page_title='Foraging behavior browser',
Expand Down Expand Up @@ -336,14 +284,10 @@ def init():
if key in ['selected_draw_types'] or '_changed' in key:
del st.session_state[key]

# Set session state from URL
for key, default in to_sync_with_url_query.items():
sync_widget_with_query(key, default)

df = load_data(['sessions'], data_source='bonsai')

# --- Perform any data source-dependent preprocessing here ---
if st.session_state.if_load_bpod_sessions:
if (st.session_state.if_load_bpod_sessions if 'if_load_bpod_sessions' in st.session_state else False):
df_bpod = load_data(['sessions'], data_source='bpod')

# For historial reason, the suffix of df['sessions_bonsai'] just mean the data of the Home.py page
Expand Down Expand Up @@ -526,6 +470,9 @@ def _get_data_source(rig):
st.session_state.df['sessions_bonsai'] = _df # Somehow _df loses the reference to the original dataframe

st.session_state.session_stats_names = [keys for keys in _df.keys()]

# Set session state from URL
sync_URL_to_session_state()

# Establish communication between pygwalker and streamlit
init_streamlit_comm()
Expand Down Expand Up @@ -790,14 +737,9 @@ def app():
st.markdown('---\n##### Debug zone')
show_debug_info()



# Update back to URL
for key in to_sync_with_url_query:
try:
st.query_params.update({key: st.session_state[key]})
except:
print(f'Failed to update {key} to URL query')
sync_session_state_to_URL()

# st.dataframe(st.session_state.df_session_filtered, use_container_width=True, height=1000)

Expand Down
Loading

0 comments on commit 138bff6

Please sign in to comment.