LogicGoInfotechSpaces commited on
Commit
ed59e54
·
verified ·
1 Parent(s): 28443f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -360,28 +360,34 @@ async def face_swap_api(
360
  daily_updates = []
361
 
362
  if not daily_entries:
363
- # FIRST EVER USAGE → today = 1
364
  daily_updates.append({"date": today_date, "count": 1})
365
  else:
366
- # Find the latest date in the array
 
 
 
367
  last_date_in_db = max(entry["date"] for entry in daily_entries)
368
- next_day = last_date_in_db + timedelta(days=1)
369
 
370
- # Fill missing days with count = 0 up to yesterday
 
371
  while next_day < today_date:
372
- daily_updates.append({"date": next_day, "count": 0})
 
373
  next_day += timedelta(days=1)
374
 
375
- # Today = 1
376
- daily_updates.append({"date": today_date, "count": 1})
 
377
 
 
378
  if daily_updates:
379
  await media_clicks_col.update_one(
380
  {"userId": user_oid},
381
  {"$push": {"ai_edit_daily_count": {"$each": daily_updates}}}
382
  )
383
 
384
- # After this, optionally sort & trim to last 32 days
385
  doc = await media_clicks_col.find_one({"userId": user_oid}, {"ai_edit_daily_count": 1})
386
  daily_entries = doc.get("ai_edit_daily_count", []) if doc else []
387
  daily_entries.sort(key=lambda x: x["date"])
@@ -392,6 +398,7 @@ async def face_swap_api(
392
  {"$set": {"ai_edit_daily_count": daily_entries}}
393
  )
394
 
 
395
  # doc = await media_clicks_col.find_one(
396
  # {"userId": user_oid},
397
  # {"ai_edit_daily_count": 1}
 
360
  daily_updates = []
361
 
362
  if not daily_entries:
363
+ # FIRST EVER USAGE → only today = 1 (no previous 0s)
364
  daily_updates.append({"date": today_date, "count": 1})
365
  else:
366
+ # Build a set of existing dates to avoid duplicates
367
+ existing_dates = {entry["date"] for entry in daily_entries}
368
+
369
+ # Find the last recorded date
370
  last_date_in_db = max(entry["date"] for entry in daily_entries)
 
371
 
372
+ # Fill missing days between last date and yesterday with count=0
373
+ next_day = last_date_in_db + timedelta(days=1)
374
  while next_day < today_date:
375
+ if next_day not in existing_dates:
376
+ daily_updates.append({"date": next_day, "count": 0})
377
  next_day += timedelta(days=1)
378
 
379
+ # Add today if not already present
380
+ if today_date not in existing_dates:
381
+ daily_updates.append({"date": today_date, "count": 1})
382
 
383
+ # Push updates if any
384
  if daily_updates:
385
  await media_clicks_col.update_one(
386
  {"userId": user_oid},
387
  {"$push": {"ai_edit_daily_count": {"$each": daily_updates}}}
388
  )
389
 
390
+ # Sort and trim to last 32 days
391
  doc = await media_clicks_col.find_one({"userId": user_oid}, {"ai_edit_daily_count": 1})
392
  daily_entries = doc.get("ai_edit_daily_count", []) if doc else []
393
  daily_entries.sort(key=lambda x: x["date"])
 
398
  {"$set": {"ai_edit_daily_count": daily_entries}}
399
  )
400
 
401
+
402
  # doc = await media_clicks_col.find_one(
403
  # {"userId": user_oid},
404
  # {"ai_edit_daily_count": 1}