import streamlit as st from utils import AgeAnalysis age_analytics = AgeAnalysis() @st.cache_resource def get_age_count_plot(): return age_analytics.age_group_count_plot() @st.cache_resource def get_age_violin_plot(): return age_analytics.age_violin_plot() st.markdown("#### Age Analysis") age_group_count, age_distibution = st.columns(2) with age_group_count: st.pyplot(fig=get_age_count_plot(), use_container_width=True) with age_distibution: with st.spinner("⏳Loading age distribution..."): st.pyplot(fig=get_age_violin_plot(), use_container_width=True) # Multiselect -- age group violin plot age_selection_for_violin = st.multiselect( "Select the Age Group and study the stats", options=['40-60', '25-40', '60-80', '80+', '<25'], default=['<25', '25-40'] ) with st.spinner("⏳Loading statistics..."): st.pyplot( fig=age_analytics.age_gender_stats_interactive( category=age_selection_for_violin), use_container_width=True ) with st.spinner(text="⏳Loading Age Analysis..."): sample_size = st.number_input( label="Sample-size", min_value=1000, max_value=1852394, step=1000, value=5000) age_polygons, age_histogram, age_kde = st.tabs( ['Polygons', 'Histograms', 'Density']) with age_polygons: color_encode = st.checkbox("Age groups", key='polygon', value=True) st.pyplot( fig=age_analytics.plot_age( sample_size=sample_size, color_encode=color_encode,), use_container_width=True) with age_histogram: color_encode = st.checkbox("Age groups", key='histogram', value=False) st.pyplot( fig=age_analytics.plot_age( sample_size=sample_size, color_encode=color_encode, element='bars'), use_container_width=True) with age_kde: color_encode = st.checkbox("Age groups", key='kde', value=False) st.pyplot( fig=age_analytics.plot_age( sample_size=sample_size, color_encode=color_encode, element='bars', kde=True, fill=False), use_container_width=True) with st.spinner(text="⏳Loading Age histogram Analysis..."): binrange_lower, binrange_upper, bin_width, hist_sample_size = st.columns(4) with binrange_lower: binrange_lower_bound = st.slider( label="Bin range lowerbound", min_value=20, max_value=100, step=1, value=30, ) with binrange_upper: binrange_upper_bound = st.slider( label="Bin range upperbound", min_value=20, max_value=100, step=1, value=60, ) with bin_width: binwidth = st.slider( label="Bin width", min_value=5, max_value=20, step=5, value=10,) with hist_sample_size: sample_size = st.number_input( label="Sample-size", min_value=1000, max_value=1852394, step=1000, value=5000, key='bin-study') if binrange_lower_bound < binrange_upper_bound: binrange = [binrange_lower_bound, binrange_upper_bound] else: st.warning( f''' Message : `lowerbound` must be less than `upperbound` ''', icon="⚠️") binrange = [30, 50] color_encode = st.checkbox("Age groups", value=False) st.pyplot( fig=age_analytics.plot_age( sample_size=sample_size, color_encode=color_encode, element='bars', binwith=binwidth, binrange=binrange, hatch='+', kde=True, fill=False), use_container_width=True)