gauravlochab commited on
Commit
0d99588
·
1 Parent(s): fdcd7fd

feat: update active agent count logic

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -1593,9 +1593,21 @@ def create_combined_time_series_graph(df):
1593
  formatted_timestamp = timestamp.strftime('%Y-%m-%d %H:%M:%S')
1594
 
1595
  # Calculate number of active agents in the last 24 hours
 
1596
  time_24h_ago = timestamp - pd.Timedelta(hours=24)
1597
- active_agents = len(apr_data[(apr_data['timestamp'] >= time_24h_ago) &
1598
- (apr_data['timestamp'] <= timestamp)]['agent_id'].unique())
 
 
 
 
 
 
 
 
 
 
 
1599
 
1600
  hover_data_apr.append(
1601
  f"Time: {formatted_timestamp}<br>Avg APR (3d window): {row['moving_avg']:.2f}<br>Active agents (24h): {active_agents}"
@@ -1634,9 +1646,21 @@ def create_combined_time_series_graph(df):
1634
  formatted_timestamp = timestamp.strftime('%Y-%m-%d %H:%M:%S')
1635
 
1636
  # Calculate number of active agents in the last 24 hours
 
1637
  time_24h_ago = timestamp - pd.Timedelta(hours=24)
1638
- active_agents = len(apr_data[(apr_data['timestamp'] >= time_24h_ago) &
1639
- (apr_data['timestamp'] <= timestamp)]['agent_id'].unique())
 
 
 
 
 
 
 
 
 
 
 
1640
 
1641
  if pd.notna(row['adjusted_moving_avg']):
1642
  hover_data_adj.append(
 
1593
  formatted_timestamp = timestamp.strftime('%Y-%m-%d %H:%M:%S')
1594
 
1595
  # Calculate number of active agents in the last 24 hours
1596
+ # Use ROI data after April 25th, 2025, and APR data before that date
1597
  time_24h_ago = timestamp - pd.Timedelta(hours=24)
1598
+ april_25_2025 = datetime(2025, 4, 25)
1599
+
1600
+ if timestamp >= april_25_2025 and global_roi_df is not None and not global_roi_df.empty:
1601
+ # After April 25th, 2025: Use ROI data
1602
+ roi_window_data = global_roi_df[(global_roi_df['timestamp'] >= time_24h_ago) &
1603
+ (global_roi_df['timestamp'] <= timestamp)]
1604
+ active_agents = len(roi_window_data['agent_id'].unique())
1605
+ logger.debug(f"Using ROI data for active agent count at {timestamp} (after Apr 25): {active_agents} agents")
1606
+ else:
1607
+ # Before April 25th, 2025 or if ROI data is not available: Use APR data
1608
+ active_agents = len(apr_data[(apr_data['timestamp'] >= time_24h_ago) &
1609
+ (apr_data['timestamp'] <= timestamp)]['agent_id'].unique())
1610
+ logger.debug(f"Using APR data for active agent count at {timestamp} (before Apr 25): {active_agents} agents")
1611
 
1612
  hover_data_apr.append(
1613
  f"Time: {formatted_timestamp}<br>Avg APR (3d window): {row['moving_avg']:.2f}<br>Active agents (24h): {active_agents}"
 
1646
  formatted_timestamp = timestamp.strftime('%Y-%m-%d %H:%M:%S')
1647
 
1648
  # Calculate number of active agents in the last 24 hours
1649
+ # Use ROI data after April 25th, 2025, and APR data before that date
1650
  time_24h_ago = timestamp - pd.Timedelta(hours=24)
1651
+ april_25_2025 = datetime(2025, 4, 25)
1652
+
1653
+ if timestamp >= april_25_2025 and global_roi_df is not None and not global_roi_df.empty:
1654
+ # After April 25th, 2025: Use ROI data
1655
+ roi_window_data = global_roi_df[(global_roi_df['timestamp'] >= time_24h_ago) &
1656
+ (global_roi_df['timestamp'] <= timestamp)]
1657
+ active_agents = len(roi_window_data['agent_id'].unique())
1658
+ logger.debug(f"Using ROI data for adjusted APR active agent count at {timestamp} (after Apr 25)")
1659
+ else:
1660
+ # Before April 25th, 2025 or if ROI data is not available: Use APR data
1661
+ active_agents = len(apr_data[(apr_data['timestamp'] >= time_24h_ago) &
1662
+ (apr_data['timestamp'] <= timestamp)]['agent_id'].unique())
1663
+ logger.debug(f"Using APR data for adjusted APR active agent count at {timestamp} (before Apr 25)")
1664
 
1665
  if pd.notna(row['adjusted_moving_avg']):
1666
  hover_data_adj.append(