- Deleted `app_new.py`, which was previously the main entry point for the dashboard application, to streamline the codebase. - Consolidated the application initialization and callback registration logic into `main.py`, enhancing modularity and maintainability. - Updated the logging and error handling practices in `main.py` to ensure consistent application behavior and improved debugging capabilities. These changes simplify the application structure, aligning with project standards for modularity and maintainability.
62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
"""
|
|
Data analysis callbacks for the dashboard.
|
|
"""
|
|
|
|
from dash import Output, Input, html, dcc
|
|
import dash_bootstrap_components as dbc
|
|
from utils.logger import get_logger
|
|
from dashboard.components.data_analysis import (
|
|
create_volume_stats_display,
|
|
create_price_stats_display,
|
|
get_market_statistics,
|
|
VolumeAnalyzer,
|
|
PriceMovementAnalyzer
|
|
)
|
|
from database.operations import get_database_operations
|
|
from datetime import datetime, timezone, timedelta
|
|
|
|
logger = get_logger("data_analysis_callbacks")
|
|
|
|
|
|
def register_data_analysis_callbacks(app):
|
|
"""Register data analysis related callbacks."""
|
|
|
|
logger.info("🚀 STARTING to register data analysis callbacks...")
|
|
|
|
# Initial callback to populate charts on load
|
|
@app.callback(
|
|
[Output('volume-analysis-chart', 'figure'),
|
|
Output('price-movement-chart', 'figure'),
|
|
Output('volume-stats-output', 'children'),
|
|
Output('price-stats-output', 'children'),
|
|
Output('market-statistics-output', 'children')],
|
|
[Input('data-analysis-symbol-dropdown', 'value'),
|
|
Input('data-analysis-timeframe-dropdown', 'value'),
|
|
Input('data-analysis-days-back-dropdown', 'value')],
|
|
prevent_initial_call=False
|
|
)
|
|
def update_data_analysis(symbol, timeframe, days_back):
|
|
"""Update data analysis with statistical cards only (no duplicate charts)."""
|
|
logger.info(f"🎯 DATA ANALYSIS CALLBACK TRIGGERED! Symbol: {symbol}, Timeframe: {timeframe}, Days Back: {days_back}")
|
|
|
|
db_ops = get_database_operations(logger)
|
|
end_time = datetime.now(timezone.utc)
|
|
start_time = end_time - timedelta(days=days_back)
|
|
|
|
df = db_ops.market_data.get_candles_df(symbol, timeframe, start_time, end_time)
|
|
|
|
volume_analyzer = VolumeAnalyzer()
|
|
price_analyzer = PriceMovementAnalyzer()
|
|
|
|
volume_stats = volume_analyzer.get_volume_statistics(df)
|
|
price_stats = price_analyzer.get_price_movement_statistics(df)
|
|
|
|
volume_stats_display = create_volume_stats_display(volume_stats)
|
|
price_stats_display = create_price_stats_display(price_stats)
|
|
market_stats_display = get_market_statistics(df, symbol, timeframe)
|
|
|
|
# Return empty figures for charts, as they are no longer the primary display
|
|
# And the stats displays
|
|
return {}, {}, volume_stats_display, price_stats_display, market_stats_display
|
|
|
|
logger.info("✅ Data analysis callbacks registered successfully") |