Update utils/api_client.py
Browse files- utils/api_client.py +84 -54
utils/api_client.py
CHANGED
|
@@ -246,65 +246,95 @@ class RewardPilotClient:
|
|
| 246 |
}
|
| 247 |
}
|
| 248 |
|
| 249 |
-
def _get_mock_analytics(self, user_id: str) -> Dict:
|
| 250 |
-
"""Generate mock analytics
|
| 251 |
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
|
| 254 |
return {
|
| 255 |
"success": True,
|
| 256 |
"data": {
|
| 257 |
-
|
| 258 |
-
"total_spending": 3450.75,
|
| 259 |
-
"total_rewards": 142.50,
|
| 260 |
-
"potential_savings": 425.00,
|
| 261 |
-
"optimization_score": 87,
|
| 262 |
-
"optimized_count": 156,
|
| 263 |
-
"total_transactions": 180,
|
| 264 |
-
"top_category": "Groceries",
|
| 265 |
-
"cards": ["Amex Gold", "Chase Sapphire Reserve", "Citi Double Cash"],
|
| 266 |
-
"category_breakdown": [
|
| 267 |
-
{
|
| 268 |
-
"category": "Groceries",
|
| 269 |
-
"spending": 1250.00,
|
| 270 |
-
"rewards": 50.00,
|
| 271 |
-
"transactions": 45
|
| 272 |
-
},
|
| 273 |
-
{
|
| 274 |
-
"category": "Dining",
|
| 275 |
-
"spending": 890.50,
|
| 276 |
-
"rewards": 35.62,
|
| 277 |
-
"transactions": 38
|
| 278 |
-
},
|
| 279 |
-
{
|
| 280 |
-
"category": "Travel",
|
| 281 |
-
"spending": 750.25,
|
| 282 |
-
"rewards": 22.51,
|
| 283 |
-
"transactions": 12
|
| 284 |
-
},
|
| 285 |
-
{
|
| 286 |
-
"category": "Gas",
|
| 287 |
-
"spending": 350.00,
|
| 288 |
-
"rewards": 14.00,
|
| 289 |
-
"transactions": 24
|
| 290 |
-
},
|
| 291 |
-
{
|
| 292 |
-
"category": "Online Shopping",
|
| 293 |
-
"spending": 210.00,
|
| 294 |
-
"rewards": 10.50,
|
| 295 |
-
"transactions": 18
|
| 296 |
-
}
|
| 297 |
-
],
|
| 298 |
-
"monthly_trends": [
|
| 299 |
-
{"month": "Jan", "spending": 2800, "rewards": 115},
|
| 300 |
-
{"month": "Feb", "spending": 3100, "rewards": 128},
|
| 301 |
-
{"month": "Mar", "spending": 3450, "rewards": 142}
|
| 302 |
-
],
|
| 303 |
-
"card_performance": [
|
| 304 |
-
{"card": "Amex Gold", "rewards": 65.00, "usage_pct": 45},
|
| 305 |
-
{"card": "Chase Sapphire Reserve", "rewards": 48.50, "usage_pct": 30},
|
| 306 |
-
{"card": "Citi Double Cash", "rewards": 29.00, "usage_pct": 25}
|
| 307 |
-
],
|
| 308 |
"mock_data": True
|
| 309 |
}
|
| 310 |
}
|
|
|
|
| 246 |
}
|
| 247 |
}
|
| 248 |
|
| 249 |
+
def _get_mock_analytics(self, user_id: str) -> Dict[str, Any]:
|
| 250 |
+
"""Generate user-specific mock analytics"""
|
| 251 |
|
| 252 |
+
# Different data for different users
|
| 253 |
+
user_profiles = {
|
| 254 |
+
"u_alice": {
|
| 255 |
+
"user_id": "u_alice",
|
| 256 |
+
"total_spending": 4250.75,
|
| 257 |
+
"total_rewards": 187.50,
|
| 258 |
+
"optimization_score": 92,
|
| 259 |
+
"optimized_count": 58,
|
| 260 |
+
"potential_savings": 125.00,
|
| 261 |
+
"spending_by_category": {
|
| 262 |
+
"Groceries": 1200.00,
|
| 263 |
+
"Restaurants": 850.50,
|
| 264 |
+
"Gas Stations": 420.25,
|
| 265 |
+
"Online Shopping": 1200.00,
|
| 266 |
+
"Entertainment": 580.00
|
| 267 |
+
},
|
| 268 |
+
"rewards_by_card": {
|
| 269 |
+
"Amex Gold": 95.50,
|
| 270 |
+
"Chase Sapphire Reserve": 62.00,
|
| 271 |
+
"Citi Double Cash": 30.00
|
| 272 |
+
},
|
| 273 |
+
"monthly_trends": [
|
| 274 |
+
{"month": "Aug", "spending": 1200, "rewards": 52},
|
| 275 |
+
{"month": "Sep", "spending": 1450, "rewards": 63},
|
| 276 |
+
{"month": "Oct", "spending": 1600, "rewards": 72}
|
| 277 |
+
]
|
| 278 |
+
},
|
| 279 |
+
"u_bob": {
|
| 280 |
+
"user_id": "u_bob",
|
| 281 |
+
"total_spending": 3150.25,
|
| 282 |
+
"total_rewards": 142.30,
|
| 283 |
+
"optimization_score": 78,
|
| 284 |
+
"optimized_count": 42,
|
| 285 |
+
"potential_savings": 285.50,
|
| 286 |
+
"spending_by_category": {
|
| 287 |
+
"Groceries": 800.00,
|
| 288 |
+
"Restaurants": 1200.00,
|
| 289 |
+
"Gas Stations": 350.00,
|
| 290 |
+
"Airlines": 600.00,
|
| 291 |
+
"Entertainment": 200.25
|
| 292 |
+
},
|
| 293 |
+
"rewards_by_card": {
|
| 294 |
+
"Chase Sapphire Reserve": 85.00,
|
| 295 |
+
"Amex Gold": 42.30,
|
| 296 |
+
"Capital One Venture": 15.00
|
| 297 |
+
},
|
| 298 |
+
"monthly_trends": [
|
| 299 |
+
{"month": "Aug", "spending": 950, "rewards": 38},
|
| 300 |
+
{"month": "Sep", "spending": 1100, "rewards": 52},
|
| 301 |
+
{"month": "Oct", "spending": 1100, "rewards": 52}
|
| 302 |
+
]
|
| 303 |
+
},
|
| 304 |
+
"u_charlie": {
|
| 305 |
+
"user_id": "u_charlie",
|
| 306 |
+
"total_spending": 5420.80,
|
| 307 |
+
"total_rewards": 245.60,
|
| 308 |
+
"optimization_score": 85,
|
| 309 |
+
"optimized_count": 67,
|
| 310 |
+
"potential_savings": 180.00,
|
| 311 |
+
"spending_by_category": {
|
| 312 |
+
"Online Shopping": 2000.00,
|
| 313 |
+
"Groceries": 1100.00,
|
| 314 |
+
"Restaurants": 950.00,
|
| 315 |
+
"Gas Stations": 520.80,
|
| 316 |
+
"Hotels": 850.00
|
| 317 |
+
},
|
| 318 |
+
"rewards_by_card": {
|
| 319 |
+
"Amex Gold": 125.00,
|
| 320 |
+
"Chase Sapphire Reserve": 95.60,
|
| 321 |
+
"Citi Double Cash": 25.00
|
| 322 |
+
},
|
| 323 |
+
"monthly_trends": [
|
| 324 |
+
{"month": "Aug", "spending": 1650, "rewards": 75},
|
| 325 |
+
{"month": "Sep", "spending": 1850, "rewards": 82},
|
| 326 |
+
{"month": "Oct", "spending": 1920, "rewards": 88}
|
| 327 |
+
]
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
# Get user-specific data or default to alice
|
| 332 |
+
user_data = user_profiles.get(user_id, user_profiles["u_alice"])
|
| 333 |
|
| 334 |
return {
|
| 335 |
"success": True,
|
| 336 |
"data": {
|
| 337 |
+
**user_data,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
"mock_data": True
|
| 339 |
}
|
| 340 |
}
|