gauravlochab commited on
Commit
5591735
·
1 Parent(s): 6d5ec43

feat: add initial data files and API test scripts for agent statistics and APR analysis

Browse files
Files changed (1) hide show
  1. app.py +34 -4
app.py CHANGED
@@ -867,6 +867,15 @@ def create_combined_roi_time_series_graph(df):
867
 
868
  logger.info(f"Calculated time-based moving averages with {len(avg_roi_data_with_ma)} points")
869
 
 
 
 
 
 
 
 
 
 
870
  # Plot individual agent data points with agent names in hover, but limit display for scalability
871
  if not df.empty:
872
  # Group by agent to use different colors for each agent
@@ -1018,9 +1027,9 @@ def create_combined_roi_time_series_graph(df):
1018
  showgrid=True,
1019
  gridwidth=1,
1020
  gridcolor='rgba(0,0,0,0.1)',
1021
- # Set fixed range with April 17 as start date
1022
  autorange=False, # Disable autoscaling
1023
- range=[x_start_date, max_time], # Set fixed range from April 17 to max date
1024
  tickformat="%b %d", # Simplified date format without time
1025
  tickangle=-30, # Angle the labels for better readability
1026
  tickfont=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size
@@ -1472,6 +1481,27 @@ def create_combined_time_series_graph(df):
1472
 
1473
  logger.info(f"Calculated time-based moving averages with {len(avg_apr_data_with_ma)} points")
1474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1475
  # Plot individual agent data points with agent names in hover, but limit display for scalability
1476
  if not apr_data.empty:
1477
  # Group by agent to use different colors for each agent
@@ -1715,9 +1745,9 @@ def create_combined_time_series_graph(df):
1715
  showgrid=True,
1716
  gridwidth=1,
1717
  gridcolor='rgba(0,0,0,0.1)',
1718
- # Set fixed range with April 17 as start date
1719
  autorange=False, # Disable autoscaling
1720
- range=[x_start_date, max_time], # Set fixed range from April 17 to max date
1721
  tickformat="%b %d", # Simplified date format without time
1722
  tickangle=-30, # Angle the labels for better readability
1723
  tickfont=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size
 
867
 
868
  logger.info(f"Calculated time-based moving averages with {len(avg_roi_data_with_ma)} points")
869
 
870
+ # Find the last date where we have valid moving average data
871
+ last_valid_ma_date = avg_roi_data_with_ma[avg_roi_data_with_ma['moving_avg'].notna()]['timestamp'].max() if not avg_roi_data_with_ma['moving_avg'].dropna().empty else None
872
+
873
+ # If we don't have any valid moving average data, use the max time from the original data
874
+ last_valid_date = last_valid_ma_date if last_valid_ma_date is not None else df['timestamp'].max()
875
+
876
+ logger.info(f"Last valid moving average date: {last_valid_ma_date}")
877
+ logger.info(f"Using last valid date for graph: {last_valid_date}")
878
+
879
  # Plot individual agent data points with agent names in hover, but limit display for scalability
880
  if not df.empty:
881
  # Group by agent to use different colors for each agent
 
1027
  showgrid=True,
1028
  gridwidth=1,
1029
  gridcolor='rgba(0,0,0,0.1)',
1030
+ # Set fixed range with start date and ending at the last valid date
1031
  autorange=False, # Disable autoscaling
1032
+ range=[x_start_date, last_valid_date], # Set fixed range from start date to last valid date
1033
  tickformat="%b %d", # Simplified date format without time
1034
  tickangle=-30, # Angle the labels for better readability
1035
  tickfont=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size
 
1481
 
1482
  logger.info(f"Calculated time-based moving averages with {len(avg_apr_data_with_ma)} points")
1483
 
1484
+ # Find the last date where we have valid moving average data
1485
+ last_valid_ma_date = avg_apr_data_with_ma[avg_apr_data_with_ma['moving_avg'].notna()]['timestamp'].max() if not avg_apr_data_with_ma['moving_avg'].dropna().empty else None
1486
+
1487
+ # Find the last date where we have valid adjusted moving average data
1488
+ last_valid_adj_ma_date = None
1489
+ if 'adjusted_moving_avg' in avg_apr_data_with_ma.columns and avg_apr_data_with_ma['adjusted_moving_avg'].notna().any():
1490
+ last_valid_adj_ma_date = avg_apr_data_with_ma[avg_apr_data_with_ma['adjusted_moving_avg'].notna()]['timestamp'].max()
1491
+
1492
+ # Determine the last valid date for either moving average
1493
+ last_valid_date = last_valid_ma_date
1494
+ if last_valid_adj_ma_date is not None:
1495
+ last_valid_date = max(last_valid_date, last_valid_adj_ma_date) if last_valid_date is not None else last_valid_adj_ma_date
1496
+
1497
+ # If we don't have any valid moving average data, use the max time from the original data
1498
+ if last_valid_date is None:
1499
+ last_valid_date = df['timestamp'].max()
1500
+
1501
+ logger.info(f"Last valid moving average date: {last_valid_ma_date}")
1502
+ logger.info(f"Last valid adjusted moving average date: {last_valid_adj_ma_date}")
1503
+ logger.info(f"Using last valid date for graph: {last_valid_date}")
1504
+
1505
  # Plot individual agent data points with agent names in hover, but limit display for scalability
1506
  if not apr_data.empty:
1507
  # Group by agent to use different colors for each agent
 
1745
  showgrid=True,
1746
  gridwidth=1,
1747
  gridcolor='rgba(0,0,0,0.1)',
1748
+ # Set fixed range with April 17 as start date and ending at the last valid date
1749
  autorange=False, # Disable autoscaling
1750
+ range=[x_start_date, last_valid_date], # Set fixed range from April 17 to last valid date
1751
  tickformat="%b %d", # Simplified date format without time
1752
  tickangle=-30, # Angle the labels for better readability
1753
  tickfont=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size