File size: 2,380 Bytes
97fe216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from tools.ofi_delta import calculate_ofi_and_delta
from utils.plots import plot_multiple_columns
# import streamlit as session


def plot_by_columns(ticker, date, timeframe, session):
    session.markdown('### Stock Dataframe')

    with session.spinner(text="Downloading required data..."):
        df = calculate_ofi_and_delta(ticker=ticker, date=date, timeframe=timeframe)

    session.dataframe(df)

    session.markdown('### Stock Dataframe Statistics')
    session.dataframe(df.describe())

    session.markdown('### Plot By columns')

    first_column = session.text_input('Enter the Primary Column Name:')
    second_column = session.text_input('Enter the Secondary Column Name:')
    third_column_query = session.selectbox("Do you want to have a third column be plotted on your chart?", ("", "Yes", "No"))

    if first_column != '' and second_column != '':

        if third_column_query == '' or third_column_query == 'No':
            plot_figure = plot_multiple_columns(dataframe=df, primary_column=first_column,
                                                secondary_column=second_column)
            session.plotly_chart(plot_figure)

        else:

            third_column = session.text_input('Enter the ternary Column Name:')
            scale_query = session.selectbox('Please select the closest column in terms of scale to the third column.',
                                       ('', 'first column', 'second column'))

            if third_column != '' and scale_query != '':
                if scale_query == 'first column':
                    plot_figure = plot_multiple_columns(dataframe=df, primary_column=first_column,
                                                        secondary_column=second_column, ternary_column=third_column,
                                                        scale_similarity=1)
                    session.plotly_chart(plot_figure)

                elif scale_query == 'second column':
                    plot_figure = plot_multiple_columns(dataframe=df, primary_column=first_column,
                                                        secondary_column=second_column, ternary_column=third_column,
                                                        scale_similarity=2)
                    session.plotly_chart(plot_figure)

    else:
        session.markdown('### You Have Not Chosen Any Columns Yet!')