""" 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) ]) ])