From 3872718e364d201bd169280e228ec920db30757f Mon Sep 17 00:00:00 2001 From: cuttlas90 Date: Mon, 12 Feb 2024 12:26:13 +0330 Subject: [PATCH] add simple chart page --- menu.py | 1 + pages/simple_chart.py | 46 +++++++++++++++++++++++++++++++++++++++++++ request.py | 7 +++++++ 3 files changed, 54 insertions(+) create mode 100644 pages/simple_chart.py diff --git a/menu.py b/menu.py index 9905d8b..180a7c6 100644 --- a/menu.py +++ b/menu.py @@ -7,4 +7,5 @@ def add_menu(): st.sidebar.page_link("pages/monthly_compare.py", label="دیده بان ماهانه", icon="📋") st.sidebar.page_link("pages/workbench.py", label="میزکار", icon="🗃️") st.sidebar.page_link("pages/portfolio.py", label="تحلیل پورتفو", icon="📊") + # st.sidebar.page_link("pages/simple_chart.py", label="نمودار ساده ماهانه", icon="📋") st.sidebar.page_link("pages/changelog.py", label="تازه ها", icon="💬") diff --git a/pages/simple_chart.py b/pages/simple_chart.py new file mode 100644 index 0000000..4d7ef51 --- /dev/null +++ b/pages/simple_chart.py @@ -0,0 +1,46 @@ +"""Comapre monthly data in a customized way""" + +import streamlit as st +import pandas as pd +import altair as alt + + +from request import get_stock_monthly +from slider import create_range_slider +from menu import add_menu + + + +st.set_page_config(layout='wide', + page_title="Vasahm Dashboard", + page_icon="./assets/favicon.ico", + initial_sidebar_state='expanded') + +with open( "style.css", encoding='UTF-8') as css: + st.markdown( f'' , unsafe_allow_html= True) +add_menu() + + +# st.sidebar.image(image="./assets/logo.png") +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) + +dfg = get_stock_monthly(name) + +stock_data_history = pd.DataFrame(dfg[name], columns=["period", + "value"]) + +chart = alt.Chart(stock_data_history).mark_bar().encode( + alt.Y('value:Q', title="مبلغ (میلیون ریال)"), + alt.X('period:N',title="تاریخ") + ) +st.altair_chart(chart, use_container_width=True) diff --git a/request.py b/request.py index 2cce705..8e4c607 100644 --- a/request.py +++ b/request.py @@ -74,3 +74,10 @@ def index_price_history2(ins_code, name): columns={'dEven': 'datetime', 'xNivInuClMresIbs': name}) shiraz['datetime'] = shiraz['datetime'].astype(str) return shiraz[["datetime", name]] + + +def get_stock_monthly(stock_name): + """Get history monthly data for free users.""" + url = f"https://api.vasahm.ir/api/monthlyChart/{stock_name}" + response = requests.get(url, timeout=60).json() + return response