gauravlochab
commited on
Commit
·
f3b2793
1
Parent(s):
197397f
fix: roi graph
Browse files
app.py
CHANGED
@@ -1197,8 +1197,51 @@ def create_combined_roi_time_series_graph(df):
|
|
1197 |
for agent_id, data in agent_runtimes.items():
|
1198 |
logger.info(f"Agent {data['agent_name']} (ID: {agent_id}): Runtime = {data['runtime_days']:.2f} days, Last report: {data['last_report']}")
|
1199 |
|
1200 |
-
# IMPORTANT:
|
1201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1202 |
# ROI values are already in percentage format from initial_value_fixer.py
|
1203 |
df['metric_type'] = df['metric_type'].astype(str) # Ensure metric_type is string
|
1204 |
|
|
|
1197 |
for agent_id, data in agent_runtimes.items():
|
1198 |
logger.info(f"Agent {data['agent_name']} (ID: {agent_id}): Runtime = {data['runtime_days']:.2f} days, Last report: {data['last_report']}")
|
1199 |
|
1200 |
+
# IMPORTANT: Clean and convert ROI data to ensure consistency
|
1201 |
+
logger.info("Cleaning ROI data before conversion...")
|
1202 |
+
|
1203 |
+
def clean_roi_value(value):
|
1204 |
+
"""Clean and convert ROI value to float"""
|
1205 |
+
if pd.isna(value):
|
1206 |
+
return None
|
1207 |
+
|
1208 |
+
# If it's already a number, return it
|
1209 |
+
if isinstance(value, (int, float)):
|
1210 |
+
return float(value)
|
1211 |
+
|
1212 |
+
# If it's a string, try to extract numeric value
|
1213 |
+
if isinstance(value, str):
|
1214 |
+
# Remove any non-numeric characters except decimal point and minus sign
|
1215 |
+
import re
|
1216 |
+
# Look for patterns like "value': 16.007665648354" and extract the number
|
1217 |
+
match = re.search(r'[\d\.-]+', value)
|
1218 |
+
if match:
|
1219 |
+
try:
|
1220 |
+
return float(match.group())
|
1221 |
+
except ValueError:
|
1222 |
+
logger.warning(f"Could not convert ROI value to float: {value}")
|
1223 |
+
return None
|
1224 |
+
else:
|
1225 |
+
logger.warning(f"No numeric value found in ROI string: {value}")
|
1226 |
+
return None
|
1227 |
+
|
1228 |
+
logger.warning(f"Unexpected ROI value type: {type(value)} - {value}")
|
1229 |
+
return None
|
1230 |
+
|
1231 |
+
# Apply cleaning function to ROI column
|
1232 |
+
df['roi'] = df['roi'].apply(clean_roi_value)
|
1233 |
+
|
1234 |
+
# Remove rows with invalid ROI values
|
1235 |
+
initial_count = len(df)
|
1236 |
+
df = df[df['roi'].notna()]
|
1237 |
+
final_count = len(df)
|
1238 |
+
removed_count = initial_count - final_count
|
1239 |
+
|
1240 |
+
if removed_count > 0:
|
1241 |
+
logger.warning(f"Removed {removed_count} rows with invalid ROI values")
|
1242 |
+
|
1243 |
+
# Ensure ROI is float after cleaning
|
1244 |
+
df['roi'] = df['roi'].astype(float)
|
1245 |
# ROI values are already in percentage format from initial_value_fixer.py
|
1246 |
df['metric_type'] = df['metric_type'].astype(str) # Ensure metric_type is string
|
1247 |
|