Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix selector #15

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import shutil

import streamlit as st
import pandas as pd
import altair as alt

from login import check_local_token
from pages.helper.monthly_chart import add_monthly_charts
from pages.helper.quarterly_chart import add_quartely_charts
from pages.helper.query import Queries
from request import vasahm_query
from menu import add_menu
from menu import add_list_selector, add_menu
from text_constant import MAIN_PAGE


Expand Down Expand Up @@ -47,14 +46,8 @@ def sfmono():

add_menu()
st.components.v1.html(MAIN_PAGE, height=60, scrolling=False)
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
STOCK_INDEX = list_of_name.index(st.query_params.stock)
else:
STOCK_INDEX = 0
name = st.sidebar.selectbox("لیست سهام", options = list_of_name, index=STOCK_INDEX)
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]]

name, selected_stock = add_list_selector()
dollar_toggle = st.sidebar.toggle(
"نمایش به دلار",
help="با فعال کردن این گزینه تمامی مبالغ بر اساس دلار بازمحاسبه می گردد."
Expand Down
18 changes: 18 additions & 0 deletions menu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Creating a custom menu for application"""
import streamlit as st
import pandas as pd

def add_menu():
"""adding a custom menu to app"""
Expand All @@ -13,3 +14,20 @@ def add_menu():
st.sidebar.page_link("pages/social_page.py", label="اطلاعات رفتاری", icon="🌐")
# st.sidebar.page_link("pages/simple_chart.py", label="نمودار ساده ماهانه", icon="📋")
st.sidebar.page_link("pages/changelog.py", label="تازه ها", icon="💬")


def add_list_selector():
"""create and init list selector"""
if "stock_index" not in st.session_state:
st.session_state.stock_index = 0
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
st.session_state.stock_index = list_of_name.index(st.query_params.stock)
name = st.sidebar.selectbox(
"لیست سهام",
options = list_of_name,
index=st.session_state.stock_index)
st.session_state.stock_index = int((df.loc[df['name'] == name].index[0]).astype(str))
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]]
return name, selected_stock
11 changes: 2 additions & 9 deletions pages/simple_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from request import get_stock_monthly
# from slider import create_range_slider
from menu import add_menu
from menu import add_list_selector, add_menu



Expand All @@ -23,14 +23,7 @@
if "ver" in st.session_state:
st.sidebar.header(f'Vasahm DashBoard `{st.session_state.ver}`')

df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
STOCK_INDEX = list_of_name.index(st.query_params.stock)
else:
STOCK_INDEX = 0

name = st.selectbox("لیست سهام", options = list_of_name, index=STOCK_INDEX)
name, _ = add_list_selector()

dfg = get_stock_monthly(name)

Expand Down
11 changes: 2 additions & 9 deletions pages/social_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from login import check_local_token
from pages.helper.query import Queries
from request import vasahm_query
from menu import add_menu
from menu import add_list_selector, add_menu



Expand All @@ -22,14 +22,7 @@

add_menu()

df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
STOCK_INDEX = list_of_name.index(st.query_params.stock)
else:
STOCK_INDEX = 0
name = st.sidebar.selectbox("لیست سهام", options = list_of_name, index=STOCK_INDEX)
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]]
name, _ = add_list_selector()

if "ver" in st.session_state:
st.sidebar.header(f'Vasahm DashBoard `{st.session_state.ver}`')
Expand Down
125 changes: 72 additions & 53 deletions pages/technical.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
"""Comapre monthly data in a customized way"""

import streamlit as st
import streamlit.components.v1 as components
import pandas as pd
import altair as alt
from login import check_local_token
import numpy as np

from pages.helper.gauge_chart import plot_gauge
from pages.helper.query import Queries
from pages.helper.ta_metrics import add_ta_metrics
from request import get_stock_monthly
# from slider import create_range_slider
from menu import add_menu
from finta import TA
from menu import add_list_selector, add_menu
from request import vasahm_query
import plotly.graph_objs as go
import streamlit.components.v1 as components



Expand All @@ -31,14 +25,7 @@
if "ver" in st.session_state:
st.sidebar.header(f'Vasahm DashBoard `{st.session_state.ver}`')

df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
STOCK_INDEX = list_of_name.index(st.query_params.stock)
else:
STOCK_INDEX = 0

name = st.sidebar.selectbox("لیست سهام", options = list_of_name, index=STOCK_INDEX)
name, _ = add_list_selector()
dollar_toggle = st.sidebar.toggle(
"نمایش به دلار",
help="با فعال کردن این گزینه تمامی مبالغ بر اساس دلار بازمحاسبه می گردد."
Expand All @@ -55,7 +42,8 @@
st.error(stock_data, icon="🚨")
else:
components.iframe(f"https://chart.vasahm.com/?name={name}", height=500)
stock_data_history = pd.DataFrame(stock_data, columns=["date","open","high","low","close", "volume"])
stock_data_history = pd.DataFrame(
stock_data, columns=["date","open","high","low","close", "volume"])
stock_data_history['date'] = pd.to_datetime(stock_data_history['date'])
stock_data_history['open'] = stock_data_history['open'].astype(int)
stock_data_history['high'] = stock_data_history['high'].astype(int)
Expand All @@ -68,50 +56,81 @@
stock_data_history.set_index("date", inplace=True)

col1, col2 = st.columns(2)

move_gauge = col1.empty()
osi_gauge = col2.empty()

current_value_moving = 0
current_value_indicator = 0
# Pylint: diable=invalid-name
cvm = 0
# Pylint: diable=invalid-name
cvi = 0


col1, col2 = st.columns(2)

col11, col12, col13 = col1.columns(3)

current_value_moving = add_ta_metrics(stock_data_history, [10],"EMA (10)", "10 period EMA", col11, current_value_moving, "EMA")
current_value_moving = add_ta_metrics(stock_data_history, [20], "EMA (20)", "20 period EMA", col12, current_value_moving, "EMA")
current_value_moving = add_ta_metrics(stock_data_history, [30], "EMA (30)", "30 period EMA", col13, current_value_moving, "EMA")
current_value_moving = add_ta_metrics(stock_data_history, [50], "EMA (50)", "50 period EMA", col11, current_value_moving, "EMA")
current_value_moving = add_ta_metrics(stock_data_history, [100], "EMA (100)", "100 period EMA", col12, current_value_moving, "EMA")
current_value_moving = add_ta_metrics(stock_data_history, [200], "EMA (200)", "200 period EMA", col13, current_value_moving, "EMA")

current_value_moving = add_ta_metrics(stock_data_history, [10],"SMA (10)", "10 period SMA", col11, current_value_moving, "SMA")
current_value_moving = add_ta_metrics(stock_data_history, [20], "SMA (20)", "20 period SMA", col12, current_value_moving, "SMA")
current_value_moving = add_ta_metrics(stock_data_history, [30], "SMA (30)", "30 period SMA", col13, current_value_moving, "SMA")
current_value_moving = add_ta_metrics(stock_data_history, [50], "SMA (50)", "50 period SMA", col11, current_value_moving, "SMA")
current_value_moving = add_ta_metrics(stock_data_history, [100], "SMA (100)", "100 period SMA", col12, current_value_moving, "SMA")
current_value_moving = add_ta_metrics(stock_data_history, [200], "SMA (200)", "200 period SMA", col13, current_value_moving, "SMA")

current_value_moving = add_ta_metrics(stock_data_history, [20], "VAMA (20)", "20 period VAMA", col11, current_value_moving, "VAMA")
current_value_moving = add_ta_metrics(stock_data_history, [9], "HMA (9)", "9 period HMA.", col12, current_value_moving, "HMA")
cvm = add_ta_metrics(
stock_data_history, [10],"EMA (10)", "10 period EMA", col11, cvm, "EMA")
cvm = add_ta_metrics(
stock_data_history, [20], "EMA (20)", "20 period EMA", col12, cvm, "EMA")
cvm = add_ta_metrics(
stock_data_history, [30], "EMA (30)", "30 period EMA", col13, cvm, "EMA")
cvm = add_ta_metrics(
stock_data_history, [50], "EMA (50)", "50 period EMA", col11, cvm, "EMA")
cvm = add_ta_metrics(
stock_data_history, [100], "EMA (100)", "100 period EMA", col12, cvm, "EMA")
cvm = add_ta_metrics(
stock_data_history, [200], "EMA (200)", "200 period EMA", col13, cvm, "EMA")

cvm = add_ta_metrics(
stock_data_history, [10],"SMA (10)", "10 period SMA", col11, cvm, "SMA")
cvm = add_ta_metrics(
stock_data_history, [20], "SMA (20)", "20 period SMA", col12, cvm, "SMA")
cvm = add_ta_metrics(
stock_data_history, [30], "SMA (30)", "30 period SMA", col13, cvm, "SMA")
cvm = add_ta_metrics(
stock_data_history, [50], "SMA (50)", "50 period SMA", col11, cvm, "SMA")
cvm = add_ta_metrics(
stock_data_history, [100], "SMA (100)", "100 period SMA", col12, cvm, "SMA")
cvm = add_ta_metrics(
stock_data_history, [200], "SMA (200)", "200 period SMA", col13, cvm, "SMA")
cvm = add_ta_metrics(
stock_data_history, [20], "VAMA (20)", "20 period VAMA", col11, cvm, "VAMA")
cvm = add_ta_metrics(
stock_data_history, [9], "HMA (9)", "9 period HMA.", col12, cvm, "HMA")

col21, col22, col23 = col2.columns(3)

current_value_indicator = add_ta_metrics(stock_data_history, [14], "RSI (14)", "14 period RSI", col21, current_value_indicator, "RSI")
current_value_indicator = add_ta_metrics(stock_data_history, [14], "STOCH (14)", "14 period STOCH %K", col22, current_value_indicator, "STOCH")
current_value_indicator = add_ta_metrics(stock_data_history, [14], "CCI (14)", "14 period CCI", col23, current_value_indicator, "CCI")
current_value_indicator = add_ta_metrics(stock_data_history, [14], "ADX (14)", "14 period ADX.", col21, current_value_indicator, "ADX")
current_value_indicator = add_ta_metrics(stock_data_history, [14], "AO (14)", "AO", col22, current_value_indicator, "AO")
current_value_indicator = add_ta_metrics(stock_data_history, [10], "MOM", "MOM", col23, current_value_indicator, "MOM")
current_value_indicator = add_ta_metrics(stock_data_history, [10,26], "MACD", "SIGNAL", col21, current_value_indicator, "MACD")
current_value_indicator = add_ta_metrics(stock_data_history, [14,14], "STOCHRSI", "14 period stochastic RSI.", col22, current_value_indicator, "STOCHRSI")
current_value_indicator = add_ta_metrics(stock_data_history, [14], "WILLIAMS", "14 Williams %R", col23, current_value_indicator, "WILLIAMS")
current_value_indicator = add_ta_metrics(stock_data_history, [], "EBBP BULL", "Bull.", col21, current_value_indicator, "EBBP")
current_value_indicator = add_ta_metrics(stock_data_history, [], "EBBP BEAR", "Bear.", col22, current_value_indicator, "EBBP")
current_value_indicator = add_ta_metrics(stock_data_history, [], "UO", 0, col23, current_value_indicator, "UO")


plot_gauge(current_value_moving, -15, 15, "Moving Averages Gauge", move_gauge)
plot_gauge(current_value_indicator, -9, 9, "Oscillators Gauge", osi_gauge)
cvi = add_ta_metrics(
stock_data_history, [14], "RSI (14)", "14 period RSI", col21, cvi, "RSI")
cvi = add_ta_metrics(
stock_data_history, [14], "STOCH (14)", "14 period STOCH %K", col22, cvi, "STOCH")
cvi = add_ta_metrics(
stock_data_history, [14], "CCI (14)", "14 period CCI", col23, cvi, "CCI")
cvi = add_ta_metrics(
stock_data_history, [14], "ADX (14)", "14 period ADX.", col21, cvi, "ADX")
cvi = add_ta_metrics(
stock_data_history, [14], "AO (14)", "AO", col22, cvi, "AO")
cvi = add_ta_metrics(
stock_data_history, [10], "MOM", "MOM", col23, cvi, "MOM")
cvi = add_ta_metrics(
stock_data_history, [10,26], "MACD", "SIGNAL", col21, cvi, "MACD")
cvi = add_ta_metrics(
stock_data_history,
[14,14],
"STOCHRSI",
"14 period stochastic RSI.",
col22,
cvi,
"STOCHRSI")
cvi = add_ta_metrics(
stock_data_history, [14], "WILLIAMS", "14 Williams %R", col23, cvi, "WILLIAMS")
cvi = add_ta_metrics(
stock_data_history, [], "EBBP BULL", "Bull.", col21, cvi, "EBBP")
cvi = add_ta_metrics(
stock_data_history, [], "EBBP BEAR", "Bear.", col22, cvi, "EBBP")
cvi = add_ta_metrics(
stock_data_history, [], "UO", 0, col23, cvi, "UO")

plot_gauge(cvm, -15, 15, "Moving Averages Gauge", move_gauge)
plot_gauge(cvi, -9, 9, "Oscillators Gauge", osi_gauge)
Loading