Spaces:
Running
Running
Mandark-droid commited on
Commit ·
79f1857
1
Parent(s): fd7daa9
Fix Trends tab error handling for HuggingFace data
Browse files- components/analytics_charts.py +67 -37
components/analytics_charts.py
CHANGED
|
@@ -648,7 +648,16 @@ def create_trends_plot(df: pd.DataFrame) -> go.Figure:
|
|
| 648 |
|
| 649 |
# Convert timestamp to datetime
|
| 650 |
df = df.copy()
|
| 651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
|
| 653 |
# Sort by timestamp
|
| 654 |
df = df.sort_values('timestamp')
|
|
@@ -656,51 +665,72 @@ def create_trends_plot(df: pd.DataFrame) -> go.Figure:
|
|
| 656 |
# Aggregate by date (in case multiple runs per day)
|
| 657 |
df['date'] = df['timestamp'].dt.date
|
| 658 |
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
|
| 666 |
# Create figure with secondary y-axis
|
| 667 |
fig = go.Figure()
|
| 668 |
|
| 669 |
# Success Rate
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
|
|
|
| 680 |
|
| 681 |
# Duration
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
|
|
|
| 692 |
|
| 693 |
# Cost
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
|
|
|
| 704 |
|
| 705 |
fig.update_layout(
|
| 706 |
title={
|
|
|
|
| 648 |
|
| 649 |
# Convert timestamp to datetime
|
| 650 |
df = df.copy()
|
| 651 |
+
try:
|
| 652 |
+
df['timestamp'] = pd.to_datetime(df['timestamp'])
|
| 653 |
+
except Exception as e:
|
| 654 |
+
return _create_empty_figure(f"Error parsing timestamp data: {str(e)}")
|
| 655 |
+
|
| 656 |
+
# Remove rows with invalid timestamps
|
| 657 |
+
df = df.dropna(subset=['timestamp'])
|
| 658 |
+
|
| 659 |
+
if df.empty:
|
| 660 |
+
return _create_empty_figure("No valid timestamp data available")
|
| 661 |
|
| 662 |
# Sort by timestamp
|
| 663 |
df = df.sort_values('timestamp')
|
|
|
|
| 665 |
# Aggregate by date (in case multiple runs per day)
|
| 666 |
df['date'] = df['timestamp'].dt.date
|
| 667 |
|
| 668 |
+
# Check which metrics are available
|
| 669 |
+
available_metrics = []
|
| 670 |
+
agg_dict = {}
|
| 671 |
+
|
| 672 |
+
if 'success_rate' in df.columns:
|
| 673 |
+
agg_dict['success_rate'] = 'mean'
|
| 674 |
+
available_metrics.append('success_rate')
|
| 675 |
+
if 'avg_duration_ms' in df.columns:
|
| 676 |
+
agg_dict['avg_duration_ms'] = 'mean'
|
| 677 |
+
available_metrics.append('avg_duration_ms')
|
| 678 |
+
if 'total_cost_usd' in df.columns:
|
| 679 |
+
agg_dict['total_cost_usd'] = 'mean'
|
| 680 |
+
available_metrics.append('total_cost_usd')
|
| 681 |
+
if 'total_tokens' in df.columns:
|
| 682 |
+
agg_dict['total_tokens'] = 'mean'
|
| 683 |
+
available_metrics.append('total_tokens')
|
| 684 |
+
|
| 685 |
+
if not agg_dict:
|
| 686 |
+
return _create_empty_figure("No metrics available for trends analysis")
|
| 687 |
+
|
| 688 |
+
daily_stats = df.groupby('date').agg(agg_dict).reset_index()
|
| 689 |
+
|
| 690 |
+
if daily_stats.empty:
|
| 691 |
+
return _create_empty_figure("No data after aggregation")
|
| 692 |
|
| 693 |
# Create figure with secondary y-axis
|
| 694 |
fig = go.Figure()
|
| 695 |
|
| 696 |
# Success Rate
|
| 697 |
+
if 'success_rate' in daily_stats.columns:
|
| 698 |
+
fig.add_trace(go.Scatter(
|
| 699 |
+
x=daily_stats['date'],
|
| 700 |
+
y=daily_stats['success_rate'],
|
| 701 |
+
name='Success Rate (%)',
|
| 702 |
+
mode='lines+markers',
|
| 703 |
+
line=dict(color='#2ECC71', width=3),
|
| 704 |
+
marker=dict(size=8),
|
| 705 |
+
yaxis='y1',
|
| 706 |
+
hovertemplate='<b>Success Rate</b><br>Date: %{x}<br>Rate: %{y:.1f}%<extra></extra>'
|
| 707 |
+
))
|
| 708 |
|
| 709 |
# Duration
|
| 710 |
+
if 'avg_duration_ms' in daily_stats.columns:
|
| 711 |
+
fig.add_trace(go.Scatter(
|
| 712 |
+
x=daily_stats['date'],
|
| 713 |
+
y=daily_stats['avg_duration_ms'],
|
| 714 |
+
name='Avg Duration (ms)',
|
| 715 |
+
mode='lines+markers',
|
| 716 |
+
line=dict(color='#3498DB', width=3),
|
| 717 |
+
marker=dict(size=8),
|
| 718 |
+
yaxis='y2',
|
| 719 |
+
hovertemplate='<b>Duration</b><br>Date: %{x}<br>Time: %{y:.0f}ms<extra></extra>'
|
| 720 |
+
))
|
| 721 |
|
| 722 |
# Cost
|
| 723 |
+
if 'total_cost_usd' in daily_stats.columns:
|
| 724 |
+
fig.add_trace(go.Scatter(
|
| 725 |
+
x=daily_stats['date'],
|
| 726 |
+
y=daily_stats['total_cost_usd'],
|
| 727 |
+
name='Avg Cost (USD)',
|
| 728 |
+
mode='lines+markers',
|
| 729 |
+
line=dict(color='#E67E22', width=3),
|
| 730 |
+
marker=dict(size=8),
|
| 731 |
+
yaxis='y2',
|
| 732 |
+
hovertemplate='<b>Cost</b><br>Date: %{x}<br>Cost: $%{y:.4f}<extra></extra>'
|
| 733 |
+
))
|
| 734 |
|
| 735 |
fig.update_layout(
|
| 736 |
title={
|