Spaces:
Running
Running
gauravlochab
commited on
Commit
·
9408331
1
Parent(s):
3663584
feat: enhance data consistency and logging in combined time series graph
Browse files
app.py
CHANGED
@@ -481,12 +481,22 @@ def create_combined_time_series_graph(df):
|
|
481 |
)
|
482 |
return fig
|
483 |
|
484 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
debug_csv = "debug_graph_data.csv"
|
486 |
df.to_csv(debug_csv)
|
487 |
logger.info(f"Exported graph data to {debug_csv} for debugging")
|
488 |
|
489 |
-
#
|
490 |
with open("debug_graph_data_report.txt", "w") as f:
|
491 |
f.write("==== GRAPH DATA REPORT ====\n\n")
|
492 |
f.write(f"Total data points: {len(df)}\n")
|
@@ -525,8 +535,13 @@ def create_combined_time_series_graph(df):
|
|
525 |
fig = go.Figure()
|
526 |
|
527 |
# Get unique agents
|
|
|
528 |
colors = px.colors.qualitative.Plotly[:len(unique_agents)]
|
529 |
|
|
|
|
|
|
|
|
|
530 |
# Add background shapes for APR and Performance regions
|
531 |
min_time = df['timestamp'].min()
|
532 |
max_time = df['timestamp'].max()
|
@@ -536,7 +551,7 @@ def create_combined_time_series_graph(df):
|
|
536 |
type="rect",
|
537 |
fillcolor="rgba(230, 243, 255, 0.3)",
|
538 |
line=dict(width=0),
|
539 |
-
y0=0, y1=
|
540 |
x0=min_time, x1=max_time,
|
541 |
layer="below"
|
542 |
)
|
@@ -546,7 +561,7 @@ def create_combined_time_series_graph(df):
|
|
546 |
type="rect",
|
547 |
fillcolor="rgba(255, 230, 230, 0.3)",
|
548 |
line=dict(width=0),
|
549 |
-
y0
|
550 |
x0=min_time, x1=max_time,
|
551 |
layer="below"
|
552 |
)
|
@@ -567,7 +582,12 @@ def create_combined_time_series_graph(df):
|
|
567 |
|
568 |
# Sort the data by timestamp
|
569 |
agent_data = agent_data.sort_values('timestamp')
|
570 |
-
|
|
|
|
|
|
|
|
|
|
|
571 |
# Add the combined line for both APR and Performance
|
572 |
fig.add_trace(
|
573 |
go.Scatter(
|
@@ -583,35 +603,43 @@ def create_combined_time_series_graph(df):
|
|
583 |
|
584 |
# Add scatter points for APR values
|
585 |
apr_data = agent_data[agent_data['metric_type'] == 'APR']
|
586 |
-
print("apr_data_combined",apr_data)
|
587 |
if not apr_data.empty:
|
|
|
|
|
|
|
|
|
588 |
fig.add_trace(
|
589 |
go.Scatter(
|
590 |
x=apr_data['timestamp'],
|
591 |
y=apr_data['apr'],
|
592 |
mode='markers',
|
593 |
-
marker=dict(color=color, symbol='circle', size=
|
594 |
name=f'{agent_name} APR',
|
595 |
legendgroup=agent_name,
|
596 |
showlegend=False,
|
597 |
-
hovertemplate='Time: %{x}<br>APR: %{y:.2f}<br>Agent: ' + agent_name + '<extra></extra>'
|
|
|
598 |
)
|
599 |
)
|
600 |
|
601 |
# Add scatter points for Performance values
|
602 |
perf_data = agent_data[agent_data['metric_type'] == 'Performance']
|
603 |
-
print("perf_data_combined",perf_data)
|
604 |
if not perf_data.empty:
|
|
|
|
|
|
|
|
|
605 |
fig.add_trace(
|
606 |
go.Scatter(
|
607 |
x=perf_data['timestamp'],
|
608 |
y=perf_data['apr'],
|
609 |
mode='markers',
|
610 |
-
marker=dict(color=color, symbol='square', size=
|
611 |
name=f'{agent_name} Perf',
|
612 |
legendgroup=agent_name,
|
613 |
showlegend=False,
|
614 |
-
hovertemplate='Time: %{x}<br>Performance: %{y:.2f}<br>Agent: ' + agent_name + '<extra></extra>'
|
|
|
615 |
)
|
616 |
)
|
617 |
|
@@ -635,9 +663,17 @@ def create_combined_time_series_graph(df):
|
|
635 |
hovermode="closest"
|
636 |
)
|
637 |
|
638 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
639 |
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='rgba(0,0,0,0.1)')
|
640 |
-
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='rgba(0,0,0,0.1)')
|
641 |
|
642 |
# Save the figure (still useful for reference)
|
643 |
graph_file = "modius_apr_combined_graph.html"
|
@@ -645,9 +681,12 @@ def create_combined_time_series_graph(df):
|
|
645 |
|
646 |
# Also save as image for compatibility
|
647 |
img_file = "modius_apr_combined_graph.png"
|
648 |
-
|
649 |
-
|
650 |
-
|
|
|
|
|
|
|
651 |
|
652 |
# Return the figure object for direct use in Gradio
|
653 |
return fig
|
|
|
481 |
)
|
482 |
return fig
|
483 |
|
484 |
+
# IMPORTANT: Force data types to ensure consistency
|
485 |
+
df['apr'] = df['apr'].astype(float) # Ensure APR is float
|
486 |
+
df['metric_type'] = df['metric_type'].astype(str) # Ensure metric_type is string
|
487 |
+
|
488 |
+
# CRITICAL: Log the exact dataframe we're using for plotting to help debug
|
489 |
+
logger.info(f"Graph data - shape: {df.shape}, columns: {df.columns}")
|
490 |
+
logger.info(f"Graph data - unique agents: {df['agent_name'].unique().tolist()}")
|
491 |
+
logger.info(f"Graph data - unique metric types: {df['metric_type'].unique().tolist()}")
|
492 |
+
logger.info(f"Graph data - min APR: {df['apr'].min()}, max APR: {df['apr'].max()}")
|
493 |
+
|
494 |
+
# Export full dataframe to CSV for debugging
|
495 |
debug_csv = "debug_graph_data.csv"
|
496 |
df.to_csv(debug_csv)
|
497 |
logger.info(f"Exported graph data to {debug_csv} for debugging")
|
498 |
|
499 |
+
# Write detailed data report
|
500 |
with open("debug_graph_data_report.txt", "w") as f:
|
501 |
f.write("==== GRAPH DATA REPORT ====\n\n")
|
502 |
f.write(f"Total data points: {len(df)}\n")
|
|
|
535 |
fig = go.Figure()
|
536 |
|
537 |
# Get unique agents
|
538 |
+
unique_agents = df['agent_id'].unique()
|
539 |
colors = px.colors.qualitative.Plotly[:len(unique_agents)]
|
540 |
|
541 |
+
# IMPORTANT: Calculate min/max values for proper axis scaling
|
542 |
+
min_apr = min(df['apr'].min(), -100) # Ensure we see at least down to -100
|
543 |
+
max_apr = max(df['apr'].max(), 100) # Ensure we see at least up to 100
|
544 |
+
|
545 |
# Add background shapes for APR and Performance regions
|
546 |
min_time = df['timestamp'].min()
|
547 |
max_time = df['timestamp'].max()
|
|
|
551 |
type="rect",
|
552 |
fillcolor="rgba(230, 243, 255, 0.3)",
|
553 |
line=dict(width=0),
|
554 |
+
y0=0, y1=max_apr,
|
555 |
x0=min_time, x1=max_time,
|
556 |
layer="below"
|
557 |
)
|
|
|
561 |
type="rect",
|
562 |
fillcolor="rgba(255, 230, 230, 0.3)",
|
563 |
line=dict(width=0),
|
564 |
+
y0=min_apr, y1=0,
|
565 |
x0=min_time, x1=max_time,
|
566 |
layer="below"
|
567 |
)
|
|
|
582 |
|
583 |
# Sort the data by timestamp
|
584 |
agent_data = agent_data.sort_values('timestamp')
|
585 |
+
|
586 |
+
# Log actual points being plotted for this agent
|
587 |
+
logger.info(f"Plotting agent: {agent_name} (ID: {agent_id}) with {len(agent_data)} points")
|
588 |
+
for idx, row in agent_data.iterrows():
|
589 |
+
logger.info(f" Point {idx}: timestamp={row['timestamp']}, apr={row['apr']}, type={row['metric_type']}")
|
590 |
+
|
591 |
# Add the combined line for both APR and Performance
|
592 |
fig.add_trace(
|
593 |
go.Scatter(
|
|
|
603 |
|
604 |
# Add scatter points for APR values
|
605 |
apr_data = agent_data[agent_data['metric_type'] == 'APR']
|
|
|
606 |
if not apr_data.empty:
|
607 |
+
logger.info(f" Adding {len(apr_data)} APR markers for {agent_name}")
|
608 |
+
for idx, row in apr_data.iterrows():
|
609 |
+
logger.info(f" APR marker: timestamp={row['timestamp']}, apr={row['apr']}")
|
610 |
+
|
611 |
fig.add_trace(
|
612 |
go.Scatter(
|
613 |
x=apr_data['timestamp'],
|
614 |
y=apr_data['apr'],
|
615 |
mode='markers',
|
616 |
+
marker=dict(color=color, symbol='circle', size=10),
|
617 |
name=f'{agent_name} APR',
|
618 |
legendgroup=agent_name,
|
619 |
showlegend=False,
|
620 |
+
hovertemplate='Time: %{x}<br>APR: %{y:.2f}<br>Agent: ' + agent_name + '<extra></extra>',
|
621 |
+
visible=True # Explicitly set visibility
|
622 |
)
|
623 |
)
|
624 |
|
625 |
# Add scatter points for Performance values
|
626 |
perf_data = agent_data[agent_data['metric_type'] == 'Performance']
|
|
|
627 |
if not perf_data.empty:
|
628 |
+
logger.info(f" Adding {len(perf_data)} Performance markers for {agent_name}")
|
629 |
+
for idx, row in perf_data.iterrows():
|
630 |
+
logger.info(f" Performance marker: timestamp={row['timestamp']}, apr={row['apr']}")
|
631 |
+
|
632 |
fig.add_trace(
|
633 |
go.Scatter(
|
634 |
x=perf_data['timestamp'],
|
635 |
y=perf_data['apr'],
|
636 |
mode='markers',
|
637 |
+
marker=dict(color=color, symbol='square', size=10),
|
638 |
name=f'{agent_name} Perf',
|
639 |
legendgroup=agent_name,
|
640 |
showlegend=False,
|
641 |
+
hovertemplate='Time: %{x}<br>Performance: %{y:.2f}<br>Agent: ' + agent_name + '<extra></extra>',
|
642 |
+
visible=True # Explicitly set visibility
|
643 |
)
|
644 |
)
|
645 |
|
|
|
663 |
hovermode="closest"
|
664 |
)
|
665 |
|
666 |
+
# Force y-axis range to include all data points with padding
|
667 |
+
y_padding = (max_apr - min_apr) * 0.1 # 10% padding
|
668 |
+
fig.update_yaxes(
|
669 |
+
showgrid=True,
|
670 |
+
gridwidth=1,
|
671 |
+
gridcolor='rgba(0,0,0,0.1)',
|
672 |
+
range=[min_apr - y_padding, max_apr + y_padding] # Force range to include all points
|
673 |
+
)
|
674 |
+
|
675 |
+
# Update x-axis
|
676 |
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='rgba(0,0,0,0.1)')
|
|
|
677 |
|
678 |
# Save the figure (still useful for reference)
|
679 |
graph_file = "modius_apr_combined_graph.html"
|
|
|
681 |
|
682 |
# Also save as image for compatibility
|
683 |
img_file = "modius_apr_combined_graph.png"
|
684 |
+
try:
|
685 |
+
fig.write_image(img_file)
|
686 |
+
logger.info(f"Combined graph saved to {graph_file} and {img_file}")
|
687 |
+
except Exception as e:
|
688 |
+
logger.error(f"Error saving image: {e}")
|
689 |
+
logger.info(f"Combined graph saved to {graph_file} only")
|
690 |
|
691 |
# Return the figure object for direct use in Gradio
|
692 |
return fig
|