Spaces:
Sleeping
Sleeping
gauravlochab
commited on
Commit
·
c009a22
1
Parent(s):
f1dade8
feat: add detailed debug logging for time series graph creation and simplify APR data plotting
Browse files
app.py
CHANGED
|
@@ -470,6 +470,69 @@ def create_time_series_graph_per_agent(df):
|
|
| 470 |
# Return the figure object for direct use in Gradio
|
| 471 |
return fig
|
| 472 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
def create_combined_time_series_graph(df):
|
| 474 |
"""Create a combined time series graph for all agents using Plotly"""
|
| 475 |
if len(df) == 0:
|
|
@@ -585,51 +648,42 @@ def create_combined_time_series_graph(df):
|
|
| 585 |
for idx, row in agent_data.iterrows():
|
| 586 |
logger.info(f" Point {idx}: timestamp={row['timestamp']}, apr={row['apr']}, type={row['metric_type']}")
|
| 587 |
|
| 588 |
-
#
|
| 589 |
apr_data = agent_data[agent_data['metric_type'] == 'APR']
|
| 590 |
-
if not apr_data.empty:
|
| 591 |
-
logger.info(f" Adding {len(apr_data)} APR markers for {agent_name}")
|
| 592 |
-
for idx, row in apr_data.iterrows():
|
| 593 |
-
logger.info(f" APR marker: timestamp={row['timestamp']}, apr={row['apr']}")
|
| 594 |
-
|
| 595 |
-
# Use explicit Python boolean for showlegend
|
| 596 |
-
is_first_point = bool(idx == apr_data.index[0])
|
| 597 |
-
fig.add_trace(
|
| 598 |
-
go.Scatter(
|
| 599 |
-
x=[row['timestamp']],
|
| 600 |
-
y=[row['apr']],
|
| 601 |
-
mode='markers',
|
| 602 |
-
marker=dict(
|
| 603 |
-
color='blue', # Force consistent color
|
| 604 |
-
symbol='circle',
|
| 605 |
-
size=14, # Make markers larger
|
| 606 |
-
line=dict(
|
| 607 |
-
width=2,
|
| 608 |
-
color='black'
|
| 609 |
-
)
|
| 610 |
-
),
|
| 611 |
-
name=f'{agent_name} APR',
|
| 612 |
-
legendgroup=agent_name,
|
| 613 |
-
showlegend=is_first_point, # Use native Python boolean
|
| 614 |
-
hovertemplate='Time: %{x}<br>APR: %{y:.2f}<br>Agent: ' + agent_name + '<extra></extra>'
|
| 615 |
-
)
|
| 616 |
-
)
|
| 617 |
|
| 618 |
-
#
|
| 619 |
-
#
|
| 620 |
if not apr_data.empty:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
fig.add_trace(
|
| 622 |
go.Scatter(
|
| 623 |
-
x=
|
| 624 |
-
y=
|
| 625 |
-
mode='lines',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 626 |
line=dict(color='blue', width=2),
|
| 627 |
-
name=
|
| 628 |
legendgroup=agent_name,
|
| 629 |
-
showlegend=
|
| 630 |
-
hovertemplate='Time: %{x}<br>
|
| 631 |
)
|
| 632 |
)
|
|
|
|
| 633 |
|
| 634 |
# Update layout - use simple boolean values everywhere
|
| 635 |
fig.update_layout(
|
|
@@ -672,6 +726,9 @@ def create_combined_time_series_graph(df):
|
|
| 672 |
# SIMPLIFIED APPROACH: Do a direct plot without markers for comparison
|
| 673 |
# This creates a simple, reliable fallback plot if the advanced one fails
|
| 674 |
try:
|
|
|
|
|
|
|
|
|
|
| 675 |
# Save the figure (still useful for reference)
|
| 676 |
graph_file = "modius_apr_combined_graph.html"
|
| 677 |
fig.write_html(graph_file, include_plotlyjs='cdn', full_html=False)
|
|
|
|
| 470 |
# Return the figure object for direct use in Gradio
|
| 471 |
return fig
|
| 472 |
|
| 473 |
+
def write_debug_info(df, fig):
|
| 474 |
+
"""Write detailed debug information to logs for troubleshooting"""
|
| 475 |
+
try:
|
| 476 |
+
logger.info("==== GRAPH DEBUG INFORMATION ====")
|
| 477 |
+
logger.info(f"Total data points: {len(df)}")
|
| 478 |
+
logger.info(f"DataFrame columns: {df.columns.tolist()}")
|
| 479 |
+
|
| 480 |
+
logger.info("Data types:")
|
| 481 |
+
for col in df.columns:
|
| 482 |
+
logger.info(f" {col}: {df[col].dtype}")
|
| 483 |
+
|
| 484 |
+
# Output sample data points
|
| 485 |
+
logger.info("Sample data (up to 5 rows):")
|
| 486 |
+
sample_df = df.head(5)
|
| 487 |
+
for idx, row in sample_df.iterrows():
|
| 488 |
+
logger.info(f" Row {idx}: {row.to_dict()}")
|
| 489 |
+
|
| 490 |
+
# Output Plotly figure structure
|
| 491 |
+
logger.info("Plotly Figure Structure:")
|
| 492 |
+
logger.info(f" Number of traces: {len(fig.data)}")
|
| 493 |
+
for i, trace in enumerate(fig.data):
|
| 494 |
+
logger.info(f" Trace {i}:")
|
| 495 |
+
logger.info(f" Type: {trace.type}")
|
| 496 |
+
logger.info(f" Mode: {trace.mode if hasattr(trace, 'mode') else 'N/A'}")
|
| 497 |
+
logger.info(f" Name: {trace.name}")
|
| 498 |
+
|
| 499 |
+
# Only log first few values to avoid overwhelming logs
|
| 500 |
+
if hasattr(trace, 'x') and trace.x is not None and len(trace.x) > 0:
|
| 501 |
+
x_sample = str(trace.x[:2])
|
| 502 |
+
logger.info(f" X data sample (first 2): {x_sample}")
|
| 503 |
+
|
| 504 |
+
if hasattr(trace, 'y') and trace.y is not None and len(trace.y) > 0:
|
| 505 |
+
y_sample = str(trace.y[:2])
|
| 506 |
+
logger.info(f" Y data sample (first 2): {y_sample}")
|
| 507 |
+
|
| 508 |
+
if hasattr(trace, 'line') and hasattr(trace.line, 'color'):
|
| 509 |
+
logger.info(f" Line color: {trace.line.color}")
|
| 510 |
+
|
| 511 |
+
if hasattr(trace, 'line') and hasattr(trace.line, 'width'):
|
| 512 |
+
logger.info(f" Line width: {trace.line.width}")
|
| 513 |
+
|
| 514 |
+
# Check environment
|
| 515 |
+
import os
|
| 516 |
+
import sys
|
| 517 |
+
import platform
|
| 518 |
+
|
| 519 |
+
logger.info("Environment Information:")
|
| 520 |
+
logger.info(f" Platform: {platform.platform()}")
|
| 521 |
+
logger.info(f" Python version: {sys.version}")
|
| 522 |
+
logger.info(f" Running in Docker: {'DOCKER_CONTAINER' in os.environ}")
|
| 523 |
+
logger.info(f" Running in HF Space: {'SPACE_ID' in os.environ}")
|
| 524 |
+
|
| 525 |
+
# Plotly version
|
| 526 |
+
import plotly
|
| 527 |
+
logger.info(f" Plotly version: {plotly.__version__}")
|
| 528 |
+
|
| 529 |
+
logger.info("End of debug info")
|
| 530 |
+
|
| 531 |
+
return True
|
| 532 |
+
except Exception as e:
|
| 533 |
+
logger.error(f"Error writing debug info: {e}")
|
| 534 |
+
return False
|
| 535 |
+
|
| 536 |
def create_combined_time_series_graph(df):
|
| 537 |
"""Create a combined time series graph for all agents using Plotly"""
|
| 538 |
if len(df) == 0:
|
|
|
|
| 648 |
for idx, row in agent_data.iterrows():
|
| 649 |
logger.info(f" Point {idx}: timestamp={row['timestamp']}, apr={row['apr']}, type={row['metric_type']}")
|
| 650 |
|
| 651 |
+
# Get the APR data - this is what we'll plot
|
| 652 |
apr_data = agent_data[agent_data['metric_type'] == 'APR']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 653 |
|
| 654 |
+
# SIMPLIFIED APPROACH: Use a single trace with lines+markers mode
|
| 655 |
+
# This is much more reliable across different platforms
|
| 656 |
if not apr_data.empty:
|
| 657 |
+
logger.info(f" Adding combined line+markers for {agent_name}")
|
| 658 |
+
|
| 659 |
+
# Explicitly convert to Python lists
|
| 660 |
+
x_values = apr_data['timestamp'].tolist()
|
| 661 |
+
y_values = apr_data['apr'].tolist()
|
| 662 |
+
|
| 663 |
+
# Log what we're about to plot
|
| 664 |
+
for i, (x, y) in enumerate(zip(x_values, y_values)):
|
| 665 |
+
logger.info(f" Point {i+1}: x={x}, y={y}")
|
| 666 |
+
|
| 667 |
+
# Use a single trace for both markers and lines
|
| 668 |
fig.add_trace(
|
| 669 |
go.Scatter(
|
| 670 |
+
x=x_values,
|
| 671 |
+
y=y_values,
|
| 672 |
+
mode='lines+markers', # Important: use both lines and markers
|
| 673 |
+
marker=dict(
|
| 674 |
+
color='blue',
|
| 675 |
+
symbol='circle',
|
| 676 |
+
size=12,
|
| 677 |
+
line=dict(width=2, color='black')
|
| 678 |
+
),
|
| 679 |
line=dict(color='blue', width=2),
|
| 680 |
+
name=agent_name,
|
| 681 |
legendgroup=agent_name,
|
| 682 |
+
showlegend=True,
|
| 683 |
+
hovertemplate='Time: %{x}<br>APR: %{y:.2f}<br>Agent: ' + agent_name + '<extra></extra>'
|
| 684 |
)
|
| 685 |
)
|
| 686 |
+
logger.info(f" Added combined line+markers trace for {agent_name}")
|
| 687 |
|
| 688 |
# Update layout - use simple boolean values everywhere
|
| 689 |
fig.update_layout(
|
|
|
|
| 726 |
# SIMPLIFIED APPROACH: Do a direct plot without markers for comparison
|
| 727 |
# This creates a simple, reliable fallback plot if the advanced one fails
|
| 728 |
try:
|
| 729 |
+
# Write detailed debug information before saving the figure
|
| 730 |
+
write_debug_info(df, fig)
|
| 731 |
+
|
| 732 |
# Save the figure (still useful for reference)
|
| 733 |
graph_file = "modius_apr_combined_graph.html"
|
| 734 |
fig.write_html(graph_file, include_plotlyjs='cdn', full_html=False)
|