yeref 0.24.63__py3-none-any.whl → 0.24.64__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
yeref/yeref.py CHANGED
@@ -16384,6 +16384,64 @@ async def return_cohort_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
16384
16384
  except Exception as e:
16385
16385
  logger.info(log_ % str(e))
16386
16386
  await asyncio.sleep(round(random.uniform(0, 1), 2))
16387
+
16388
+
16389
+ async def return_retention_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
16390
+ try:
16391
+ sql = 'SELECT USER_TID, USER_VARS, USER_LSTS FROM "USER"'
16392
+ data_users = await db_select_pg(sql, (), BASE_P)
16393
+
16394
+ # собираем выручку по пользователю и месяцу
16395
+ user_month_rev = defaultdict(lambda: defaultdict(float))
16396
+ for USER_TID, USER_VARS, USER_LSTS in data_users:
16397
+ USER_LSTS = json.loads(USER_LSTS or "{}")
16398
+ for pay in USER_LSTS.get("USER_PAYMENTS", []):
16399
+ dt_p = datetime.strptime(pay.get("DT_START", ""), "%d-%m-%Y_%H-%M-%S")
16400
+ mo = dt_p.strftime("%Y-%m")
16401
+ amt = float(pay.get("AMOUNT", 0)) * 0.013
16402
+ user_month_rev[USER_TID][mo] += amt
16403
+
16404
+ # список всех месяцев с выручкой, отсортированный
16405
+ all_months = sorted({mo for revs in user_month_rev.values() for mo in revs.keys()})
16406
+
16407
+ results = []
16408
+ for idx, mo in enumerate(all_months):
16409
+ if idx == 0:
16410
+ results.append({"MO": mo, "NRR": ""})
16411
+ continue
16412
+ prev_mo = all_months[idx - 1]
16413
+ # общая выручка в prev_mo
16414
+ prev_total = sum(user_month_rev[u][prev_mo] for u in user_month_rev if prev_mo in user_month_rev[u])
16415
+ if prev_total == 0:
16416
+ results.append({"MO": mo, "NRR": ""})
16417
+ continue
16418
+ # выручка текущего месяца от тех же пользователей
16419
+ curr_existing = sum(
16420
+ user_month_rev[u][mo]
16421
+ for u in user_month_rev
16422
+ if prev_mo in user_month_rev[u] and mo in user_month_rev[u]
16423
+ )
16424
+ nrr = curr_existing / prev_total
16425
+ results.append({"MO": mo, "NRR": f"{nrr * 100:.2f}"})
16426
+
16427
+ # средний NRR (арифметическое по ненулевым)
16428
+ vals = [float(r["NRR"]) for r in results if r["NRR"]]
16429
+ avg_nrr = f"{(sum(vals) / len(vals)):.2f}" if vals else ""
16430
+
16431
+ path = os.path.join(EXTRA_D, "4_retention_metrics.csv")
16432
+ with open(path, "w", newline="", encoding="utf-8") as f:
16433
+ writer = csv.writer(f)
16434
+ writer.writerow(["MO", "NRR (%)"])
16435
+ for r in results:
16436
+ writer.writerow([r["MO"], r["NRR"]])
16437
+ writer.writerow([])
16438
+ writer.writerow([f"Avg NRR (%)", avg_nrr])
16439
+
16440
+ thumb = types.FSInputFile(os.path.join(EXTRA_D, "parse.jpg"))
16441
+ await bot.send_document(chat_id=my_tid, document=types.FSInputFile(path), thumbnail=thumb)
16442
+ except Exception as e:
16443
+ logger.info(log_ % str(e))
16444
+ await asyncio.sleep(round(random.uniform(0, 1), 2))
16387
16445
  # endregion
16388
16446
 
16389
16447
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.24.63
3
+ Version: 0.24.64
4
4
  Summary: desc-f
5
5
  Author: john smith
6
6
  Dynamic: author
@@ -0,0 +1,8 @@
1
+ yeref/__init__.py,sha256=Qpv3o6Xa78VdLcsSRmctGtpnYE9btpAkCekgGhgJyXM,49
2
+ yeref/l_.py,sha256=LMX_olmJwq-tgoALJCnhV_fGrL_i_43yBLkLIcEVqGo,1176743
3
+ yeref/tonweb.js,sha256=Jf6aFOQ1OIY4q7fINYz-m5LsI3seMus124M5SYYZmtE,443659
4
+ yeref/yeref.py,sha256=glPGJMY3TeP4Co9strdQVC0_69hoczpgZrdd4EYZyWA,1049992
5
+ yeref-0.24.64.dist-info/METADATA,sha256=47oqQivE47jiq3OilxVF4-aTeR5TfdCT_1txVLJVhWg,119
6
+ yeref-0.24.64.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ yeref-0.24.64.dist-info/top_level.txt,sha256=yCQKchWHbfV-3OuQPYRdi2loypD-nmbDJbtt3OuKKkY,6
8
+ yeref-0.24.64.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- yeref/__init__.py,sha256=Qpv3o6Xa78VdLcsSRmctGtpnYE9btpAkCekgGhgJyXM,49
2
- yeref/l_.py,sha256=LMX_olmJwq-tgoALJCnhV_fGrL_i_43yBLkLIcEVqGo,1176743
3
- yeref/tonweb.js,sha256=Jf6aFOQ1OIY4q7fINYz-m5LsI3seMus124M5SYYZmtE,443659
4
- yeref/yeref.py,sha256=rAoPHlZIPtypeSgPOOh0OTBFFxTwHk22mfPgHUGAip8,1047232
5
- yeref-0.24.63.dist-info/METADATA,sha256=Vx9UiXw9chj2HewsdxkCOVgZU5LuPKp_9htAWA0tU_0,119
6
- yeref-0.24.63.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- yeref-0.24.63.dist-info/top_level.txt,sha256=yCQKchWHbfV-3OuQPYRdi2loypD-nmbDJbtt3OuKKkY,6
8
- yeref-0.24.63.dist-info/RECORD,,