Update main.py
Browse files
main.py
CHANGED
|
@@ -105,20 +105,28 @@ def predict_revenue():
|
|
| 105 |
# Fetch transaction data based on user and transaction type
|
| 106 |
transactions_ref = db.collection("system_users").document(user_id).collection("transactions")
|
| 107 |
query = transactions_ref.where("transactionType", "==", transaction_type).stream()
|
| 108 |
-
|
| 109 |
data = []
|
| 110 |
for doc in query:
|
| 111 |
transaction = doc.to_dict()
|
| 112 |
data.append({
|
| 113 |
-
"date": transaction["date"]
|
| 114 |
"amountDue": transaction["amountDue"]
|
| 115 |
})
|
| 116 |
|
| 117 |
# Create DataFrame from transaction data
|
| 118 |
df = pd.DataFrame(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
df = df.sort_values("date").set_index("date")
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# Check if there's enough data to train the model
|
| 124 |
if df.shape[0] < 10:
|
|
|
|
| 105 |
# Fetch transaction data based on user and transaction type
|
| 106 |
transactions_ref = db.collection("system_users").document(user_id).collection("transactions")
|
| 107 |
query = transactions_ref.where("transactionType", "==", transaction_type).stream()
|
| 108 |
+
|
| 109 |
data = []
|
| 110 |
for doc in query:
|
| 111 |
transaction = doc.to_dict()
|
| 112 |
data.append({
|
| 113 |
+
"date": transaction["date"], # Assuming transaction["date"] is already a datetime object
|
| 114 |
"amountDue": transaction["amountDue"]
|
| 115 |
})
|
| 116 |
|
| 117 |
# Create DataFrame from transaction data
|
| 118 |
df = pd.DataFrame(data)
|
| 119 |
+
|
| 120 |
+
# Ensure 'date' column is datetime
|
| 121 |
+
df['date'] = pd.to_datetime(df['date'])
|
| 122 |
+
|
| 123 |
+
# Set 'date' as index
|
| 124 |
df = df.sort_values("date").set_index("date")
|
| 125 |
+
|
| 126 |
+
# Resample daily to ensure regular intervals
|
| 127 |
+
df = df.resample("D").sum().reset_index()
|
| 128 |
+
|
| 129 |
+
df.columns = ["ds", "y"] # ds: date, y: target
|
| 130 |
|
| 131 |
# Check if there's enough data to train the model
|
| 132 |
if df.shape[0] < 10:
|