Spaces:
Running
Running
gauravlochab
commited on
Commit
·
7ac1cac
1
Parent(s):
6f0e911
refactor: update logging configuration for reduced verbosity and improved outlier handling
Browse files
app.py
CHANGED
@@ -19,9 +19,9 @@ from typing import List, Dict, Any
|
|
19 |
# from app_trans_new import create_transcation_visualizations,create_active_agents_visualizations
|
20 |
# APR visualization functions integrated directly
|
21 |
|
22 |
-
# Set up
|
23 |
logging.basicConfig(
|
24 |
-
level=logging.
|
25 |
format="%(asctime)s - %(levelname)s - %(message)s",
|
26 |
handlers=[
|
27 |
logging.FileHandler("app_debug.log"), # Log to file for persistence
|
@@ -30,6 +30,11 @@ logging.basicConfig(
|
|
30 |
)
|
31 |
logger = logging.getLogger(__name__)
|
32 |
|
|
|
|
|
|
|
|
|
|
|
33 |
# Log the startup information
|
34 |
logger.info("============= APPLICATION STARTING =============")
|
35 |
logger.info(f"Running from directory: {os.getcwd()}")
|
@@ -471,63 +476,10 @@ def create_time_series_graph_per_agent(df):
|
|
471 |
return fig
|
472 |
|
473 |
def write_debug_info(df, fig):
|
474 |
-
"""
|
475 |
try:
|
476 |
-
|
477 |
-
logger.
|
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}")
|
@@ -629,17 +581,24 @@ def create_combined_time_series_graph(df):
|
|
629 |
)
|
630 |
|
631 |
# MODIFIED: Calculate average APR values across all agents for each timestamp
|
632 |
-
# Filter for APR data only
|
633 |
apr_data = df[df['metric_type'] == 'APR'].copy()
|
634 |
|
635 |
-
# Filter out
|
636 |
-
|
637 |
-
apr_data_filtered = apr_data[apr_data['
|
638 |
|
639 |
-
# Log the
|
640 |
-
if len(
|
641 |
-
excluded_count = len(
|
642 |
-
logger.info(f"Excluded {excluded_count} data points
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
643 |
|
644 |
# Use the filtered data for all subsequent operations
|
645 |
apr_data = apr_data_filtered
|
@@ -806,7 +765,7 @@ def create_combined_time_series_graph(df):
|
|
806 |
# Update layout - use simple boolean values everywhere
|
807 |
# Increase the width and height for better visualization
|
808 |
fig.update_layout(
|
809 |
-
title="
|
810 |
xaxis_title="Time",
|
811 |
yaxis_title="Value",
|
812 |
template="plotly_white",
|
@@ -1001,7 +960,7 @@ def create_combined_time_series_graph(df):
|
|
1001 |
|
1002 |
# Simplified layout with adjusted y-axis range and increased size
|
1003 |
simple_fig.update_layout(
|
1004 |
-
title="
|
1005 |
xaxis_title="Time",
|
1006 |
yaxis_title="Value",
|
1007 |
yaxis=dict(
|
|
|
19 |
# from app_trans_new import create_transcation_visualizations,create_active_agents_visualizations
|
20 |
# APR visualization functions integrated directly
|
21 |
|
22 |
+
# Set up logging with appropriate verbosity
|
23 |
logging.basicConfig(
|
24 |
+
level=logging.INFO, # Use INFO level instead of DEBUG to reduce verbosity
|
25 |
format="%(asctime)s - %(levelname)s - %(message)s",
|
26 |
handlers=[
|
27 |
logging.FileHandler("app_debug.log"), # Log to file for persistence
|
|
|
30 |
)
|
31 |
logger = logging.getLogger(__name__)
|
32 |
|
33 |
+
# Reduce third-party library logging
|
34 |
+
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
35 |
+
logging.getLogger("httpx").setLevel(logging.WARNING)
|
36 |
+
logging.getLogger("matplotlib").setLevel(logging.WARNING)
|
37 |
+
|
38 |
# Log the startup information
|
39 |
logger.info("============= APPLICATION STARTING =============")
|
40 |
logger.info(f"Running from directory: {os.getcwd()}")
|
|
|
476 |
return fig
|
477 |
|
478 |
def write_debug_info(df, fig):
|
479 |
+
"""Minimal debug info function"""
|
480 |
try:
|
481 |
+
# Just log minimal information
|
482 |
+
logger.debug(f"Graph created with {len(df)} data points and {len(fig.data)} traces")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
483 |
return True
|
484 |
except Exception as e:
|
485 |
logger.error(f"Error writing debug info: {e}")
|
|
|
581 |
)
|
582 |
|
583 |
# MODIFIED: Calculate average APR values across all agents for each timestamp
|
584 |
+
# Filter for APR data only
|
585 |
apr_data = df[df['metric_type'] == 'APR'].copy()
|
586 |
|
587 |
+
# Filter out outliers (APR values above 200 or below -200)
|
588 |
+
outlier_data = apr_data[(apr_data['apr'] > 200) | (apr_data['apr'] < -200)].copy()
|
589 |
+
apr_data_filtered = apr_data[(apr_data['apr'] <= 200) & (apr_data['apr'] >= -200)].copy()
|
590 |
|
591 |
+
# Log the outliers for better debugging
|
592 |
+
if len(outlier_data) > 0:
|
593 |
+
excluded_count = len(outlier_data)
|
594 |
+
logger.info(f"Excluded {excluded_count} data points with outlier APR values (>200 or <-200)")
|
595 |
+
|
596 |
+
# Group outliers by agent for detailed logging
|
597 |
+
outlier_agents = outlier_data.groupby('agent_name')
|
598 |
+
for agent_name, agent_outliers in outlier_agents:
|
599 |
+
logger.info(f"Agent '{agent_name}' has {len(agent_outliers)} outlier values:")
|
600 |
+
for idx, row in agent_outliers.iterrows():
|
601 |
+
logger.info(f" - APR: {row['apr']}, timestamp: {row['timestamp']}")
|
602 |
|
603 |
# Use the filtered data for all subsequent operations
|
604 |
apr_data = apr_data_filtered
|
|
|
765 |
# Update layout - use simple boolean values everywhere
|
766 |
# Increase the width and height for better visualization
|
767 |
fig.update_layout(
|
768 |
+
title="Babydegen agents",
|
769 |
xaxis_title="Time",
|
770 |
yaxis_title="Value",
|
771 |
template="plotly_white",
|
|
|
960 |
|
961 |
# Simplified layout with adjusted y-axis range and increased size
|
962 |
simple_fig.update_layout(
|
963 |
+
title="Babydegen agents",
|
964 |
xaxis_title="Time",
|
965 |
yaxis_title="Value",
|
966 |
yaxis=dict(
|