Spaces:
Running
Running
gauravlochab
commited on
Commit
·
ba83473
1
Parent(s):
28c8cbd
feat: add markers for all agents and toggle for top agents
Browse files
app.py
CHANGED
|
@@ -713,8 +713,35 @@ def create_combined_time_series_graph(df):
|
|
| 713 |
|
| 714 |
logger.info(f"Showing {len(top_agents)} agents by default out of {len(unique_agents)} total agents")
|
| 715 |
|
| 716 |
-
#
|
| 717 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
|
| 719 |
# Add 2-hour moving average as a smooth line
|
| 720 |
x_values_ma = avg_apr_data_with_ma['timestamp'].tolist()
|
|
@@ -785,7 +812,16 @@ def create_combined_time_series_graph(df):
|
|
| 785 |
hovermode="closest"
|
| 786 |
)
|
| 787 |
|
| 788 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
|
| 790 |
# FORCE FIXED Y-AXIS RANGE
|
| 791 |
fig.update_yaxes(
|
|
@@ -887,8 +923,39 @@ def create_combined_time_series_graph(df):
|
|
| 887 |
else:
|
| 888 |
avg_apr_data_with_ma.at[i, 'infinite_avg'] = row['apr']
|
| 889 |
|
| 890 |
-
#
|
| 891 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 892 |
|
| 893 |
# Add 2-hour moving average as a line
|
| 894 |
simple_fig.add_trace(
|
|
@@ -922,7 +989,16 @@ def create_combined_time_series_graph(df):
|
|
| 922 |
width=1000
|
| 923 |
)
|
| 924 |
|
| 925 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 926 |
|
| 927 |
# Return the simple figure
|
| 928 |
return simple_fig
|
|
|
|
| 713 |
|
| 714 |
logger.info(f"Showing {len(top_agents)} agents by default out of {len(unique_agents)} total agents")
|
| 715 |
|
| 716 |
+
# Add data points for each agent, but only make top agents visible by default
|
| 717 |
+
for agent_name in unique_agents:
|
| 718 |
+
agent_data = apr_data[apr_data['agent_name'] == agent_name]
|
| 719 |
+
|
| 720 |
+
# Explicitly convert to Python lists
|
| 721 |
+
x_values = agent_data['timestamp'].tolist()
|
| 722 |
+
y_values = agent_data['apr'].tolist()
|
| 723 |
+
|
| 724 |
+
# Determine if this agent should be visible by default
|
| 725 |
+
is_visible = agent_name in top_agents
|
| 726 |
+
|
| 727 |
+
# Add data points as markers
|
| 728 |
+
fig.add_trace(
|
| 729 |
+
go.Scatter(
|
| 730 |
+
x=x_values,
|
| 731 |
+
y=y_values,
|
| 732 |
+
mode='markers', # Only markers for original data
|
| 733 |
+
marker=dict(
|
| 734 |
+
color=color_map[agent_name],
|
| 735 |
+
symbol='circle',
|
| 736 |
+
size=10,
|
| 737 |
+
line=dict(width=1, color='black')
|
| 738 |
+
),
|
| 739 |
+
name=f'Agent: {agent_name}',
|
| 740 |
+
hovertemplate='Time: %{x}<br>APR: %{y:.2f}<br>Agent: ' + agent_name + '<extra></extra>',
|
| 741 |
+
visible=is_visible # Only top agents visible by default
|
| 742 |
+
)
|
| 743 |
+
)
|
| 744 |
+
logger.info(f"Added data points for agent {agent_name} with {len(x_values)} points (visible: {is_visible})")
|
| 745 |
|
| 746 |
# Add 2-hour moving average as a smooth line
|
| 747 |
x_values_ma = avg_apr_data_with_ma['timestamp'].tolist()
|
|
|
|
| 812 |
hovermode="closest"
|
| 813 |
)
|
| 814 |
|
| 815 |
+
# Add a note about hidden agents if there are more than MAX_VISIBLE_AGENTS
|
| 816 |
+
if len(unique_agents) > MAX_VISIBLE_AGENTS:
|
| 817 |
+
fig.add_annotation(
|
| 818 |
+
text=f"Note: Only showing top {MAX_VISIBLE_AGENTS} agents by default. Toggle others in legend.",
|
| 819 |
+
xref="paper", yref="paper",
|
| 820 |
+
x=0.5, y=1.05,
|
| 821 |
+
showarrow=False,
|
| 822 |
+
font=dict(size=12, color="gray"),
|
| 823 |
+
align="center"
|
| 824 |
+
)
|
| 825 |
|
| 826 |
# FORCE FIXED Y-AXIS RANGE
|
| 827 |
fig.update_yaxes(
|
|
|
|
| 923 |
else:
|
| 924 |
avg_apr_data_with_ma.at[i, 'infinite_avg'] = row['apr']
|
| 925 |
|
| 926 |
+
# Add data points for each agent, but only make top agents visible by default
|
| 927 |
+
unique_agents = apr_data['agent_name'].unique()
|
| 928 |
+
colors = px.colors.qualitative.Plotly[:len(unique_agents)]
|
| 929 |
+
color_map = {agent: colors[i % len(colors)] for i, agent in enumerate(unique_agents)}
|
| 930 |
+
|
| 931 |
+
# Calculate the total number of data points per agent
|
| 932 |
+
agent_counts = apr_data['agent_name'].value_counts()
|
| 933 |
+
|
| 934 |
+
# Determine how many agents to show individually (limit to top 5 most active)
|
| 935 |
+
MAX_VISIBLE_AGENTS = 5
|
| 936 |
+
top_agents = agent_counts.nlargest(min(MAX_VISIBLE_AGENTS, len(agent_counts))).index.tolist()
|
| 937 |
+
|
| 938 |
+
for agent_name in unique_agents:
|
| 939 |
+
agent_data = apr_data[apr_data['agent_name'] == agent_name]
|
| 940 |
+
|
| 941 |
+
# Determine if this agent should be visible by default
|
| 942 |
+
is_visible = agent_name in top_agents
|
| 943 |
+
|
| 944 |
+
# Add data points as markers
|
| 945 |
+
simple_fig.add_trace(
|
| 946 |
+
go.Scatter(
|
| 947 |
+
x=agent_data['timestamp'],
|
| 948 |
+
y=agent_data['apr'],
|
| 949 |
+
mode='markers',
|
| 950 |
+
name=f'Agent: {agent_name}',
|
| 951 |
+
marker=dict(
|
| 952 |
+
size=10,
|
| 953 |
+
color=color_map[agent_name]
|
| 954 |
+
),
|
| 955 |
+
hovertemplate='Time: %{x}<br>APR: %{y:.2f}<br>Agent: ' + agent_name + '<extra></extra>',
|
| 956 |
+
visible=is_visible # Only top agents visible by default
|
| 957 |
+
)
|
| 958 |
+
)
|
| 959 |
|
| 960 |
# Add 2-hour moving average as a line
|
| 961 |
simple_fig.add_trace(
|
|
|
|
| 989 |
width=1000
|
| 990 |
)
|
| 991 |
|
| 992 |
+
# Add a note about hidden agents if there are more than MAX_VISIBLE_AGENTS
|
| 993 |
+
if len(unique_agents) > MAX_VISIBLE_AGENTS:
|
| 994 |
+
simple_fig.add_annotation(
|
| 995 |
+
text=f"Note: Only showing top {MAX_VISIBLE_AGENTS} agents by default. Toggle others in legend.",
|
| 996 |
+
xref="paper", yref="paper",
|
| 997 |
+
x=0.5, y=1.05,
|
| 998 |
+
showarrow=False,
|
| 999 |
+
font=dict(size=12, color="gray"),
|
| 1000 |
+
align="center"
|
| 1001 |
+
)
|
| 1002 |
|
| 1003 |
# Return the simple figure
|
| 1004 |
return simple_fig
|