yoursdvniel commited on
Commit
d31557e
·
verified ·
1 Parent(s): d25a8b4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -3
main.py CHANGED
@@ -129,7 +129,12 @@ def predict_metric():
129
  # Calculate net profit for each date
130
  for date, income in income_data.items():
131
  expense = expense_data.get(date, 0)
132
- data.append({"date": date, "amountDue": income - expense})
 
 
 
 
 
133
 
134
  elif metric_type == "Customer Engagement":
135
  # Use count of Income transactions per day as Customer Engagement
@@ -142,7 +147,7 @@ def predict_metric():
142
  engagement_data[date_str] = engagement_data.get(date_str, 0) + 1
143
 
144
  for date, count in engagement_data.items():
145
- data.append({"date": date, "amountDue": count})
146
 
147
  # Create DataFrame from the aggregated data
148
  df = pd.DataFrame(data)
@@ -173,7 +178,11 @@ def predict_metric():
173
 
174
  # Extract the forecast for the requested interval
175
  forecast_data = forecast[['ds', 'yhat']].tail(interval)
176
- predictions = [{"date": row['ds'].strftime('%Y-%m-%d'), "value": row['yhat']} for _, row in forecast_data.iterrows()]
 
 
 
 
177
 
178
  # Return predictions in JSON format
179
  return jsonify({"predictedData": predictions})
 
129
  # Calculate net profit for each date
130
  for date, income in income_data.items():
131
  expense = expense_data.get(date, 0)
132
+ profit_or_loss = income - expense
133
+ data.append({
134
+ "date": date,
135
+ "amountDue": abs(profit_or_loss),
136
+ "isLoss": profit_or_loss < 0 # Indicate if it's a loss
137
+ })
138
 
139
  elif metric_type == "Customer Engagement":
140
  # Use count of Income transactions per day as Customer Engagement
 
147
  engagement_data[date_str] = engagement_data.get(date_str, 0) + 1
148
 
149
  for date, count in engagement_data.items():
150
+ data.append({"date": date, "amountDue": count, "isLoss": False})
151
 
152
  # Create DataFrame from the aggregated data
153
  df = pd.DataFrame(data)
 
178
 
179
  # Extract the forecast for the requested interval
180
  forecast_data = forecast[['ds', 'yhat']].tail(interval)
181
+ predictions = [{
182
+ "date": row['ds'].strftime('%Y-%m-%d'),
183
+ "value": abs(row['yhat']), # Use absolute value to remove negatives
184
+ "isLoss": row['yhat'] < 0 # Indicate if prediction is a loss
185
+ } for _, row in forecast_data.iterrows()]
186
 
187
  # Return predictions in JSON format
188
  return jsonify({"predictedData": predictions})