Skip to content

Commit

Permalink
enhancements, development in stock_info
Browse files Browse the repository at this point in the history
  • Loading branch information
pratham-darooka committed Jun 19, 2024
1 parent 0df884a commit 9403c33
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 18 deletions.
3 changes: 3 additions & 0 deletions app/db/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class Stocks:
def get_stock_symbol_from_name(self, name):
return self.supabase.fetch_records('stocks', ('company_name', 'ilike', f'*{name}*'))[0]['stock_symbol']

def get_exact_name_from_stock_symbol(self, symbol):
return self.supabase.fetch_records('stocks', ('stock_symbol', 'eq', f'{symbol}'))[0]['company_name']

def get_name_from_stock_symbol(self, symbol):
return self.supabase.fetch_records('stocks', ('stock_symbol', 'ilike', f'*{symbol}*'))[0]['company_name']

Expand Down
2 changes: 1 addition & 1 deletion app/pages/equity.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
selection = write_aggrid_df('stock_prices_equity_cash_view', 'equity')

if selection is not None:
st.session_state.stock_info_co_name = stock.get_name_from_stock_symbol(list(selection['Stock'])[0])
st.session_state.stock_info_co_name = stock.get_exact_name_from_stock_symbol(list(selection['Stock'])[0])
st.switch_page('pages/stock_info.py')

# cash_df = pd.DataFrame(supabase.fetch_records("stock_prices_equity_cash_view"))
Expand Down
3 changes: 2 additions & 1 deletion app/pages/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@
selection = write_aggrid_df(df_names_for_dates[expiry], 'futures')

if selection is not None:
st.session_state.stock_info_co_name = stock.get_name_from_stock_symbol(list(selection['Stock'])[0])
st.session_state.stock_info_co_name = stock.get_exact_name_from_stock_symbol(list(selection['Stock'])[0])
st.switch_page('pages/stock_info.py')

# futures_df = pd.DataFrame(supabase.fetch_records(df_names_for_dates[expiry]))

# futures_df = futures_df.sort_values(by="Day Change (%)", ascending=False)
Expand Down
29 changes: 17 additions & 12 deletions app/pages/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
with dropdown:
indices_df = pd.DataFrame(supabase.fetch_records('index_price_view'))
indices_df.set_index('Index', inplace=True)
index = st.selectbox("Select index to see constituents:", ['All'] + indices_df.index.tolist(),
st.session_state.index_selected = st.selectbox("Select index to see constituents:", ['All'] + indices_df.index.tolist(),
index=0,
label_visibility="collapsed")

Expand All @@ -64,11 +64,7 @@
with constituents:
with st.container(border=True, height=600):
name, search_bar = st.columns(2)
with name:
if index != "All":
st.header(f"{index} Contributors")
else:
st.header(f"All Stocks")

with search_bar:
stock_query = st.text_input("Find out what's happening...",
placeholder="Enter stock name...",
Expand All @@ -88,18 +84,27 @@

while True:
with indices_container_placeholder.container():
write_aggrid_df('index_price_view', 'indices', selection=False)
selection = write_aggrid_df('index_price_view', 'indices')

if selection is not None:
st.session_state.index_selected = list(selection['Index'])[0]

# indices_df = pd.DataFrame(supabase.fetch_records('index_price_view'))
# indices_df.set_index('Index', inplace=True)

# st.dataframe(indices_df, use_container_width=True, height=525)
with name:
if st.session_state.index_selected != "All":
st.header(f"{st.session_state.index_selected} Contributors")
else:
st.header(f"All Stocks")

with stocks_container_placeholder.container():
if index == "All":
selection = write_aggrid_df('stock_prices_equity_indices_view', 'contributors')
if st.session_state.index_selected == "All":
selection = write_aggrid_df('stock_prices_equity_indices_view', 'contributors_all')

if selection is not None:
st.session_state.stock_info_co_name = stock.get_name_from_stock_symbol(list(selection['Stock'])[0])
st.session_state.stock_info_co_name = stock.get_exact_name_from_stock_symbol(list(selection['Stock'])[0])
st.switch_page('pages/stock_info.py')

# # Initialize an empty DataFrame
Expand All @@ -108,10 +113,10 @@
# latest_cash_df = latest_cash_df.sort_values(by="Day Change (%)", ascending=False)
# st.dataframe(latest_cash_df, use_container_width=True, height=450)
else:
selection = write_aggrid_df('index_constituents_equity_indices_view', 'contributors', condition=('Index', 'ilike', f"*{index}*"))
selection = write_aggrid_df('index_constituents_equity_indices_view', 'contributors', condition=('Index', 'ilike', f"*{st.session_state.index_selected}*"))

if selection is not None:
st.session_state.stock_info_co_name = stock.get_name_from_stock_symbol(list(selection['Stock'])[0])
st.session_state.stock_info_co_name = stock.get_exact_name_from_stock_symbol(list(selection['Stock'])[0])
st.switch_page('pages/stock_info.py')
# latest_cash_df = pd.DataFrame(
# supabase.fetch_records('index_constituents_equity_indices_view', ('Index', 'ilike', f"*{index}*")))
Expand Down
24 changes: 21 additions & 3 deletions app/pages/stock_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
stock_info = st.empty()

with stock_info.container():
symbol = stock.get_stock_symbol_from_name(st.session_state.stock_info_co_name)
name = st.session_state.stock_info_co_name
stock_selected = supabase.fetch_records('stocks', ('company_name', 'eq', st.session_state.stock_info_co_name))[0]
symbol = stock_selected['stock_symbol']
name = stock_selected['company_name']

st.title(f"{name} ({symbol})")

stock_metrics = st.empty()
Expand All @@ -56,7 +58,23 @@
with stock_metrics:
with st.container(border=True):
st.write("#### Stock Metrics")
st.write("DEVELOPMENT IN PROGRESS")
metric_col1, metric_col2, metric_col3, metric_col4, metric_col5 = st.columns(5)

with metric_col1:
st.metric(label="Temperature", value="70 °F", delta="1.2 °F")

with metric_col2:
st.metric(label="Temperature", value="70 °F", delta="1.2 °F")

with metric_col3:
st.metric(label="Temperature", value="70 °F", delta="1.2 °F")

with metric_col4:
st.metric(label="Temperature", value="70 °F", delta="1.2 °F")

with metric_col5:
st.metric(label="Temperature", value="70 °F", delta="1.2 °F")


with stock_analysis:
with st.container(border=True):
Expand Down
14 changes: 13 additions & 1 deletion app/utils/whats_happening.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@
from markdownify import markdownify as md
from icecream import ic
import urllib.parse
from datetime import datetime

def check_whats_happening(stock):
print("triggered ai!")


def fetch_and_parse_perplexity_output(query):
url = f'https://unfortunate-sally-maharat-8663b4b4.koyeb.app/search_normal?query={urllib.parse.quote(query)}&pro_mode=true&date_context=Today%20is%20Monday,%2017/06/2024%20and%20the%20time%20is%2001:45%20PM'
# Get the current date and time
now = datetime.now()

# Format the date and time
formatted_date = now.strftime("%A, %d/%m/%Y")
formatted_time = now.strftime("%I:%M %p")

# Construct the date_context parameter
date_context = f"Today is {formatted_date} and the time is {formatted_time}. Only look for Indian stocks. Else, reply 'I don't Know'. Respond with only recent results (maximum 5 days old)."


url = f'https://unfortunate-sally-maharat-8663b4b4.koyeb.app/search_normal?query={urllib.parse.quote(query)}&pro_mode=true&date_context={urllib.parse.quote(date_context)}'
response = requests.get(url, stream=True)

response_content = response.content.decode('utf-8')
Expand Down

0 comments on commit 9403c33

Please sign in to comment.