-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayouts.py
103 lines (94 loc) · 4.21 KB
/
layouts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from dash import html, dcc
import datetime
def create_app_layout():
current_year = datetime.datetime.now().year
current_month = datetime.datetime.now().month
year_options = [{"label": str(year), "value": year} for year in range(current_year-5, current_year+1)]
month_options = [{"label": datetime.datetime(current_year, month, 1).strftime("%B"), "value": month} for month in range(1, current_month+1)]
tickers = ["AAPL", "GOOGL", "MSFT", "AMZN", "TSLA", "NFLX", "NVDA"]
default_tickers = ["AAPL", "AMZN", "GOOGL"]
return html.Div(className="container py-4", children=[
html.H1("StockSense AI", className="mb-4"),
html.Div(className="row mb-4", children=[
html.Div(className="col-md-4", children=[
html.Label("Select Assets", className="form-label"),
dcc.Dropdown(
id="asset-dropdown",
options=[{"label": ticker, "value": ticker} for ticker in tickers],
value=default_tickers,
multi=True,
className="mb-3"
)
]),
html.Div(className="col-md-4", children=[
html.Label("Select Year", className="form-label"),
dcc.Dropdown(
id="year-dropdown",
options=year_options,
value=current_year,
className="mb-3",
clearable=False
)
]),
html.Div(className="col-md-4", children=[
html.Label("Select Month", className="form-label"),
dcc.Dropdown(
id="month-dropdown",
options=month_options,
value=current_month,
className="mb-3"
)
])
]),
html.Div(className="row mb-4", children=[
html.Div(className="col-md-6", children=[
html.Button(
"Analyze Sentiment",
id="sentiment-button",
n_clicks=0,
className="btn btn-secondary"
)
])
]),
html.Div(id="performance-plot", className="mb-4"),
html.Div(id="sentiment-results"),
html.Div(id="error-display", className="alert alert-danger", style={"display": "none"})
])
def create_sentiment_card(asset, sentiment_counts, article_count):
"""Generate a sentiment card for a given asset with sentiment breakdown and article count."""
return html.Div(className="card mb-3", children=[
html.Div(className="card-header", children=[
html.H5(f"{asset} Sentiment Analysis", className="mb-0")
]),
html.Div(className="card-body", children=[
html.Div(className="row", children=[
html.Div(className="col-sm-4", children=[
html.Div(className="alert alert-success", children=[
html.Strong("Positive: "),
html.Span(f"{sentiment_counts.get('positive', 0):.1f}%")
])
]),
html.Div(className="col-sm-4", children=[
html.Div(className="alert alert-secondary", children=[
html.Strong("Neutral: "),
html.Span(f"{sentiment_counts.get('neutral', 0):.1f}%")
])
]),
html.Div(className="col-sm-4", children=[
html.Div(className="alert alert-danger", children=[
html.Strong("Negative: "),
html.Span(f"{sentiment_counts.get('negative', 0):.1f}%")
])
])
]),
html.Div(className="mt-3 text-muted", children=[
f"Based on analysis of {article_count} recent news articles"
])
])
])
def create_performance_plot_layout(fig, selected_year, selected_month):
"""Generate layout for displaying performance plot."""
return html.Div([
html.H4(f"Performance Visualization for {selected_month}{selected_year}", className="mb-3"),
dcc.Graph(figure=fig)
])