Update main.py
Browse files
main.py
CHANGED
|
@@ -129,12 +129,7 @@ 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 |
-
|
| 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,7 +142,7 @@ def predict_metric():
|
|
| 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
|
| 151 |
|
| 152 |
# Create DataFrame from the aggregated data
|
| 153 |
df = pd.DataFrame(data)
|
|
@@ -178,16 +173,13 @@ def predict_metric():
|
|
| 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})
|
| 189 |
|
| 190 |
|
| 191 |
|
|
|
|
| 192 |
if __name__ == "__main__":
|
| 193 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
|
| 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 |
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 |
|
| 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})
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
+
|
| 184 |
if __name__ == "__main__":
|
| 185 |
app.run(debug=True, host="0.0.0.0", port=7860)
|