Skip to content

Commit

Permalink
Merge branch 'add-metrics'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuttlas90 committed Mar 3, 2024
2 parents f72a3d4 + eb05783 commit fb8c49c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
48 changes: 34 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,38 @@ def get_nonce_callback():
# 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()
name = st.sidebar.selectbox("لیست سهام", options = list_of_name)

query_string = f"""select
\"stockData\".id, \"estimatedEPS\", \"sectorPE\", pe, all_holder_percent, all_holder_share
from
\"stockData\"
INNER JOIN stocks ON \"stockData\".stock_id = stocks.id
where
stocks.name = '{name}'
order by
"stockData".id desc
"""

error, stock_data = vasahm_query(query_string)
if error:
st.error(stock_data, icon="🚨")
else:
col1, col2, col3, col4 = st.columns(4)
col1.metric("سود سهم", f"{stock_data[0]["estimatedEPS"]}")
col2.metric("نسبت سود به قیمت", f"{format(stock_data[0]["pe"], ".2f")}")
col3.metric("P/E صنعت", f"{format(float(stock_data[0]["sectorPE"]), ".2f")}")
col4.metric("درصد سهامداران عمده", f"{format(stock_data[0]["all_holder_percent"], ".2f")}")

tab1, tab2 = st.tabs(["بر اساس ریال", "بر اساس دلار"])

with tab1:
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()

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

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

queryString = queryString = f"""select
query_string = f"""select
\"rowTitle\",
sum(value) as value,
\"endToPeriod\"
Expand All @@ -124,7 +144,7 @@ def get_nonce_callback():
public.\"MonthlyData\".\"rowTitle\",
public.\"MonthlyData\".\"endToPeriod\"
"""
error, stock_data = vasahm_query(queryString)
error, stock_data = vasahm_query(query_string)
if error:
st.error(stock_data, icon="🚨")
else:
Expand All @@ -144,7 +164,7 @@ def get_nonce_callback():


st.header('گزارش تعداد تولید', divider='rainbow')
queryString = queryString = f"""select
query_string = f"""select
\"rowTitle\",
sum(value) as value,
\"endToPeriod\"
Expand All @@ -160,7 +180,7 @@ def get_nonce_callback():
\"MonthlyData\".\"rowTitle\",
\"MonthlyData\".\"endToPeriod\"
"""
error, stock_data = vasahm_query(queryString)
error, stock_data = vasahm_query(query_string)
if error:
st.error(stock_data, icon="🚨")
else:
Expand All @@ -179,7 +199,7 @@ def get_nonce_callback():
st.altair_chart(chart_product, use_container_width=True)

st.header('گزارش تعداد فروش', divider='rainbow')
queryString = f"""select
query_string = f"""select
\"rowTitle\",
sum(value) as value,
\"endToPeriod\"
Expand All @@ -195,7 +215,7 @@ def get_nonce_callback():
\"MonthlyData\".\"rowTitle\",
\"MonthlyData\".\"endToPeriod\"
"""
error, stock_data = vasahm_query(queryString)
error, stock_data = vasahm_query(query_string)
if error:
st.error(stock_data, icon="🚨")
else:
Expand All @@ -215,7 +235,7 @@ def get_nonce_callback():


st.header('درآمدهای عملیاتی و سود', divider='rainbow')
queryString = f"""select
query_string = f"""select
\"rowTitle\",
\"value\",
\"endToPeriod\"
Expand All @@ -230,7 +250,7 @@ def get_nonce_callback():
)
and stocks.name = '{name}'
"""
error, stock_data = vasahm_query(queryString)
error, stock_data = vasahm_query(query_string)
if error:
st.error(stock_data, icon="🚨")
else:
Expand All @@ -248,7 +268,7 @@ def get_nonce_callback():


st.header('حاشیه سود خالص', divider='rainbow')
queryString = f"""select
query_string = f"""select
\"rowTitle\",
\"value\",
\"endToPeriod\"
Expand All @@ -263,7 +283,7 @@ def get_nonce_callback():
)
and stocks.name = '{name}'
"""
error, stock_data = vasahm_query(queryString)
error, stock_data = vasahm_query(query_string)
if error:
st.error(stock_data, icon="🚨")
else:
Expand Down
11 changes: 8 additions & 3 deletions request.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ def is_authenticate(saved_token):
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site"
}
x = requests.get(url, headers=headers, timeout=60).json()
if x["hasError"]:
print(f"is_auth {saved_token}")
x = requests.get(url, headers=headers, timeout=60)
if x.status_code != 200:
return False
else:
return True
x=x.json()
if x["hasError"]:
return False
else:
return True

def index_price_history(ins_code, name):
"""Get history price of a tehran exchange Fund."""
Expand Down

0 comments on commit fb8c49c

Please sign in to comment.