3.10 Enhance data analysis components with type conversion and UI improvements

- Added type conversion for relevant columns in `VolumeAnalyzer` and `PriceMovementAnalyzer` to ensure consistent data handling and avoid type errors.
- Refactored the `create_data_analysis_panel` function to implement a tabbed interface for volume and price movement analysis, improving user experience and organization of analysis tools.
- Updated styles in `indicator_modal.py` for better layout and responsiveness of the modal component.
- Marked unit testing of dashboard components as complete in the task list.
This commit is contained in:
Vasily.onl 2025-06-06 13:13:11 +08:00
parent b4798bfc07
commit 38cbf9cd2f
3 changed files with 43 additions and 61 deletions

View File

@ -32,6 +32,15 @@ class VolumeAnalyzer:
if df.empty or 'volume' not in df.columns:
return {'error': 'DataFrame is empty or missing volume column'}
# Convert all relevant columns to float to avoid type errors with Decimal
df = df.copy()
numeric_cols = ['open', 'high', 'low', 'close', 'volume']
for col in numeric_cols:
if col in df.columns:
df[col] = df[col].astype(float)
if 'trades_count' in df.columns:
df['trades_count'] = df['trades_count'].astype(float)
# Calculate volume statistics
total_volume = df['volume'].sum()
avg_volume = df['volume'].mean()
@ -93,6 +102,13 @@ class PriceMovementAnalyzer:
if df.empty or not all(col in df.columns for col in ['open', 'high', 'low', 'close']):
return {'error': 'DataFrame is empty or missing required price columns'}
# Convert all relevant columns to float to avoid type errors with Decimal
df = df.copy()
numeric_cols = ['open', 'high', 'low', 'close', 'volume']
for col in numeric_cols:
if col in df.columns:
df[col] = df[col].astype(float)
# Basic price statistics
current_price = df['close'].iloc[-1]
period_start_price = df['open'].iloc[0]
@ -434,55 +450,28 @@ def create_price_movement_chart(symbol: str, timeframe: str = "1h", days_back: i
def create_data_analysis_panel():
"""Create the data analysis panel with volume and price movement tools."""
"""Create the main data analysis panel with tabs for different analyses."""
return html.Div([
html.H3("📊 Data Analysis Tools", style={'margin-bottom': '20px'}),
# Analysis type selection - using regular dropdown instead of SegmentedControl
html.Div([
html.Label("Analysis Type:", style={'font-weight': 'bold', 'margin-right': '10px'}),
dcc.Dropdown(
id="analysis-type-selector",
options=[
{"label": "Volume Analysis", "value": "volume"},
{"label": "Price Movement", "value": "price"},
{"label": "Combined Stats", "value": "combined"}
],
value="volume",
clearable=False,
style={'width': '200px', 'display': 'inline-block'}
)
], style={'margin-bottom': '20px'}),
# Time period selector - using regular dropdown
html.Div([
html.Label("Analysis Period:", style={'font-weight': 'bold', 'margin-right': '10px'}),
dcc.Dropdown(
id="analysis-period-selector",
options=[
{"label": "1 Day", "value": "1"},
{"label": "3 Days", "value": "3"},
{"label": "7 Days", "value": "7"},
{"label": "14 Days", "value": "14"},
{"label": "30 Days", "value": "30"}
],
value="7",
clearable=False,
style={'width': '150px', 'display': 'inline-block'}
)
], style={'margin-bottom': '20px'}),
# Charts container
html.Div(id="analysis-chart-container", children=[
html.P("Chart container loaded - waiting for callback...")
]),
# Statistics container
html.Div(id="analysis-stats-container", children=[
html.P("Stats container loaded - waiting for callback...")
])
], style={'border': '1px solid #ccc', 'padding': '20px', 'margin-top': '20px'})
dcc.Tabs(
id="data-analysis-tabs",
value="volume-analysis",
children=[
dcc.Tab(label="Volume Analysis", value="volume-analysis", children=[
html.Div(id='volume-analysis-content', children=[
html.P("Content for Volume Analysis")
]),
html.Div(id='volume-stats-container', children=[
html.P("Stats container loaded - waiting for callback...")
])
]),
dcc.Tab(label="Price Movement", value="price-movement", children=[
html.Div(id='price-movement-content', children=[
dmc.Alert("Select a symbol and timeframe to view price movement analysis.", color="blue")
])
]),
],
)
], id='data-analysis-panel-wrapper')
def format_number(value: float, decimals: int = 2) -> str:

View File

@ -262,22 +262,15 @@ def create_indicator_modal():
}
),
html.Div(id='save-indicator-feedback', style={'margin-top': '10px'})
], style={'text-align': 'right', 'border-top': '1px solid #eee', 'padding-top': '15px'})
], style={'display': 'flex', 'justify-content': 'flex-end', 'margin-top': '20px', 'border-top': '1px solid #eee', 'padding-top': '15px'})
], style={
'background-color': 'white',
'margin': '5% auto',
'padding': '30px',
'background': 'white',
'padding': '20px',
'border-radius': '8px',
'box-shadow': '0 4px 6px rgba(0, 0, 0, 0.1)',
'width': '600px',
'max-width': '90%',
'max-height': '80%',
'overflow-y': 'auto'
'box-shadow': '0 4px 8px rgba(0,0,0,0.1)'
})
],
id='indicator-modal',
style={
], id='indicator-modal-content', style={
'display': 'none',
'position': 'fixed',
'z-index': '1001',

View File

@ -88,7 +88,7 @@
- [x] 3.7 Add the chart time range selector and trigger for realtime data or historical data (when i analyze specified time range i do not want it to reset with realtime data triggers and callbacks)
- [-] 3.8 Setup real-time dashboard updates using Redis callbacks (DEFERRED: Redis is not used for real-time dashboard updates now)
- [x] 3.9 Add data export functionality for analysis (CSV/JSON export)
- [ ] 3.10 Unit test basic dashboard components and data visualization
- [x] 3.10 Unit test basic dashboard components and data visualization
- [ ] 4.0 Strategy Engine and Bot Management Framework
- [ ] 4.1 Design and implement base strategy interface class