MCPcopy Create free account
hub / github.com/shiyu-coder/Kronos / load_data

Function load_data

webui/app.py:342–402  ·  view source on GitHub ↗

Load data file

()

Source from the content-addressed store, hash-verified

340
341@app.route('/api/load-data', methods=['POST'])
342def load_data():
343 """Load data file"""
344 try:
345 data = request.get_json()
346 file_path = data.get('file_path')
347
348 if not file_path:
349 return jsonify({'error': 'File path cannot be empty'}), 400
350
351 df, error = load_data_file(file_path)
352 if error:
353 return jsonify({'error': error}), 400
354
355 # Detect data time frequency
356 def detect_timeframe(df):
357 if len(df) < 2:
358 return "Unknown"
359
360 time_diffs = []
361 for i in range(1, min(10, len(df))): # Check first 10 time differences
362 diff = df['timestamps'].iloc[i] - df['timestamps'].iloc[i-1]
363 time_diffs.append(diff)
364
365 if not time_diffs:
366 return "Unknown"
367
368 # Calculate average time difference
369 avg_diff = sum(time_diffs, pd.Timedelta(0)) / len(time_diffs)
370
371 # Convert to readable format
372 if avg_diff < pd.Timedelta(minutes=1):
373 return f"{avg_diff.total_seconds():.0f} seconds"
374 elif avg_diff < pd.Timedelta(hours=1):
375 return f"{avg_diff.total_seconds() / 60:.0f} minutes"
376 elif avg_diff < pd.Timedelta(days=1):
377 return f"{avg_diff.total_seconds() / 3600:.0f} hours"
378 else:
379 return f"{avg_diff.days} days"
380
381 # Return data information
382 data_info = {
383 'rows': len(df),
384 'columns': list(df.columns),
385 'start_date': df['timestamps'].min().isoformat() if 'timestamps' in df.columns else 'N/A',
386 'end_date': df['timestamps'].max().isoformat() if 'timestamps' in df.columns else 'N/A',
387 'price_range': {
388 'min': float(df[['open', 'high', 'low', 'close']].min().min()),
389 'max': float(df[['open', 'high', 'low', 'close']].max().max())
390 },
391 'prediction_columns': ['open', 'high', 'low', 'close'] + (['volume'] if 'volume' in df.columns else []),
392 'timeframe': detect_timeframe(df)
393 }
394
395 return jsonify({
396 'success': True,
397 'data_info': data_info,
398 'message': f'Successfully loaded data, total {len(df)} rows'
399 })

Callers

nothing calls this directly

Calls 3

load_data_fileFunction · 0.85
detect_timeframeFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected