Skip to content

Commit 29e37b6

Browse files
committed
Add sidebar persistence
1 parent e7c07c5 commit 29e37b6

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

Recent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main():
2020

2121
last_projects = conn.sql(f"""
2222
WITH maxdate AS (
23-
select (date_trunc('day', max(author_when)) - interval '3 day')::date as maxdate
23+
select (date_trunc('day', max(author_when)) - interval '7 day')::date as maxdate
2424
from git_commits JOIN repos ON git_commits.repo_id=repos.id
2525
WHERE {filters.commit_filter}
2626
)
@@ -31,7 +31,7 @@ def main():
3131
GROUP BY repo
3232
ORDER BY count(hash) DESC LIMIT 100
3333
""", params=filters.commit_params).df()
34-
st.markdown("### Most active in last 3 days")
34+
st.markdown("### Most active in last 7 days")
3535
st.dataframe(last_projects, hide_index=True)
3636

3737
if __name__ == '__main__':

utils.py

+45-16
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def commit_filter(self):
6161
"""
6262

6363
def get_sidebar_filters(conn):
64-
6564
st.markdown("""
6665
<style>
6766
[data-testid="stSidebarNavItems"] {
@@ -70,35 +69,65 @@ def get_sidebar_filters(conn):
7069
</style>
7170
""", unsafe_allow_html=True)
7271

72+
time_range = conn.sql("select date_trunc('month', min(author_when) - interval '15 day')::date as min, date_trunc('month', max(author_when) + interval '15 day')::date as max from git_commits").df()
73+
time_range = pd.date_range(start=time_range['min'][0], end=time_range['max'][0], freq='MS')
74+
75+
if 'provider' not in st.session_state:
76+
st.session_state['provider'] = None
77+
if 'granularity' not in st.session_state:
78+
st.session_state['granularity'] = 'week'
79+
if 'time_from' not in st.session_state:
80+
st.session_state['time_from'] = time_range[0]
81+
if 'time_to' not in st.session_state:
82+
st.session_state['time_to'] = time_range[-1]
83+
if 'pos_repo' not in st.session_state:
84+
st.session_state['pos_repo'] = None
85+
if 'neg_repo' not in st.session_state:
86+
st.session_state['neg_repo'] = 'mautic|matomo|imagemagick|osm2pgsql|simplesamle-php-upstream'
87+
if 'pos_author' not in st.session_state:
88+
st.session_state['pos_author'] = None
89+
if 'neg_author' not in st.session_state:
90+
st.session_state['neg_author'] = 'lctl.gov|immerda.ch|unige.ch|bastelfreak.de|kohlvanwijngaarden.nl'
91+
7392
with st.sidebar:
74-
time_range = conn.sql("select date_trunc('month', min(author_when) - interval '15 day')::date as min, date_trunc('month', max(author_when) + interval '15 day')::date as max from git_commits").df()
75-
time_range = pd.date_range(start=time_range['min'][0], end=time_range['max'][0], freq='MS')
7693
time_range = st.select_slider(
7794
"Month range",
7895
options=time_range,
79-
value=(time_range[0], time_range[-1]),
96+
value=(st.session_state['time_from'], st.session_state['time_to']),
8097
format_func=lambda x: str(x)[0:7]
8198
)
8299

83-
p_repo = st.text_input('Repository (regex)', '')
84-
p_negrepo = st.text_input('Repository exclusion (regex)', 'mautic|matomo|imagemagick|osm2pgsql|simplesamle-php-upstream')
85-
p_author = st.text_input('Author name/email (regex)', '')
86-
p_negauthor = st.text_input('Author name/email exclusion (regex)', 'lctl.gov|immerda.ch|unige.ch|bastelfreak.de|kohlvanwijngaarden.nl')
100+
pos_repo = st.text_input('Repository (regex)', st.session_state['pos_repo'])
101+
neg_repo = st.text_input('Repository exclusion (regex)', st.session_state['neg_repo'])
102+
pos_author = st.text_input('Author name/email (regex)', st.session_state['pos_author'])
103+
neg_author = st.text_input('Author name/email exclusion (regex)', st.session_state['neg_author'])
104+
105+
g_options = ['week', 'month', 'year', 'day']
106+
g_index = g_options.index(st.session_state['granularity']) if st.session_state['granularity'] in g_options else None
107+
granularity = st.selectbox("Graph granularity", options=g_options, index=g_index)
87108

88-
granularity = st.selectbox("Graph granularity", options=['week', 'month', 'year', 'day']) or 'week'
109+
p_options = list(conn.sql('select name from providers').df()['name'])
110+
p_index = p_options.index(st.session_state['provider']) if st.session_state['provider'] in p_options else None
111+
p_provider = st.selectbox("Forge", options=p_options, index=p_index)
89112

90-
providers = conn.sql('select name from providers').df()
91-
p_provider = st.selectbox("Forge", options=providers['name'], index=None)
113+
st.session_state['provider'] = p_provider
114+
st.session_state['granularity'] = granularity
115+
st.session_state['time_from'] = time_range[0]
116+
st.session_state['time_to'] = time_range[1]
117+
st.session_state['pos_repo'] = pos_repo
118+
st.session_state['neg_repo'] = neg_repo
119+
st.session_state['pos_author'] = pos_author
120+
st.session_state['neg_author'] = neg_author
92121

93122
return Filters(
94123
provider=p_provider,
95-
pos_repo=f".*({p_repo}).*" if p_repo else None,
96-
neg_repo=f".*({p_negrepo}).*" if p_negrepo else None,
97-
pos_author=f".*({p_author}).*" if p_author else None,
98-
neg_author=f".*({p_negauthor}).*" if p_negauthor else None,
124+
pos_repo=f".*({pos_repo}).*" if pos_repo else None,
125+
neg_repo=f".*({neg_repo}).*" if neg_repo else None,
126+
pos_author=f".*({pos_author}).*" if pos_author else None,
127+
neg_author=f".*({neg_author}).*" if neg_author else None,
99128
time_from=time_range[0],
100129
time_to=time_range[1],
101-
granularity=granularity,
130+
granularity=granularity or 'week',
102131
)
103132

104133

0 commit comments

Comments
 (0)