Spaces:
Sleeping
Sleeping
gauravlochab
commited on
Commit
·
ef47052
1
Parent(s):
0d99588
feat: ROI runtime calculation fixed and log individual agent runtimes
Browse files
app.py
CHANGED
|
@@ -744,6 +744,31 @@ def create_combined_roi_time_series_graph(df):
|
|
| 744 |
)
|
| 745 |
return fig
|
| 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)
|
|
@@ -958,10 +983,10 @@ def create_combined_roi_time_series_graph(df):
|
|
| 958 |
)
|
| 959 |
logger.info(f"Added 3-day moving average ROI trace with {len(x_values_ma)} points")
|
| 960 |
|
| 961 |
-
# Update layout
|
| 962 |
fig.update_layout(
|
| 963 |
title=dict(
|
| 964 |
-
text="Modius Agents ROI",
|
| 965 |
font=dict(
|
| 966 |
family="Arial, sans-serif",
|
| 967 |
size=22,
|
|
|
|
| 744 |
)
|
| 745 |
return fig
|
| 746 |
|
| 747 |
+
# Define fixed start date (February 1, 2025)
|
| 748 |
+
fixed_start_date = datetime(2025, 2, 1)
|
| 749 |
+
logger.info(f"Using fixed start date for ROI runtime calculation: {fixed_start_date}")
|
| 750 |
+
|
| 751 |
+
# Calculate runtime for each agent from fixed start date
|
| 752 |
+
agent_runtimes = {}
|
| 753 |
+
for agent_id in df['agent_id'].unique():
|
| 754 |
+
agent_data = df[df['agent_id'] == agent_id]
|
| 755 |
+
agent_name = agent_data['agent_name'].iloc[0]
|
| 756 |
+
last_report = agent_data['timestamp'].max()
|
| 757 |
+
runtime_days = (last_report - fixed_start_date).total_seconds() / (24 * 3600) # Convert to days
|
| 758 |
+
agent_runtimes[agent_id] = {
|
| 759 |
+
'agent_name': agent_name,
|
| 760 |
+
'last_report': last_report,
|
| 761 |
+
'runtime_days': runtime_days
|
| 762 |
+
}
|
| 763 |
+
|
| 764 |
+
# Calculate average runtime
|
| 765 |
+
avg_runtime = sum(data['runtime_days'] for data in agent_runtimes.values()) / len(agent_runtimes) if agent_runtimes else 0
|
| 766 |
+
logger.info(f"Average agent runtime from fixed start date: {avg_runtime:.2f} days")
|
| 767 |
+
|
| 768 |
+
# Log individual agent runtimes for debugging
|
| 769 |
+
for agent_id, data in agent_runtimes.items():
|
| 770 |
+
logger.info(f"Agent {data['agent_name']} (ID: {agent_id}): Runtime = {data['runtime_days']:.2f} days, Last report: {data['last_report']}")
|
| 771 |
+
|
| 772 |
# IMPORTANT: Force data types to ensure consistency
|
| 773 |
df['roi'] = df['roi'].astype(float) # Ensure ROI is float
|
| 774 |
# Convert ROI values to percentages (multiply by 100)
|
|
|
|
| 983 |
)
|
| 984 |
logger.info(f"Added 3-day moving average ROI trace with {len(x_values_ma)} points")
|
| 985 |
|
| 986 |
+
# Update layout with average runtime information in the title
|
| 987 |
fig.update_layout(
|
| 988 |
title=dict(
|
| 989 |
+
text=f"Modius Agents ROI (over avg. {avg_runtime:.1f} days runtime)",
|
| 990 |
font=dict(
|
| 991 |
family="Arial, sans-serif",
|
| 992 |
size=22,
|