File size: 3,597 Bytes
d391513
85902d5
aa639ce
 
d391513
e6e4c0a
 
a8ce126
85902d5
f1672d2
 
2ba1cfe
85902d5
aa639ce
85902d5
 
139e4cc
 
aa639ce
139e4cc
aa639ce
 
139e4cc
 
975e7b1
85902d5
f1672d2
139e4cc
f1672d2
139e4cc
 
 
 
 
 
 
 
 
 
f1672d2
 
2ba1cfe
139e4cc
f1672d2
 
 
 
 
 
 
 
 
 
 
 
 
 
d12a02a
 
 
 
f1672d2
 
 
 
 
 
 
 
 
 
 
b0eecf1
d12a02a
f1672d2
 
 
 
 
d12a02a
 
 
f1672d2
 
 
 
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
import streamlit as st
import pandas as pd
import time


st.header("Plotting Time Series Data")
st.markdown("Users can load their time-series data in **.csv** format and select a particular feature and plot-type.\
 Go ahead and use the sidebar on the left to upload your data files to start visualizing it!")

tab1, tab2 = st.tabs(["Main", "Demo"])

# Load and config
with st.sidebar:
    plot = st.radio("Select the kind of visualization:",('Feature collection', 'Users comparison', 'Data distribution'))
    file = st.file_uploader("Load CSV file", accept_multiple_files = False)
    if file:
        df_p = pd.read_csv(file, index_col = False)
        # df_p.index = df_p['Unnamed: 0'].tolist()
        try:
            del df_p['Unnamed: 0']
        except KeyError:
            pass
        if 'df_p' not in st.session_state:
                st.session_state['df_p'] = df_p
        st.success("Your data has been successfully loaded! πŸ€—")

with tab1:
    if 'df_p' in st.session_state:
        st.caption("Your uploaded data:")
        st.dataframe(st.session_state.df_p)
    elif 'df_right' in st.session_state:
        st.caption("Your data:")
        st.dataframe(st.session_state.df_right)
        if 'df_p' not in st.session_state:
                df_p = st.session_state.df_right
                st.session_state['df_p'] = df_p
        else:
                df_p = st.session_state.df_right
                st.session_state.df_p = df_p
    else:
        st.caption("Upload your data using the sidebar and select a plot-type to start :sunglasses:")
    
    df_base = st.session_state.df_p if 'df_p' in st.session_state else pd.DataFrame()
    n = len(df_base)
    col1, col2 = st.columns(2)
    
    # Prepare data
    if not df_base.empty and n:
        with col1:
            st.info(f"Your data has {n} samples.")
        slider_range = list(range(n))
        n_plot = st.slider("How many samples do you want to plot in the same graph", slider_range[0]+1, slider_range[-1]+1, 5)
        plot_it = st.button("Plot now! πŸ“Š")
        if plot_it:
            st.snow()
            feature = "relative_pupil_dilation"
            df_plot = df_base.head(n_plot)
            try:
                df_plot = [ini_list.strip('][').split(',') for ini_list in df_plot[feature]]
            except AttributeError:
                df_plot = [ini_list for ini_list in df_plot[feature]]
            df_plot = pd.DataFrame(df_plot)
            df_plot.columns = [str(column) for column in range(len(df_plot.columns))]
            if 'df_plot' not in st.session_state:
                st.session_state['df_plot'] = df_plot
    
    # Draw plot
    if 'df_plot' in st.session_state:
        with st.spinner(f"Drawing plot to visualize {plot.lower()}"):
            st.caption("Your visualization:")
            df_plot_t = df_plot.copy(deep=True).transpose()
            df_plot_t.columns = [str(column) for column in range(len(df_plot_t.columns))]
            st.line_chart(df_plot_t, y=list(df_plot_t.columns), height=450, width=600)
            # st.dataframe(df_plot_t)
            with st.expander("See explanation"):
                    st.caption("The chart above shows...")
    elif df_base.empty and file:
        st.warning("Consider running outlier detection to clean your data!", icon="⚠️")
        
    # st.caption(f"developer:: session_state keys: {list(st.session_state.keys())}")
    # st.caption(f"what is the meaning of the x-axis, add to explanation")
    # st.caption(f"add sample data demo in another tab")

# demo
with tab2:
    st.caption("demo under construction 🚧")