yeref 0.24.62__tar.gz → 0.24.64__tar.gz
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-0.24.62 → yeref-0.24.64}/PKG-INFO +1 -1
- {yeref-0.24.62 → yeref-0.24.64}/setup.py +1 -1
- {yeref-0.24.62 → yeref-0.24.64}/yeref/yeref.py +58 -0
- {yeref-0.24.62 → yeref-0.24.64}/yeref.egg-info/PKG-INFO +1 -1
- {yeref-0.24.62 → yeref-0.24.64}/pyproject.toml +0 -0
- {yeref-0.24.62 → yeref-0.24.64}/setup.cfg +0 -0
- {yeref-0.24.62 → yeref-0.24.64}/yeref/__init__.py +0 -0
- {yeref-0.24.62 → yeref-0.24.64}/yeref/l_.py +0 -0
- {yeref-0.24.62 → yeref-0.24.64}/yeref/tonweb.js +0 -0
- {yeref-0.24.62 → yeref-0.24.64}/yeref.egg-info/SOURCES.txt +0 -0
- {yeref-0.24.62 → yeref-0.24.64}/yeref.egg-info/dependency_links.txt +0 -0
- {yeref-0.24.62 → yeref-0.24.64}/yeref.egg-info/top_level.txt +0 -0
@@ -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
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|