File size: 11,956 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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
"""
File upload component
"""
import dash
from dash import dcc, html
import dash_bootstrap_components as dbc
def create_upload_component():
"""
Create the file upload component with drag-and-drop
Returns:
Dash component
"""
return dbc.Card([
dbc.CardHeader(html.H5("Data Input", className="mb-0")),
dbc.CardBody([
dcc.Upload(
id='upload-data',
children=html.Div([
html.I(className="fas fa-cloud-upload-alt fa-3x mb-3"),
html.H5('Drag and Drop or Click to Select File'),
html.P('Supported formats: CSV, Excel (max 100MB)', className='text-muted')
]),
style={
'width': '100%',
'height': '150px',
'lineHeight': '150px',
'borderWidth': '2px',
'borderStyle': 'dashed',
'borderRadius': '10px',
'textAlign': 'center',
'backgroundColor': '#f8f9fa'
},
multiple=False
),
html.Div(id='upload-status', className='mt-3'),
])
], className='mb-4')
def create_column_selector():
"""
Create column mapping dropdowns with support for multivariate and covariate-informed forecasting
Returns:
Dash component
"""
return dbc.Card([
dbc.CardHeader(html.H5("Data Configuration", className="mb-0")),
dbc.CardBody([
# Forecasting Mode Selector
dbc.Row([
dbc.Col([
dbc.Label("Forecasting Mode", className="fw-bold"),
dcc.RadioItems(
id='forecasting-mode',
options=[
{'label': ' Univariate (Single target)', 'value': 'univariate'},
{'label': ' Multivariate (Multiple targets)', 'value': 'multivariate'},
{'label': ' Covariate-informed (With external variables)', 'value': 'covariate'}
],
value='univariate',
className='mt-2',
labelStyle={'display': 'block', 'marginBottom': '8px'}
),
html.Small("Chronos-2 supports all three modes with zero-shot learning",
className='text-muted')
], md=12),
], className='mb-3'),
html.Hr(),
# Column Selection
dbc.Row([
dbc.Col([
dbc.Label("Date/Timestamp Column"),
dcc.Dropdown(
id='date-column-dropdown',
placeholder='Select date column...',
clearable=False
)
], md=4),
dbc.Col([
dbc.Label("Target Variable(s)"),
dcc.Dropdown(
id='target-column-dropdown',
placeholder='Select target column(s)...',
clearable=False,
multi=True # Enable multi-select
),
html.Small(id='target-help-text', className='text-muted')
], md=4),
dbc.Col([
dbc.Label("ID Column (Optional)"),
dcc.Dropdown(
id='id-column-dropdown',
placeholder='Select ID column (optional)...',
clearable=True
),
html.Small("For multiple time series", className='text-muted')
], md=4),
], className='mb-3'),
# Covariate Selection (shown only for covariate-informed mode)
html.Div([
dbc.Row([
dbc.Col([
dbc.Label("Covariate Columns"),
dcc.Dropdown(
id='covariate-columns-dropdown',
placeholder='Select covariate column(s)...',
clearable=True,
multi=True
),
html.Small("External variables that may influence the forecast",
className='text-muted')
], md=12),
], className='mb-3'),
], id='covariate-section', style={'display': 'none'}),
html.Hr(),
html.Div(id='data-preview-container', className='mt-3'),
html.Div(id='data-quality-report', className='mt-3')
])
], className='mb-4', id='column-selector-card', style={'display': 'none'})
def create_sample_data_loader():
"""
Create sample data loader component
Returns:
Dash component
"""
return dbc.Card([
dbc.CardBody([
html.H6("Quick Start with Sample Data"),
dbc.Row([
dbc.Col([
dbc.Button(
"Weather Stations",
id='load-weather',
color='outline-primary',
size='sm',
className='w-100 mb-2'
),
], md=4),
dbc.Col([
dbc.Button(
"Air Quality UCI",
id='load-airquality',
color='outline-primary',
size='sm',
className='w-100 mb-2'
),
], md=4),
dbc.Col([
dbc.Button(
"Bitcoin Price",
id='load-bitcoin',
color='outline-primary',
size='sm',
className='w-100 mb-2'
),
], md=4),
]),
dbc.Row([
dbc.Col([
dbc.Button(
"S&P 500 Stock",
id='load-stock',
color='outline-primary',
size='sm',
className='w-100 mb-2'
),
], md=4),
dbc.Col([
dbc.Button(
"Traffic Speeds",
id='load-traffic',
color='outline-primary',
size='sm',
className='w-100 mb-2'
),
], md=4),
dbc.Col([
dbc.Button(
"Electricity Consumption",
id='load-electricity',
color='outline-primary',
size='sm',
className='w-100 mb-2'
),
], md=4),
]),
])
], className='mb-4')
def format_upload_status(status: str, message: str, is_error: bool = False):
"""
Format upload status message
Args:
status: Status type ('success', 'error', 'info')
message: Message to display
is_error: Whether this is an error message
Returns:
Dash component
"""
if is_error or status == 'error':
return dbc.Alert([
html.I(className="fas fa-exclamation-circle me-2"),
message
], color='danger', dismissable=True)
elif status == 'success':
return dbc.Alert([
html.I(className="fas fa-check-circle me-2"),
message
], color='success', dismissable=True)
elif status == 'warning':
return dbc.Alert([
html.I(className="fas fa-exclamation-triangle me-2"),
message
], color='warning', dismissable=True)
else:
return dbc.Alert([
html.I(className="fas fa-info-circle me-2"),
message
], color='info', dismissable=True)
def create_data_preview_table(df, n_rows=10):
"""
Create a data preview table
Args:
df: DataFrame to preview
n_rows: Number of rows to show
Returns:
Dash component
"""
if df is None or df.empty:
return html.Div()
return html.Div([
html.H6("Data Preview"),
dbc.Table.from_dataframe(
df.head(n_rows),
striped=True,
bordered=True,
hover=True,
responsive=True,
size='sm'
),
html.P(
f"Showing first {min(n_rows, len(df))} of {len(df)} rows",
className='text-muted small'
)
])
def create_quality_report(report: dict):
"""
Create a data quality report display
Args:
report: Quality report dictionary
Returns:
Dash component
"""
if not report:
return html.Div()
# Build warning messages if needed
warnings = []
if report.get('sampled', False):
warnings.append(
dbc.Alert(
f"⚠️ Large dataset detected: Sampled from {report.get('original_points', 0):,} to {report.get('total_points', 0):,} rows (most recent data retained)",
color="warning",
className="mb-2"
)
)
if report.get('duplicates_removed', 0) > 0:
warnings.append(
dbc.Alert(
f"⚠️ Removed {report.get('duplicates_removed', 0):,} duplicate timestamps",
color="info",
className="mb-2"
)
)
return dbc.Card([
dbc.CardHeader(html.H6("Data Quality Report", className="mb-0")),
dbc.CardBody([
html.Div(warnings) if warnings else None,
dbc.Row([
dbc.Col([
html.Small("Total Points", className='text-muted'),
html.H6(f"{report.get('total_points', 0):,}")
], md=3),
dbc.Col([
html.Small("Date Range", className='text-muted'),
html.H6(f"{report.get('date_range', {}).get('start', 'N/A')} to {report.get('date_range', {}).get('end', 'N/A')}",
style={'fontSize': '0.9rem'})
], md=3),
dbc.Col([
html.Small("Frequency", className='text-muted'),
html.H6(report.get('frequency', 'Unknown'))
], md=2),
dbc.Col([
html.Small("Missing Filled", className='text-muted'),
html.H6(str(report.get('missing_filled', 0)))
], md=2),
dbc.Col([
html.Small("Outliers", className='text-muted'),
html.H6(str(report.get('outliers_detected', 0)))
], md=2),
]),
html.Hr(),
dbc.Row([
dbc.Col([
html.Small("Mean", className='text-muted'),
html.P(f"{report.get('statistics', {}).get('mean', 0):.2f}")
], md=3),
dbc.Col([
html.Small("Std Dev", className='text-muted'),
html.P(f"{report.get('statistics', {}).get('std', 0):.2f}")
], md=3),
dbc.Col([
html.Small("Min", className='text-muted'),
html.P(f"{report.get('statistics', {}).get('min', 0):.2f}")
], md=3),
dbc.Col([
html.Small("Max", className='text-muted'),
html.P(f"{report.get('statistics', {}).get('max', 0):.2f}")
], md=3),
])
])
], className='mt-3')
|