Skip to content

Commit

Permalink
Merge pull request #54 from AllenNeuralDynamics/han_minor_tweaks
Browse files Browse the repository at this point in the history
feat: minor tweaks for the foraging meeting
  • Loading branch information
hanhou authored Apr 5, 2024
2 parents 0f7e976 + 6171475 commit 1fc70e3
Show file tree
Hide file tree
Showing 3 changed files with 8,502 additions and 2,520 deletions.
43 changes: 32 additions & 11 deletions code/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ def _fetch_img(glob_patterns, crop=None):

return img, file[0]

def _user_name_mapper(user_name):
user_mapper = { # tuple of key words --> user name
('Avalon',): 'Avalon Amaya',
('Ella',): 'Ella Hilton',
('Katrina',): 'Katrina Nguyen',
('Lucas',): 'Lucas Kinsey',
('Travis',): 'Travis Ramirez',
('Xinxin', 'the ghost'): 'Xinxin Yin',
}
for key_words, name in user_mapper.items():
for key_word in key_words:
if key_word in user_name:
return name
else:
return user_name

# @st.cache_data(ttl=24*3600, max_entries=20)
def show_session_level_img_by_key_and_prefix(key, prefix, column=None, other_patterns=[''], crop=None, caption=True, **kwargs):
Expand Down Expand Up @@ -553,7 +568,10 @@ def init():

# weekday
st.session_state.df['sessions_bonsai'].session_date = pd.to_datetime(st.session_state.df['sessions_bonsai'].session_date)
st.session_state.df['sessions_bonsai']['weekday'] = st.session_state.df['sessions_bonsai'].session_date.dt.day_name()
st.session_state.df['sessions_bonsai']['weekday'] = st.session_state.df['sessions_bonsai'].session_date.dt.dayofweek + 1

# map user_name
st.session_state.df['sessions_bonsai']['user_name'] = st.session_state.df['sessions_bonsai']['user_name'].apply(_user_name_mapper)

# foraging performance = foraing_eff * finished_rate
if 'foraging_performance' not in st.session_state.df['sessions_bonsai'].columns:
Expand All @@ -578,7 +596,6 @@ def app():
cols = st.columns([1, 1.2])
with cols[0]:
st.markdown('## 🌳🪴 Foraging sessions from Bonsai 🌳🪴')
st.markdown('##### (still using a temporary workaround until AIND behavior metadata and pipeline are set up)')

with st.sidebar:

Expand Down Expand Up @@ -606,14 +623,18 @@ def app():
# with col1:
# -- 1. unit dataframe --

cols = st.columns([2, 2, 2])
cols[0].markdown(f'### Filter the sessions on the sidebar ({len(st.session_state.df_session_filtered)} filtered)')
# if cols[1].button('Press this and then Ctrl + R to reload from S3'):
# st.rerun()
if cols[1].button('Reload data '):
st.cache_data.clear()
init()
st.rerun()
cols = st.columns([2, 1, 4, 1])
cols[0].markdown(f'### Filter the sessions on the sidebar\n'
f'##### {len(st.session_state.df_session_filtered)} sessions, '
f'{len(st.session_state.df_session_filtered.h2o.unique())} mice filtered')
with cols[1]:
st.markdown('# ')
if st.button(' Reload data ', type='primary'):
st.cache_data.clear()
init()
st.rerun()

table_height = cols[3].slider('Table height', 100, 2000, 400, 50, key='table_height')

# aggrid_outputs = aggrid_interactive_table_units(df=df['ephys_units'])
# st.session_state.df_session_filtered = aggrid_outputs['data']
Expand All @@ -625,7 +646,7 @@ def app():
st.markdown('## No filtered results!')
return

aggrid_outputs = aggrid_interactive_table_session(df=st.session_state.df_session_filtered)
aggrid_outputs = aggrid_interactive_table_session(df=st.session_state.df_session_filtered, table_height=table_height)

if len(aggrid_outputs['selected_rows']) and not set(pd.DataFrame(aggrid_outputs['selected_rows']
).set_index(['h2o', 'session']).index
Expand Down
4 changes: 2 additions & 2 deletions code/util/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"padding": "4px !important"},
}

def aggrid_interactive_table_session(df: pd.DataFrame):
def aggrid_interactive_table_session(df: pd.DataFrame, table_height: int = 400):
"""Creates an st-aggrid interactive table based on a dataframe.
Args:
Expand Down Expand Up @@ -92,7 +92,7 @@ def aggrid_interactive_table_session(df: pd.DataFrame):
theme="balham",
update_mode=GridUpdateMode.SELECTION_CHANGED,
allow_unsafe_jscode=True,
height=400,
height=table_height,
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
custom_css=custom_css,
)
Expand Down
Loading

0 comments on commit 1fc70e3

Please sign in to comment.