File size: 8,014 Bytes
15b68db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
"""
Control components for forecast parameters
"""

import dash
from dash import dcc, html
import dash_bootstrap_components as dbc
from config.constants import FORECAST_HORIZONS, CONFIDENCE_LEVELS


def create_forecast_controls():
    """
    Create forecast parameter controls

    Returns:
        Dash component
    """
    return dbc.Card([
        dbc.CardHeader(html.H5("Forecasting Parameters", className="mb-0")),
        dbc.CardBody([
            # Forecast Horizon Slider
            html.Label("Forecast Horizon (Days)", className="fw-bold"),
            dcc.Slider(
                id='horizon-slider',
                min=1,
                max=365,
                step=1,
                value=30,
                marks={
                    1: '1D',
                    7: '1W',
                    30: '1M',
                    90: '3M',
                    180: '6M',
                    365: '1Y'
                },
                tooltip={"placement": "bottom", "always_visible": True},
                className='mb-4'
            ),

            # Confidence Levels
            html.Label("Confidence Levels", className="fw-bold mt-3"),
            dbc.Checklist(
                id='confidence-checklist',
                options=[
                    {'label': '80%', 'value': 80},
                    {'label': '90%', 'value': 90},
                    {'label': '95%', 'value': 95},
                    {'label': '99%', 'value': 99},
                ],
                value=[80, 95],
                inline=True,
                className='mb-4'
            ),

            # Backtesting Section
            html.Hr(),
            html.Label("Model Performance Validation", className="fw-bold mt-3"),
            dbc.Checklist(
                id='backtest-enable',
                options=[
                    {'label': ' Enable backtesting (show model performance on historical data)', 'value': 'enabled'}
                ],
                value=[],
                className='mb-3'
            ),

            # Backtest Size Slider (only visible when backtest is enabled)
            html.Div([
                html.Label("Backtest Period (Days)", className="fw-bold"),
                html.Small(" - Amount of historical data to use for validation", className="text-muted"),
                dcc.Slider(
                    id='backtest-size-slider',
                    min=5,
                    max=180,
                    step=5,
                    value=30,
                    marks={
                        5: '5D',
                        30: '1M',
                        60: '2M',
                        90: '3M',
                        180: '6M'
                    },
                    tooltip={"placement": "bottom", "always_visible": True},
                    className='mb-3'
                ),
            ], id='backtest-controls', style={'display': 'none'}),

            # Generate Button
            dbc.Button(
                [
                    html.I(className="fas fa-chart-line me-2"),
                    "Generate Forecast"
                ],
                id='generate-forecast-btn',
                color='primary',
                size='lg',
                className='w-100 mt-3',
                disabled=True
            ),

            # Loading indicator
            dcc.Loading(
                id="loading-forecast",
                type="default",
                children=html.Div(id="loading-output")
            )
        ])
    ], className='mb-4')


def create_model_status_bar(status: str = 'loading'):
    """
    Create model status indicator

    Args:
        status: 'loading', 'ready', 'error'

    Returns:
        Dash component
    """
    if status == 'loading':
        return dbc.Alert([
            dbc.Spinner(size="sm", className="me-2"),
            html.Span("Loading Chronos 2 model...")
        ], color='info', className='mb-4')
    elif status == 'ready':
        return dbc.Alert([
            html.I(className="fas fa-check-circle me-2"),
            html.Span("Model loaded and ready")
        ], color='success', className='mb-4', dismissable=True)
    elif status == 'error':
        return dbc.Alert([
            html.I(className="fas fa-exclamation-circle me-2"),
            html.Span("Failed to load model. Please check logs.")
        ], color='danger', className='mb-4')
    else:
        return html.Div()


def create_results_section():
    """
    Create the results visualization section

    Returns:
        Dash component
    """
    return dbc.Card([
        dbc.CardHeader(html.H5("Forecast Results", className="mb-0")),
        dbc.CardBody([
            # Chart container
            dcc.Graph(
                id='forecast-chart',
                config=create_chart_config(),
                style={'height': '600px'}
            ),

            # Metrics row
            html.Div(id='metrics-display', className='mt-4')
        ])
    ], className='mb-4', id='results-card', style={'display': 'none'})


def create_chart_config():
    """
    Create Plotly chart configuration

    Returns:
        Configuration dictionary
    """
    from config.constants import CHART_CONFIG
    return CHART_CONFIG


def create_app_header():
    """
    Create application header

    Returns:
        Dash component
    """
    from config.settings import APP_METADATA

    return dbc.Navbar(
        dbc.Container([
            dbc.Row([
                dbc.Col([
                    html.Div([
                        html.H2(APP_METADATA['title'], className="mb-0 text-white"),
                        html.P(APP_METADATA['subtitle'], className="mb-0 text-white-50 small")
                    ])
                ])
            ], align="center", className="g-0 w-100")
        ], fluid=True),
        color="primary",
        dark=True,
        className="mb-4"
    )


def create_footer():
    """
    Create application footer

    Returns:
        Dash component
    """
    from config.settings import APP_METADATA

    return html.Footer([
        html.Hr(),
        dbc.Container([
            dbc.Row([
                dbc.Col([
                    html.Div([
                        html.P([
                            "Created by ",
                            html.A([
                                html.I(className="fab fa-linkedin me-1"),
                                "Abhay Pratap Singh"
                            ],
                            href="https://www.linkedin.com/in/mindful-abhay/",
                            target="_blank",
                            className="text-primary fw-bold",
                            style={'textDecoration': 'none'}
                            )
                        ], className="text-center mb-2"),
                        html.P([
                            html.A([
                                html.I(className="fas fa-coffee me-2"),
                                "Buy me a coffee"
                            ],
                            href="https://buymeacoffee.com/abhaypratapsingh",
                            target="_blank",
                            className="btn btn-outline-warning btn-sm"
                            )
                        ], className="text-center mb-2"),
                        html.P([
                            f"Version {APP_METADATA['version']}"
                        ], className="text-center text-muted small mb-0")
                    ])
                ])
            ])
        ])
    ], className="mt-5 mb-3")


def create_progress_indicator(progress: int, message: str = "Processing..."):
    """
    Create a progress indicator

    Args:
        progress: Progress percentage (0-100)
        message: Progress message

    Returns:
        Dash component
    """
    return dbc.Card([
        dbc.CardBody([
            html.H6(message, className="mb-3"),
            dbc.Progress(value=progress, striped=True, animated=True)
        ])
    ])