Skip to content

Commit

Permalink
Merge pull request #2 from Cuttlas90/portfolio
Browse files Browse the repository at this point in the history
Portfolio
  • Loading branch information
Cuttlas90 authored Feb 4, 2024
2 parents e169bc0 + 76b7e4a commit d2dcd0e
Show file tree
Hide file tree
Showing 10 changed files with 377 additions and 213 deletions.
245 changes: 129 additions & 116 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Plot Some main monthly and quarterly charts"""


import streamlit as st
import pandas as pd
import plotly.express as px
import plost
from request import vasahm_query
from slider import create_slider
from request import get_nonce
from request import get_key
import altair as alt

st.session_state.ver = '0.1.3'
from request import vasahm_query, get_nonce, get_key


st.session_state.ver = '0.1.5'

st.set_page_config(layout='wide',
page_title="Vasahm Dashboard",
Expand All @@ -33,7 +33,7 @@
# </style>
# """, unsafe_allow_html=True
# )
with open( "style.css" ) as css:
with open( "style.css", encoding="utf-8") as css:
st.markdown( f'<style>{css.read()}</style>' , unsafe_allow_html= True)


Expand All @@ -42,17 +42,21 @@


def get_email_callback():
hasError, message = get_nonce(st.session_state.email)
if hasError:
"""Send nonce to entered email."""
has_error, message = get_nonce(st.session_state.email)
if has_error:
st.error(message, icon="🚨")
else:
submit_nonce = st.form("submit_nonce")
nonce = submit_nonce.text_input('کد تایید خود را وارد کنید', placeholder='XXXX', key="nonce")
submitted = submit_nonce.form_submit_button("ارسال", on_click = get_nonce_callback )
submit_nonce.text_input('کد تایید خود را وارد کنید',
placeholder='XXXX',
key="nonce")
submit_nonce.form_submit_button("ارسال", on_click = get_nonce_callback )

def get_nonce_callback():
hasError, message = get_key(st.session_state.email, st.session_state.nonce)
if hasError:
"""Confirm nonce for login."""
has_error, message = get_key(st.session_state.email, st.session_state.nonce)
if has_error:
st.error(message, icon="🚨")
del st.session_state["nonce"]
else:
Expand All @@ -61,18 +65,20 @@ def get_nonce_callback():

if "token" not in st .session_state:
get_email = st.form("get_email")
email = get_email.text_input('ایمیل خود را وارد کنید', placeholder='example@mail.com', key="email")
email = get_email.text_input('ایمیل خود را وارد کنید',
placeholder='example@mail.com',
key="email")
# Every form must have a submit button.
submitted = get_email.form_submit_button("دریافت کد", on_click = get_email_callback )
else:
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()

name = st.sidebar.selectbox("لیست سهام", options = list_of_name)
name = st.sidebar.selectbox("لیست سهام", options = list_of_name)

st.header('گزارش ماهانه فروش', divider='rainbow')
st.header('گزارش ماهانه فروش', divider='rainbow')

queryString = queryString = """select
queryString = queryString = f"""select
\"rowTitle\",
sum(value) as value,
\"endToPeriod\"
Expand All @@ -85,32 +91,32 @@ def get_nonce_callback():
or public.\"MonthlyData\".\"columnTitle\" = 'درآمد شناسایی شده'
or public.\"MonthlyData\".\"columnTitle\" = 'درآمد محقق شده طی دوره یک ماهه - لیزینگ'
)
and stocks.name = '{}'
and stocks.name = '{name}'
group by
public.\"MonthlyData\".\"rowTitle\",
public.\"MonthlyData\".\"endToPeriod\"
""".format(name)
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
# specify the type of selection, here single selection is used
selector = alt.selection_single(encodings=['x', 'color'])

chart = alt.Chart(stock_data_history).mark_bar().encode(
color='rowTitle:N',
y='sum(value):Q',
x='endToPeriod:N'
)
st.altair_chart(chart, use_container_width=True)
"""
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
# specify the type of selection, here single selection is used
selector = alt.selection_single(encodings=['x', 'color'])

chart = alt.Chart(stock_data_history).mark_bar().encode(
color='rowTitle:N',
y='sum(value):Q',
x='endToPeriod:N'
)
st.altair_chart(chart, use_container_width=True)

st.header('گزارش تعداد تولید', divider='rainbow')
queryString = queryString = """select

st.header('گزارش تعداد تولید', divider='rainbow')
queryString = queryString = f"""select
\"rowTitle\",
sum(value) as value,
\"endToPeriod\"
Expand All @@ -121,31 +127,31 @@ def get_nonce_callback():
(
\"MonthlyData\".\"columnTitle\" = 'تعداد تولید'
)
and stocks.name = '{}'
and stocks.name = '{name}'
group by
\"MonthlyData\".\"rowTitle\",
\"MonthlyData\".\"endToPeriod\"
""".format(name)
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
# specify the type of selection, here single selection is used
selector = alt.selection_single(encodings=['x', 'color'])

chart_product = alt.Chart(stock_data_history).mark_bar().encode(
color='rowTitle:N',
y='sum(value):Q',
x='endToPeriod:N'
)
st.altair_chart(chart_product, use_container_width=True)
"""
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
# specify the type of selection, here single selection is used
selector = alt.selection_single(encodings=['x', 'color'])

chart_product = alt.Chart(stock_data_history).mark_bar().encode(
color='rowTitle:N',
y='sum(value):Q',
x='endToPeriod:N'
)
st.altair_chart(chart_product, use_container_width=True)

st.header('گزارش تعداد فروش', divider='rainbow')
queryString = queryString = """select
st.header('گزارش تعداد فروش', divider='rainbow')
queryString = f"""select
\"rowTitle\",
sum(value) as value,
\"endToPeriod\"
Expand All @@ -156,32 +162,32 @@ def get_nonce_callback():
(
\"MonthlyData\".\"columnTitle\" = 'تعداد فروش'
)
and stocks.name = '{}'
and stocks.name = '{name}'
group by
\"MonthlyData\".\"rowTitle\",
\"MonthlyData\".\"endToPeriod\"
""".format(name)
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
# specify the type of selection, here single selection is used
selector = alt.selection_single(encodings=['x', 'color'])

chart_product = alt.Chart(stock_data_history).mark_bar().encode(
color='rowTitle:N',
y='sum(value):Q',
x='endToPeriod:N'
)
st.altair_chart(chart_product, use_container_width=True)
"""
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
# specify the type of selection, here single selection is used
selector = alt.selection_single(encodings=['x', 'color'])

chart_product = alt.Chart(stock_data_history).mark_bar().encode(
color='rowTitle:N',
y='sum(value):Q',
x='endToPeriod:N'
)
st.altair_chart(chart_product, use_container_width=True)

st.header('درآمدهای عملیاتی و سود', divider='rainbow')
queryString = """select

st.header('درآمدهای عملیاتی و سود', divider='rainbow')
queryString = f"""select
\"rowTitle\",
\"value\",
\"endToPeriod\"
Expand All @@ -194,28 +200,28 @@ def get_nonce_callback():
or \"QuarterlyData\".\"rowTitle\" = 'سود(زیان) ناخالص'
or \"QuarterlyData\".\"rowTitle\" = 'سود(زیان) خالص'
)
and stocks.name = '{}'
""".format(name)
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
# specify the type of selection, here single selection is used
chart2 = alt.Chart(stock_data_history).mark_area(opacity=0.3).encode(
color='rowTitle:N',
y=alt.Y('value:Q').stack(None),
x='endToPeriod:N'
)
and stocks.name = '{name}'
"""
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
# specify the type of selection, here single selection is used
chart2 = alt.Chart(stock_data_history).mark_area(opacity=0.3).encode(
color='rowTitle:N',
y=alt.Y('value:Q').stack(None),
x='endToPeriod:N'
)

st.altair_chart(chart2, use_container_width=True)
st.altair_chart(chart2, use_container_width=True)


st.header('حاشیه سود خالص', divider='rainbow')
queryString = """select
st.header('حاشیه سود خالص', divider='rainbow')
queryString = f"""select
\"rowTitle\",
\"value\",
\"endToPeriod\"
Expand All @@ -228,17 +234,24 @@ def get_nonce_callback():
or \"QuarterlyData\".\"rowTitle\" = 'سود(زیان) ناخالص'
or \"QuarterlyData\".\"rowTitle\" = 'سود(زیان) خالص'
)
and stocks.name = '{}'
""".format(name)
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
pivot_df = stock_data_history.pivot_table(index='endToPeriod', columns='rowTitle', values='value', aggfunc='sum').reset_index()
pivot_df["profit_ratio"] = pivot_df["سود(زیان) خالص"].astype(float)/pivot_df["درآمدهای عملیاتی"].astype(float)
pe_df=pivot_df[["profit_ratio", "endToPeriod"]]
st.line_chart(data=pe_df, x="endToPeriod", y="profit_ratio", color=None, use_container_width=True)
and stocks.name = '{name}'
"""
error, stock_data = vasahm_query(queryString)
if error:
st.error(stock_data, icon="🚨")
else:
stock_data_history = pd.DataFrame(stock_data, columns=["rowTitle",
"value",
"endToPeriod"])
stock_data_history["endToPeriod"] = stock_data_history["endToPeriod"].astype(str)
pivot_df = stock_data_history.pivot_table(index='endToPeriod',
columns='rowTitle',
values='value',
aggfunc='sum').reset_index()
pivot_df["profit_ratio"] = (pivot_df["سود(زیان) خالص"].astype(float)
/pivot_df["درآمدهای عملیاتی"].astype(float))
pe_df=pivot_df[["profit_ratio", "endToPeriod"]]
st.line_chart(data=pe_df, x="endToPeriod",
y="profit_ratio",
color=None,
use_container_width=True)
2 changes: 0 additions & 2 deletions pages/01 Dollar_Base.py → pages/01_Dollar_Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from request import get_key
import altair as alt

st.session_state.ver = '0.1.2'

st.set_page_config(layout='wide',
page_title="Vasahm Dashboard",
page_icon="./assets/favicon.ico",
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d2dcd0e

Please sign in to comment.