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

feat: convert ROI values to percentages and update related annotations and ranges

Browse files
Files changed (1) hide show
  1. app.py +18 -27
app.py CHANGED
@@ -746,6 +746,8 @@ def create_combined_roi_time_series_graph(df):
746
 
747
  # IMPORTANT: Force data types to ensure consistency
748
  df['roi'] = df['roi'].astype(float) # Ensure ROI is float
 
 
749
  df['metric_type'] = df['metric_type'].astype(str) # Ensure metric_type is string
750
 
751
  # Get min and max time for shapes
@@ -778,7 +780,7 @@ def create_combined_roi_time_series_graph(df):
778
  type="rect",
779
  fillcolor="rgba(230, 243, 255, 0.3)",
780
  line=dict(width=0),
781
- y0=0, y1=1, # Use a fixed positive value
782
  x0=min_time, x1=max_time,
783
  layer="below"
784
  )
@@ -788,7 +790,7 @@ def create_combined_roi_time_series_graph(df):
788
  type="rect",
789
  fillcolor="rgba(255, 230, 230, 0.3)",
790
  line=dict(width=0),
791
- y0=-1, y1=0, # Use a fixed negative value
792
  x0=min_time, x1=max_time,
793
  layer="below"
794
  )
@@ -801,14 +803,14 @@ def create_combined_roi_time_series_graph(df):
801
  x0=min_time, x1=max_time
802
  )
803
 
804
- # Filter out outliers (ROI values above 2 or below -2)
805
- outlier_data = df[(df['roi'] > 2) | (df['roi'] < -2)].copy()
806
- df_filtered = df[(df['roi'] <= 2) & (df['roi'] >= -2)].copy()
807
 
808
  # Log the outliers for better debugging
809
  if len(outlier_data) > 0:
810
  excluded_count = len(outlier_data)
811
- logger.info(f"Excluded {excluded_count} data points with outlier ROI values (>2 or <-2)")
812
 
813
  # Group outliers by agent for detailed logging
814
  outlier_agents = outlier_data.groupby('agent_name')
@@ -922,7 +924,7 @@ def create_combined_roi_time_series_graph(df):
922
  for idx, row in avg_roi_data_with_ma.iterrows():
923
  timestamp = row['timestamp']
924
  hover_data_roi.append(
925
- f"Time: {timestamp}<br>Avg ROI (3d window): {row['moving_avg']:.2f}"
926
  )
927
 
928
  fig.add_trace(
@@ -967,25 +969,13 @@ def create_combined_roi_time_series_graph(df):
967
  hovermode="closest"
968
  )
969
 
970
- # Add annotations for y-axis regions
971
- fig.add_annotation(
972
- x=-0.08, # Position further from the y-axis to avoid overlapping with tick labels
973
- y=-0.5, # Middle of the negative region
974
- xref="paper",
975
- yref="y",
976
- text="Negative ROI [ratio]",
977
- showarrow=False,
978
- font=dict(size=16, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size
979
- textangle=-90, # Rotate text to be vertical
980
- align="center"
981
- )
982
-
983
  fig.add_annotation(
984
  x=-0.08, # Position further from the y-axis to avoid overlapping with tick labels
985
- y=0.5, # Middle of the positive region
986
  xref="paper",
987
  yref="y",
988
- text="Positive ROI [ratio]",
989
  showarrow=False,
990
  font=dict(size=16, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size
991
  textangle=-90, # Rotate text to be vertical
@@ -1010,14 +1000,14 @@ def create_combined_roi_time_series_graph(df):
1010
  )
1011
  )
1012
 
1013
- # Update y-axis with fixed range of -1 to +1 for ROI
1014
  fig.update_yaxes(
1015
  showgrid=True,
1016
  gridwidth=1,
1017
  gridcolor='rgba(0,0,0,0.1)',
1018
  # Use fixed range instead of autoscaling
1019
  autorange=False, # Disable autoscaling
1020
- range=[-1, 1], # Set fixed range from -1 to +1
1021
  tickformat=".2f", # Format tick labels with 2 decimal places
1022
  tickfont=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size
1023
  title=None # Remove the built-in axis title since we're using annotations
@@ -1101,15 +1091,16 @@ def create_combined_roi_time_series_graph(df):
1101
  margin=dict(r=30, l=120, t=40, b=50)
1102
  )
1103
 
1104
- # Update y-axis with fixed range of -1 to +1 for ROI
1105
  simple_fig.update_yaxes(
1106
  showgrid=True,
1107
  gridwidth=1,
1108
  gridcolor='rgba(0,0,0,0.1)',
1109
  autorange=False,
1110
- range=[-1, 1],
1111
  tickformat=".2f",
1112
- tickfont=dict(size=14, family="Arial, sans-serif", color="black", weight="bold")
 
1113
  )
1114
 
1115
  # Update x-axis with better formatting and fixed range
 
746
 
747
  # IMPORTANT: Force data types to ensure consistency
748
  df['roi'] = df['roi'].astype(float) # Ensure ROI is float
749
+ # Convert ROI values to percentages (multiply by 100)
750
+ df['roi'] = df['roi'] * 100
751
  df['metric_type'] = df['metric_type'].astype(str) # Ensure metric_type is string
752
 
753
  # Get min and max time for shapes
 
780
  type="rect",
781
  fillcolor="rgba(230, 243, 255, 0.3)",
782
  line=dict(width=0),
783
+ y0=0, y1=100, # Use a fixed positive value (percentage)
784
  x0=min_time, x1=max_time,
785
  layer="below"
786
  )
 
790
  type="rect",
791
  fillcolor="rgba(255, 230, 230, 0.3)",
792
  line=dict(width=0),
793
+ y0=-100, y1=0, # Use a fixed negative value (percentage)
794
  x0=min_time, x1=max_time,
795
  layer="below"
796
  )
 
803
  x0=min_time, x1=max_time
804
  )
805
 
806
+ # Filter out outliers (ROI values above 200% or below -200%)
807
+ outlier_data = df[(df['roi'] > 200) | (df['roi'] < -200)].copy()
808
+ df_filtered = df[(df['roi'] <= 200) & (df['roi'] >= -200)].copy()
809
 
810
  # Log the outliers for better debugging
811
  if len(outlier_data) > 0:
812
  excluded_count = len(outlier_data)
813
+ logger.info(f"Excluded {excluded_count} data points with outlier ROI values (>200% or <-200%)")
814
 
815
  # Group outliers by agent for detailed logging
816
  outlier_agents = outlier_data.groupby('agent_name')
 
924
  for idx, row in avg_roi_data_with_ma.iterrows():
925
  timestamp = row['timestamp']
926
  hover_data_roi.append(
927
+ f"Time: {timestamp}<br>Avg ROI (3d window): {row['moving_avg']:.2f}%"
928
  )
929
 
930
  fig.add_trace(
 
969
  hovermode="closest"
970
  )
971
 
972
+ # Add single annotation for y-axis
 
 
 
 
 
 
 
 
 
 
 
 
973
  fig.add_annotation(
974
  x=-0.08, # Position further from the y-axis to avoid overlapping with tick labels
975
+ y=0, # Center of the y-axis
976
  xref="paper",
977
  yref="y",
978
+ text="ROI [%]",
979
  showarrow=False,
980
  font=dict(size=16, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size
981
  textangle=-90, # Rotate text to be vertical
 
1000
  )
1001
  )
1002
 
1003
+ # Update y-axis with fixed range of -100% to +100% for ROI
1004
  fig.update_yaxes(
1005
  showgrid=True,
1006
  gridwidth=1,
1007
  gridcolor='rgba(0,0,0,0.1)',
1008
  # Use fixed range instead of autoscaling
1009
  autorange=False, # Disable autoscaling
1010
+ range=[-100, 100], # Set fixed range from -100% to +100%
1011
  tickformat=".2f", # Format tick labels with 2 decimal places
1012
  tickfont=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Adjusted font size
1013
  title=None # Remove the built-in axis title since we're using annotations
 
1091
  margin=dict(r=30, l=120, t=40, b=50)
1092
  )
1093
 
1094
+ # Update y-axis with fixed range of -100% to +100% for ROI
1095
  simple_fig.update_yaxes(
1096
  showgrid=True,
1097
  gridwidth=1,
1098
  gridcolor='rgba(0,0,0,0.1)',
1099
  autorange=False,
1100
+ range=[-100, 100],
1101
  tickformat=".2f",
1102
+ tickfont=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"),
1103
+ title=None # Remove the built-in axis title since we're using annotations
1104
  )
1105
 
1106
  # Update x-axis with better formatting and fixed range