Spaces:
Running
Running
Commit
·
c2ee0af
1
Parent(s):
49ead1e
fix: Handle zero-cost models in cost-performance efficiency chart
Browse filesFix issue where 17 models with zero cost were clustered in a vertical
line due to log(0) being undefined on logarithmic X-axis scale.
Changes:
- Add epsilon value (0.00001) for zero-cost models to enable proper
log scale positioning
- Create separate display column for visualization while preserving
actual cost data
- Update hover text to indicate when cost data is missing
- Adjust star annotations to use display values
Result: All 50+ models now properly distributed across cost spectrum
from $0.00001 (no cost data) to $7.35 (premium models).
components/analytics_charts.py
CHANGED
|
@@ -317,6 +317,14 @@ def create_cost_efficiency_scatter(df: pd.DataFrame) -> go.Figure:
|
|
| 317 |
|
| 318 |
model_stats = df.groupby('model').agg(agg_dict).reset_index()
|
| 319 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
# Calculate efficiency metric: success_rate / cost
|
| 321 |
model_stats['efficiency'] = model_stats['success_rate'] / (model_stats['total_cost_usd'] + 0.0001) # Avoid division by zero
|
| 322 |
|
|
@@ -346,7 +354,11 @@ def create_cost_efficiency_scatter(df: pd.DataFrame) -> go.Figure:
|
|
| 346 |
model_name = row['model'].split('/')[-1] if '/' in row['model'] else row['model']
|
| 347 |
hover = f"<b>{model_name}</b><br>"
|
| 348 |
hover += f"Success Rate: {row['success_rate']:.1f}%<br>"
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
hover += f"Efficiency: {row['efficiency']:.0f} (points/$)<br>"
|
| 351 |
if 'avg_duration_ms' in row and pd.notna(row['avg_duration_ms']):
|
| 352 |
hover += f"Duration: {row['avg_duration_ms']:.0f}ms"
|
|
@@ -361,7 +373,7 @@ def create_cost_efficiency_scatter(df: pd.DataFrame) -> go.Figure:
|
|
| 361 |
sizes = 30 # Default size
|
| 362 |
|
| 363 |
fig.add_trace(go.Scatter(
|
| 364 |
-
x=subset['
|
| 365 |
y=subset['success_rate'],
|
| 366 |
mode='markers+text',
|
| 367 |
name=str(provider).title(),
|
|
@@ -413,7 +425,7 @@ def create_cost_efficiency_scatter(df: pd.DataFrame) -> go.Figure:
|
|
| 413 |
top_efficient = model_stats.nlargest(3, 'efficiency')
|
| 414 |
for _, row in top_efficient.iterrows():
|
| 415 |
fig.add_annotation(
|
| 416 |
-
x=row['
|
| 417 |
y=row['success_rate'],
|
| 418 |
text="⭐",
|
| 419 |
showarrow=False,
|
|
|
|
| 317 |
|
| 318 |
model_stats = df.groupby('model').agg(agg_dict).reset_index()
|
| 319 |
|
| 320 |
+
# Handle zero costs for log scale visualization
|
| 321 |
+
# Replace zero costs with a small epsilon value (0.00001)
|
| 322 |
+
# This allows log scale to work properly while keeping all models visible
|
| 323 |
+
EPSILON = 0.00001
|
| 324 |
+
model_stats['total_cost_usd_display'] = model_stats['total_cost_usd'].apply(
|
| 325 |
+
lambda x: max(x, EPSILON)
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
# Calculate efficiency metric: success_rate / cost
|
| 329 |
model_stats['efficiency'] = model_stats['success_rate'] / (model_stats['total_cost_usd'] + 0.0001) # Avoid division by zero
|
| 330 |
|
|
|
|
| 354 |
model_name = row['model'].split('/')[-1] if '/' in row['model'] else row['model']
|
| 355 |
hover = f"<b>{model_name}</b><br>"
|
| 356 |
hover += f"Success Rate: {row['success_rate']:.1f}%<br>"
|
| 357 |
+
# Show actual cost (even if zero) in hover text
|
| 358 |
+
if row['total_cost_usd'] == 0:
|
| 359 |
+
hover += f"Total Cost: $0.0000 (No cost data)<br>"
|
| 360 |
+
else:
|
| 361 |
+
hover += f"Total Cost: ${row['total_cost_usd']:.4f}<br>"
|
| 362 |
hover += f"Efficiency: {row['efficiency']:.0f} (points/$)<br>"
|
| 363 |
if 'avg_duration_ms' in row and pd.notna(row['avg_duration_ms']):
|
| 364 |
hover += f"Duration: {row['avg_duration_ms']:.0f}ms"
|
|
|
|
| 373 |
sizes = 30 # Default size
|
| 374 |
|
| 375 |
fig.add_trace(go.Scatter(
|
| 376 |
+
x=subset['total_cost_usd_display'], # Use adjusted cost for log scale
|
| 377 |
y=subset['success_rate'],
|
| 378 |
mode='markers+text',
|
| 379 |
name=str(provider).title(),
|
|
|
|
| 425 |
top_efficient = model_stats.nlargest(3, 'efficiency')
|
| 426 |
for _, row in top_efficient.iterrows():
|
| 427 |
fig.add_annotation(
|
| 428 |
+
x=row['total_cost_usd_display'], # Use adjusted cost for positioning
|
| 429 |
y=row['success_rate'],
|
| 430 |
text="⭐",
|
| 431 |
showarrow=False,
|