File size: 2,663 Bytes
d391513
85902d5
aa639ce
 
d391513
e6e4c0a
 
85902d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa639ce
85902d5
aa639ce
85902d5
 
975e7b1
b01cb1f
aa639ce
 
 
 
85902d5
 
975e7b1
85902d5
 
975e7b1
 
 
823d19a
975e7b1
449b912
975e7b1
e6e4c0a
aa639ce
 
 
e6e4c0a
 
 
 
aa639ce
 
 
 
 
 
 
 
 
 
 
39b197f
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
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 and to start visualizing it!")


def plot_collection(plot_only_this, collection, number_of_desired_plots=0):
  fig = go.Figure()
  plots_count = 0
  print("total number of graphs: ", len(collection))

  for (pattern_name, d) in collection:
    if pattern_name == plot_only_this:
      if plots_count ==0:
        fig.add_trace(go.Line(y=d))
        fig.update_layout(title=plot_only_this)
      else:
        fig.add_trace(go.Line(y=d))
      plots_count += 1
      fig.update_layout(width=1200, height=800)
      if number_of_desired_plots:
        if plots_count == number_of_desired_plots:
          break

            
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 = pd.read_csv(file, index_col = False)
        # df.index = df['Unnamed: 0'].tolist()
        try:
            del df['Unnamed: 0']
        except KeyError:
            pass
        if 'df' not in st.session_state:
                st.session_state['df'] = df
        st.success("Your data has been successfully loaded! πŸ€—")

if 'df' in list(st.session_state.keys()):
    st.markdown("Your uploaded data:") 
    st.dataframe(st.session_state.df)
else:
    st.caption("Upload your data using the sidebar and select a plot-type to start :sunglasses:")

df_base = st.session_state.df if 'df' in list(st.session_state.keys()) else pd.DataFrame()
n = len(df_base)
col1, col2 = st.columns(2)

if not df_base.empty:
    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)
        st.write(f"Action: {plot} using {n_plot} samples")
        plot_it = st.button("Plot now! πŸ“Š")
        if plot_it:
            with st.spinner(f"Drawing plot to visualize {plot.lower()}"):
                while True:
                    time.sleep(4)
            # create a DataFrame with each run in the columns (depending on n)
            with st.expander("See explanation"):
                st.write(\"\"\"
                    The chart above shows...
                \"\"\")
else:
    st.warning("Consider running outlier detection to clean your data!", icon="⚠️")