Skip to content

Commit

Permalink
add simple chart page
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuttlas90 committed Feb 12, 2024
1 parent 7767f5d commit 3872718
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="💬")
46 changes: 46 additions & 0 deletions pages/simple_chart.py
Original file line number Diff line number Diff line change
@@ -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'<style>{css.read()}</style>' , 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)
7 changes: 7 additions & 0 deletions request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3872718

Please sign in to comment.