File size: 3,598 Bytes
89d10a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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)