Vaibhav84 commited on
Commit
2154961
·
1 Parent(s): dffa418
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -162,7 +162,10 @@ async def login(customer_id: str):
162
  customer_data = purchase_history[purchase_history['Customer_Id'] == customer_id]
163
  total_purchases = len(customer_data)
164
  total_spent = customer_data['Amount (In Dollars)'].sum()
165
- last_purchase = customer_data['Purchase_Date'].max().strftime('%Y-%m-%d')
 
 
 
166
 
167
  return JSONResponse(
168
  status_code=status.HTTP_200_OK,
@@ -173,7 +176,7 @@ async def login(customer_id: str):
173
  "customer_stats": {
174
  "total_purchases": total_purchases,
175
  "total_spent": float(total_spent),
176
- "last_purchase_date": last_purchase
177
  }
178
  }
179
  )
 
162
  customer_data = purchase_history[purchase_history['Customer_Id'] == customer_id]
163
  total_purchases = len(customer_data)
164
  total_spent = customer_data['Amount (In Dollars)'].sum()
165
+
166
+ # Convert last purchase date to datetime if it's not already
167
+ last_purchase = pd.to_datetime(customer_data['Purchase_Date'].max())
168
+ last_purchase_str = last_purchase.strftime('%Y-%m-%d')
169
 
170
  return JSONResponse(
171
  status_code=status.HTTP_200_OK,
 
176
  "customer_stats": {
177
  "total_purchases": total_purchases,
178
  "total_spent": float(total_spent),
179
+ "last_purchase_date": last_purchase_str
180
  }
181
  }
182
  )