Nazhar commited on
Commit
46cfeb9
·
verified ·
1 Parent(s): c1bf422

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -70
app.py CHANGED
@@ -322,10 +322,10 @@ with news_analysis:
322
  figure = go.Figure(data=[line_stock], layout=layout)
323
  figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
324
  marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
325
- customdata=plot_sub_pos['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
326
  figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
327
  marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
328
- customdata=plot_sub_neg['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
329
  figure.update_layout(
330
  title={
331
  'text': title,
@@ -356,31 +356,37 @@ with news_analysis:
356
  figure.update_yaxes(fixedrange=False)
357
  st.plotly_chart(figure)
358
 
359
- # news = events[events['Date'].between(start_date, end_date, inclusive='both')]
 
360
 
361
- pos_news = plot_sub_pos[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
362
- neg_news = plot_sub_neg[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
363
 
364
  cols = ['Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']
365
  for col in cols:
366
- pos_news[col] = pos_news[col].apply(convert_str_to_list)
367
- neg_news[col] = neg_news[col].apply(convert_str_to_list)
 
368
  # Extract only the date part
369
- neg_news['Date'] = neg_news['Date'].dt.date
370
- pos_news['Date'] = pos_news['Date'].dt.date
 
371
  # Sort DataFrame based on the 'Date' column in descending order
372
- neg_news = neg_news.sort_values(by='Date', ascending=False)
373
- pos_news = pos_news.sort_values(by='Date', ascending=False)
 
374
 
375
  # Reset index to reflect the new order
376
- pos_news.reset_index(drop=True, inplace=True)
377
- neg_news.reset_index(drop=True, inplace=True)
 
378
  st.subheader("News Events")
379
  # st.dataframe(news, hide_index=True)
380
  # st.table(news)
381
- dates_neg = list(neg_news['Date'].unique())
382
- dates_pos = list(pos_news['Date'].unique())
383
- dates = dates_pos + dates_neg
 
384
  dates = np.sort(dates)
385
  # Reverse the array to have the latest date at index 0
386
  dates = dates[::-1]
@@ -389,62 +395,87 @@ with news_analysis:
389
  items_per_page = min(num_dates, 5)
390
  for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False, ukey='news_pages'):
391
  st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
392
 
393
- if date in dates_pos:
394
- filtered_news = pos_news[pos_news['Date'] == date]
395
- print(filtered_news.shape)
396
- features = filtered_news['Feature'].sum()
397
- headlines = filtered_news['Raw_Headline'].sum()
398
- news_list = filtered_news['Raw_News'].sum()
399
- sources = filtered_news['Sources'].sum()
400
- urls = filtered_news['Urls'].sum()
401
-
402
- main_container = st.container(height = 250, border=True)
403
- # main_container.write(f"Date: {date}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
 
405
- col1, col2 = main_container.columns([0.7, 0.3], gap='medium')
406
-
407
- # Merge lists of headlines into a single list
408
- for index, headline in enumerate(headlines):
409
- col1.page_link(urls[index], label=f"**:blue[{headline}]**")
410
- # col1.write(f"<span style='font-size: large;'><b><u>{headline}</u></b></span>", unsafe_allow_html=True)
411
- col1.write(f"<span style='font-size: small;'>By {sources[index]}</span><br>", unsafe_allow_html=True)
412
- with col1:
413
- with st.expander("Show Full Article"):
414
- st.write(news_list[index])
415
-
416
- with col2:
417
- # st.divider()
418
- with st.expander("Oil Sector Features"):
419
- st.write(set(features))
420
 
421
- if date in dates_neg:
422
- filtered_news = neg_news[neg_news['Date'] == date]
423
- print(filtered_news.shape)
424
- features = filtered_news['Feature'].sum()
425
- headlines = filtered_news['Raw_Headline'].sum()
426
- news_list = filtered_news['Raw_News'].sum()
427
- sources = filtered_news['Sources'].sum()
428
- urls = filtered_news['Urls'].sum()
429
-
430
- main_container = st.container(height = 250, border=True)
431
- # main_container.write(f"Date: {date}")
432
 
433
- col1, col2 = main_container.columns([0.7, 0.3], gap='medium')
434
-
435
- # Merge lists of headlines into a single list
436
- for index, headline in enumerate(headlines):
437
- col1.page_link(urls[index], label=f"**:blue[{headline}]**")
438
- # col1.write(f"<span style='font-size: large;'><b><u>{headline}</u></b></span>", unsafe_allow_html=True)
439
- col1.write(f"<span style='font-size: small;'>By {sources[index]}</span><br>", unsafe_allow_html=True)
440
- with col1:
441
- with st.expander("Show Full Article"):
442
- st.write(news_list[index])
443
-
444
- with col2:
445
- # st.divider()
446
- with st.expander("Oil Sector Features"):
447
- st.write(set(features))
448
 
449
  st.markdown("""
450
  <div style='background-color:#b43c42; color:#ffffff; padding:8px; border-radius:3px; font-size:12px''>
@@ -687,10 +718,10 @@ with final_recs:
687
  figure = go.Figure(data=[line_stock], layout=layout)
688
  figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
689
  marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
690
- customdata=plot_sub_pos['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
691
  figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
692
  marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
693
- customdata=plot_sub_neg['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
694
  figure.update_layout(
695
  title={
696
  'text': title,
 
322
  figure = go.Figure(data=[line_stock], layout=layout)
323
  figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
324
  marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
325
+ customdata=set(plot_sub_pos['Feature']), hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
326
  figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
327
  marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
328
+ customdata=set(plot_sub_neg['Feature']), hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
329
  figure.update_layout(
330
  title={
331
  'text': title,
 
356
  figure.update_yaxes(fixedrange=False)
357
  st.plotly_chart(figure)
358
 
359
+ news = events[events['Date'].between(start_date, end_date, inclusive='both')]
360
+ news = news[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
361
 
362
+ # pos_news = plot_sub_pos[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
363
+ # neg_news = plot_sub_neg[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
364
 
365
  cols = ['Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']
366
  for col in cols:
367
+ news[col] = news[col].apply(convert_str_to_list)
368
+ # pos_news[col] = pos_news[col].apply(convert_str_to_list)
369
+ # neg_news[col] = neg_news[col].apply(convert_str_to_list)
370
  # Extract only the date part
371
+ news['Date'] = news['Date'].dt.date
372
+ # neg_news['Date'] = neg_news['Date'].dt.date
373
+ # pos_news['Date'] = pos_news['Date'].dt.date
374
  # Sort DataFrame based on the 'Date' column in descending order
375
+ news = news.sort_values(by='Date', ascending=False)
376
+ # neg_news = neg_news.sort_values(by='Date', ascending=False)
377
+ # pos_news = pos_news.sort_values(by='Date', ascending=False)
378
 
379
  # Reset index to reflect the new order
380
+ news.reset_index(drop=True, inplace=True)
381
+ # pos_news.reset_index(drop=True, inplace=True)
382
+ # neg_news.reset_index(drop=True, inplace=True)
383
  st.subheader("News Events")
384
  # st.dataframe(news, hide_index=True)
385
  # st.table(news)
386
+ dates = list(news['Date'].unique())
387
+ # dates_neg = list(neg_news['Date'].unique())
388
+ # dates_pos = list(pos_news['Date'].unique())
389
+ # dates = dates_pos + dates_neg
390
  dates = np.sort(dates)
391
  # Reverse the array to have the latest date at index 0
392
  dates = dates[::-1]
 
395
  items_per_page = min(num_dates, 5)
396
  for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False, ukey='news_pages'):
397
  st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
398
+ filtered_news = news[news['Date'] == date]
399
+ print(filtered_news.shape)
400
+ features = filtered_news['Feature'].sum()
401
+ headlines = filtered_news['Raw_Headline'].sum()
402
+ news_list = filtered_news['Raw_News'].sum()
403
+ sources = filtered_news['Sources'].sum()
404
+ urls = filtered_news['Urls'].sum()
405
+
406
+ main_container = st.container(height = 250, border=True)
407
+ # main_container.write(f"Date: {date}")
408
 
409
+ col1, col2 = main_container.columns([0.7, 0.3], gap='medium')
410
+
411
+ # Merge lists of headlines into a single list
412
+ for index, headline in enumerate(headlines):
413
+ col1.page_link(urls[index], label=f"**:blue[{headline}]**")
414
+ # col1.write(f"<span style='font-size: large;'><b><u>{headline}</u></b></span>", unsafe_allow_html=True)
415
+ col1.write(f"<span style='font-size: small;'>By {sources[index]}</span><br>", unsafe_allow_html=True)
416
+ with col1:
417
+ with st.expander("Show Full Article"):
418
+ st.write(news_list[index])
419
+
420
+ with col2:
421
+ # st.divider()
422
+ with st.expander("Oil Sector Features"):
423
+ st.write(set(features))
424
+ # if date in dates_pos:
425
+ # filtered_news = pos_news[pos_news['Date'] == date]
426
+ # print(filtered_news.shape)
427
+ # features = filtered_news['Feature'].sum()
428
+ # headlines = filtered_news['Raw_Headline'].sum()
429
+ # news_list = filtered_news['Raw_News'].sum()
430
+ # sources = filtered_news['Sources'].sum()
431
+ # urls = filtered_news['Urls'].sum()
432
+
433
+ # main_container = st.container(height = 250, border=True)
434
+ # # main_container.write(f"Date: {date}")
435
 
436
+ # col1, col2 = main_container.columns([0.7, 0.3], gap='medium')
437
+
438
+ # # Merge lists of headlines into a single list
439
+ # for index, headline in enumerate(headlines):
440
+ # col1.page_link(urls[index], label=f"**:blue[{headline}]**")
441
+ # # col1.write(f"<span style='font-size: large;'><b><u>{headline}</u></b></span>", unsafe_allow_html=True)
442
+ # col1.write(f"<span style='font-size: small;'>By {sources[index]}</span><br>", unsafe_allow_html=True)
443
+ # with col1:
444
+ # with st.expander("Show Full Article"):
445
+ # st.write(news_list[index])
446
+
447
+ # with col2:
448
+ # # st.divider()
449
+ # with st.expander("Oil Sector Features"):
450
+ # st.write(set(features))
451
 
452
+ # if date in dates_neg:
453
+ # filtered_news = neg_news[neg_news['Date'] == date]
454
+ # print(filtered_news.shape)
455
+ # features = filtered_news['Feature'].sum()
456
+ # headlines = filtered_news['Raw_Headline'].sum()
457
+ # news_list = filtered_news['Raw_News'].sum()
458
+ # sources = filtered_news['Sources'].sum()
459
+ # urls = filtered_news['Urls'].sum()
460
+
461
+ # main_container = st.container(height = 250, border=True)
462
+ # # main_container.write(f"Date: {date}")
463
 
464
+ # col1, col2 = main_container.columns([0.7, 0.3], gap='medium')
465
+
466
+ # # Merge lists of headlines into a single list
467
+ # for index, headline in enumerate(headlines):
468
+ # col1.page_link(urls[index], label=f"**:blue[{headline}]**")
469
+ # # col1.write(f"<span style='font-size: large;'><b><u>{headline}</u></b></span>", unsafe_allow_html=True)
470
+ # col1.write(f"<span style='font-size: small;'>By {sources[index]}</span><br>", unsafe_allow_html=True)
471
+ # with col1:
472
+ # with st.expander("Show Full Article"):
473
+ # st.write(news_list[index])
474
+
475
+ # with col2:
476
+ # # st.divider()
477
+ # with st.expander("Oil Sector Features"):
478
+ # st.write(set(features))
479
 
480
  st.markdown("""
481
  <div style='background-color:#b43c42; color:#ffffff; padding:8px; border-radius:3px; font-size:12px''>
 
718
  figure = go.Figure(data=[line_stock], layout=layout)
719
  figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
720
  marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
721
+ customdata=set(plot_sub_pos['Feature']), hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
722
  figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
723
  marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
724
+ customdata=set(plot_sub_neg['Feature']), hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
725
  figure.update_layout(
726
  title={
727
  'text': title,