Spaces:
Sleeping
Sleeping
gauravlochab
commited on
Commit
·
6f0e911
1
Parent(s):
9ca7c3a
feat: enable autoscaling for y-axis and x-axis in combined time series graph
Browse files
app.py
CHANGED
|
@@ -593,14 +593,8 @@ def create_combined_time_series_graph(df):
|
|
| 593 |
# Create Plotly figure in a clean state
|
| 594 |
fig = go.Figure()
|
| 595 |
|
| 596 |
-
#
|
| 597 |
-
|
| 598 |
-
min_apr = -40 # Bottom of the range
|
| 599 |
-
max_apr = -10 # Top of the range
|
| 600 |
-
|
| 601 |
-
logger.info(f"Using fixed y-axis range: [{min_apr}, {max_apr}]")
|
| 602 |
-
|
| 603 |
-
logger.info(f"Setting y-axis range to [{min_apr:.2f}, {max_apr:.2f}] based on filtered data")
|
| 604 |
|
| 605 |
# Add background shapes for APR and Performance regions
|
| 606 |
min_time = df['timestamp'].min()
|
|
@@ -611,7 +605,7 @@ def create_combined_time_series_graph(df):
|
|
| 611 |
type="rect",
|
| 612 |
fillcolor="rgba(230, 243, 255, 0.3)",
|
| 613 |
line=dict(width=0),
|
| 614 |
-
y0=0, y1=
|
| 615 |
x0=min_time, x1=max_time,
|
| 616 |
layer="below"
|
| 617 |
)
|
|
@@ -621,7 +615,7 @@ def create_combined_time_series_graph(df):
|
|
| 621 |
type="rect",
|
| 622 |
fillcolor="rgba(255, 230, 230, 0.3)",
|
| 623 |
line=dict(width=0),
|
| 624 |
-
y0
|
| 625 |
x0=min_time, x1=max_time,
|
| 626 |
layer="below"
|
| 627 |
)
|
|
@@ -844,46 +838,28 @@ def create_combined_time_series_graph(df):
|
|
| 844 |
# Use fixed tick spacing for clarity
|
| 845 |
dtick = 5 # 5-unit ticks for better readability
|
| 846 |
|
|
|
|
| 847 |
fig.update_yaxes(
|
| 848 |
showgrid=True,
|
| 849 |
gridwidth=1,
|
| 850 |
gridcolor='rgba(0,0,0,0.1)',
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
)
|
| 856 |
|
| 857 |
-
# Update x-axis with better formatting and
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
display_max_time = data_max_time + padding
|
| 869 |
-
|
| 870 |
-
# Update x-axis range to focus on the actual data
|
| 871 |
-
fig.update_xaxes(
|
| 872 |
-
showgrid=True,
|
| 873 |
-
gridwidth=1,
|
| 874 |
-
gridcolor='rgba(0,0,0,0.1)',
|
| 875 |
-
range=[display_min_time, display_max_time],
|
| 876 |
-
tickformat="%b %d, %H:%M", # More detailed time format
|
| 877 |
-
tickangle=-30, # Angle the labels for better readability
|
| 878 |
-
tickfont=dict(size=12) # Larger font for tick labels
|
| 879 |
-
)
|
| 880 |
-
else:
|
| 881 |
-
# Default x-axis settings if no data
|
| 882 |
-
fig.update_xaxes(
|
| 883 |
-
showgrid=True,
|
| 884 |
-
gridwidth=1,
|
| 885 |
-
gridcolor='rgba(0,0,0,0.1)'
|
| 886 |
-
)
|
| 887 |
|
| 888 |
# SIMPLIFIED APPROACH: Do a direct plot without markers for comparison
|
| 889 |
# This creates a simple, reliable fallback plot if the advanced one fails
|
|
@@ -1028,36 +1004,24 @@ def create_combined_time_series_graph(df):
|
|
| 1028 |
title="Average APR Values Across All Agents",
|
| 1029 |
xaxis_title="Time",
|
| 1030 |
yaxis_title="Value",
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
height=700, # Increased height
|
| 1038 |
width=1400, # Increased width
|
| 1039 |
template="plotly_white" # Use a cleaner template
|
| 1040 |
)
|
| 1041 |
|
| 1042 |
-
# Apply the
|
| 1043 |
-
|
| 1044 |
-
#
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
time_range = data_max_time - data_min_time
|
| 1050 |
-
padding = time_range * 0.1
|
| 1051 |
-
display_min_time = data_min_time - padding
|
| 1052 |
-
display_max_time = data_max_time + padding
|
| 1053 |
-
|
| 1054 |
-
# Update x-axis range to focus on the actual data
|
| 1055 |
-
simple_fig.update_xaxes(
|
| 1056 |
-
range=[display_min_time, display_max_time],
|
| 1057 |
-
tickformat="%b %d, %H:%M",
|
| 1058 |
-
tickangle=-30,
|
| 1059 |
-
tickfont=dict(size=12)
|
| 1060 |
-
)
|
| 1061 |
|
| 1062 |
# Add a note about hidden agents if there are more than MAX_VISIBLE_AGENTS
|
| 1063 |
if len(unique_agents) > MAX_VISIBLE_AGENTS:
|
|
|
|
| 593 |
# Create Plotly figure in a clean state
|
| 594 |
fig = go.Figure()
|
| 595 |
|
| 596 |
+
# Enable autoscaling instead of fixed ranges
|
| 597 |
+
logger.info("Using autoscaling for axes ranges")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
|
| 599 |
# Add background shapes for APR and Performance regions
|
| 600 |
min_time = df['timestamp'].min()
|
|
|
|
| 605 |
type="rect",
|
| 606 |
fillcolor="rgba(230, 243, 255, 0.3)",
|
| 607 |
line=dict(width=0),
|
| 608 |
+
y0=0, y1=100, # Use a fixed positive value
|
| 609 |
x0=min_time, x1=max_time,
|
| 610 |
layer="below"
|
| 611 |
)
|
|
|
|
| 615 |
type="rect",
|
| 616 |
fillcolor="rgba(255, 230, 230, 0.3)",
|
| 617 |
line=dict(width=0),
|
| 618 |
+
y0=-100, y1=0, # Use a fixed negative value
|
| 619 |
x0=min_time, x1=max_time,
|
| 620 |
layer="below"
|
| 621 |
)
|
|
|
|
| 838 |
# Use fixed tick spacing for clarity
|
| 839 |
dtick = 5 # 5-unit ticks for better readability
|
| 840 |
|
| 841 |
+
# Update y-axis with autoscaling and improved appearance
|
| 842 |
fig.update_yaxes(
|
| 843 |
showgrid=True,
|
| 844 |
gridwidth=1,
|
| 845 |
gridcolor='rgba(0,0,0,0.1)',
|
| 846 |
+
# No fixed range - let Plotly autoscale
|
| 847 |
+
autorange=True, # Explicitly enable autoscaling
|
| 848 |
+
tickformat=".2f", # Format tick labels with 2 decimal places
|
| 849 |
+
tickfont=dict(size=12) # Larger font for tick labels
|
| 850 |
)
|
| 851 |
|
| 852 |
+
# Update x-axis with better formatting and autoscaling
|
| 853 |
+
fig.update_xaxes(
|
| 854 |
+
showgrid=True,
|
| 855 |
+
gridwidth=1,
|
| 856 |
+
gridcolor='rgba(0,0,0,0.1)',
|
| 857 |
+
# No fixed range - let Plotly autoscale
|
| 858 |
+
autorange=True, # Explicitly enable autoscaling
|
| 859 |
+
tickformat="%b %d, %H:%M", # More detailed time format
|
| 860 |
+
tickangle=-30, # Angle the labels for better readability
|
| 861 |
+
tickfont=dict(size=12) # Larger font for tick labels
|
| 862 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 863 |
|
| 864 |
# SIMPLIFIED APPROACH: Do a direct plot without markers for comparison
|
| 865 |
# This creates a simple, reliable fallback plot if the advanced one fails
|
|
|
|
| 1004 |
title="Average APR Values Across All Agents",
|
| 1005 |
xaxis_title="Time",
|
| 1006 |
yaxis_title="Value",
|
| 1007 |
+
yaxis=dict(
|
| 1008 |
+
# No fixed range - let Plotly autoscale
|
| 1009 |
+
autorange=True, # Explicitly enable autoscaling
|
| 1010 |
+
tickformat=".2f", # Format tick labels with 2 decimal places
|
| 1011 |
+
tickfont=dict(size=12) # Larger font for tick labels
|
| 1012 |
+
),
|
| 1013 |
height=700, # Increased height
|
| 1014 |
width=1400, # Increased width
|
| 1015 |
template="plotly_white" # Use a cleaner template
|
| 1016 |
)
|
| 1017 |
|
| 1018 |
+
# Apply autoscaling to the x-axis for the fallback graph
|
| 1019 |
+
simple_fig.update_xaxes(
|
| 1020 |
+
autorange=True, # Explicitly enable autoscaling
|
| 1021 |
+
tickformat="%b %d, %H:%M",
|
| 1022 |
+
tickangle=-30,
|
| 1023 |
+
tickfont=dict(size=12)
|
| 1024 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1025 |
|
| 1026 |
# Add a note about hidden agents if there are more than MAX_VISIBLE_AGENTS
|
| 1027 |
if len(unique_agents) > MAX_VISIBLE_AGENTS:
|