yeref 0.24.69__tar.gz → 0.24.70__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.69 → yeref-0.24.70}/PKG-INFO +1 -1
- {yeref-0.24.69 → yeref-0.24.70}/setup.py +1 -1
- {yeref-0.24.69 → yeref-0.24.70}/yeref/yeref.py +70 -40
- {yeref-0.24.69 → yeref-0.24.70}/yeref.egg-info/PKG-INFO +1 -1
- {yeref-0.24.69 → yeref-0.24.70}/pyproject.toml +0 -0
- {yeref-0.24.69 → yeref-0.24.70}/setup.cfg +0 -0
- {yeref-0.24.69 → yeref-0.24.70}/yeref/__init__.py +0 -0
- {yeref-0.24.69 → yeref-0.24.70}/yeref/l_.py +0 -0
- {yeref-0.24.69 → yeref-0.24.70}/yeref/tonweb.js +0 -0
- {yeref-0.24.69 → yeref-0.24.70}/yeref.egg-info/SOURCES.txt +0 -0
- {yeref-0.24.69 → yeref-0.24.70}/yeref.egg-info/dependency_links.txt +0 -0
- {yeref-0.24.69 → yeref-0.24.70}/yeref.egg-info/top_level.txt +0 -0
@@ -16240,7 +16240,7 @@ async def return_cohort_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
|
|
16240
16240
|
|
16241
16241
|
months = ["2025-06", "2025-07", "2025-08", "2025-09"]
|
16242
16242
|
data_users = []
|
16243
|
-
for _ in range(
|
16243
|
+
for _ in range(30):
|
16244
16244
|
# дата входа
|
16245
16245
|
entry_month = random.choice(months)
|
16246
16246
|
entry_day = random.randint(1, 28)
|
@@ -16302,7 +16302,6 @@ async def return_cohort_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
|
|
16302
16302
|
))
|
16303
16303
|
print(f"gen {data_users=}")
|
16304
16304
|
|
16305
|
-
|
16306
16305
|
cohorts = defaultdict(set)
|
16307
16306
|
activity_months = defaultdict(set)
|
16308
16307
|
|
@@ -16365,7 +16364,7 @@ async def return_cohort_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
|
|
16365
16364
|
row.append(str(val))
|
16366
16365
|
row_sum += val
|
16367
16366
|
else:
|
16368
|
-
row.append("")
|
16367
|
+
row.append("0")
|
16369
16368
|
|
16370
16369
|
row.append(str(row_sum))
|
16371
16370
|
table.append(row)
|
@@ -16391,7 +16390,7 @@ async def return_cohort_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
|
|
16391
16390
|
for r in table:
|
16392
16391
|
writer.writerow(r)
|
16393
16392
|
writer.writerow([])
|
16394
|
-
writer.writerow([f"Churn ~ ×{avg_churn:.
|
16393
|
+
writer.writerow([f"Churn ~ ×{avg_churn:.0f} monthly"])
|
16395
16394
|
|
16396
16395
|
thumb = types.FSInputFile(os.path.join(EXTRA_D, "parse.jpg"))
|
16397
16396
|
await bot.send_document(chat_id=my_tid, document=types.FSInputFile(path), thumbnail=thumb)
|
@@ -16401,7 +16400,6 @@ async def return_cohort_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
|
|
16401
16400
|
await asyncio.sleep(round(random.uniform(0, 1), 2))
|
16402
16401
|
|
16403
16402
|
|
16404
|
-
|
16405
16403
|
async def return_retention_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
|
16406
16404
|
try:
|
16407
16405
|
sql = 'SELECT USER_TID, USER_VARS, USER_LSTS FROM "USER"'
|
@@ -16409,7 +16407,7 @@ async def return_retention_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
|
|
16409
16407
|
|
16410
16408
|
months = ["2025-06", "2025-07", "2025-08", "2025-09"]
|
16411
16409
|
data_users = []
|
16412
|
-
for _ in range(
|
16410
|
+
for _ in range(30):
|
16413
16411
|
# дата входа
|
16414
16412
|
entry_month = random.choice(months)
|
16415
16413
|
entry_day = random.randint(1, 28)
|
@@ -16471,57 +16469,89 @@ async def return_retention_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
|
|
16471
16469
|
))
|
16472
16470
|
print(f"gen {data_users=}")
|
16473
16471
|
|
16474
|
-
#
|
16475
|
-
|
16472
|
+
# Собираем платежи и дату входа для каждого пользователя
|
16473
|
+
rev_by_cohort = defaultdict(lambda: defaultdict(float))
|
16474
|
+
cohort_users = defaultdict(set)
|
16475
|
+
|
16476
16476
|
for USER_TID, USER_VARS, USER_LSTS in data_users:
|
16477
|
+
USER_VARS = json.loads(USER_VARS or "{}")
|
16477
16478
|
USER_LSTS = json.loads(USER_LSTS or "{}")
|
16479
|
+
dt_entry_raw = USER_VARS.get("USER_DT", "").split("_")[0]
|
16480
|
+
if not dt_entry_raw:
|
16481
|
+
continue
|
16482
|
+
cohort_mo = datetime.strptime(dt_entry_raw, "%d-%m-%Y").strftime("%Y-%m")
|
16483
|
+
cohort_users[cohort_mo].add(USER_TID)
|
16484
|
+
|
16478
16485
|
for pay in USER_LSTS.get("USER_PAYMENTS", []):
|
16479
|
-
|
16480
|
-
|
16486
|
+
dt_pay = datetime.strptime(pay.get("DT_START", ""), "%d-%m-%Y_%H-%M-%S")
|
16487
|
+
pay_mo = dt_pay.strftime("%Y-%m")
|
16488
|
+
# вычисляем разницу в месяцах
|
16489
|
+
y0, m0 = map(int, cohort_mo.split("-"))
|
16490
|
+
y1, m1 = map(int, pay_mo.split("-"))
|
16491
|
+
offset = (y1 - y0) * 12 + (m1 - m0)
|
16492
|
+
if offset < 0:
|
16493
|
+
continue
|
16481
16494
|
amt = float(pay.get("AMOUNT", 0)) * 0.013
|
16482
|
-
|
16495
|
+
rev_by_cohort[cohort_mo][offset] += amt
|
16483
16496
|
|
16484
|
-
|
16485
|
-
|
16486
|
-
|
16487
|
-
|
16488
|
-
|
16489
|
-
|
16490
|
-
results.append({"MO": mo, "NRR": ""})
|
16491
|
-
continue
|
16492
|
-
prev_mo = all_months[idx - 1]
|
16493
|
-
# общая выручка в prev_mo
|
16494
|
-
prev_total = sum(user_month_rev[u][prev_mo] for u in user_month_rev if prev_mo in user_month_rev[u])
|
16495
|
-
if prev_total == 0:
|
16496
|
-
results.append({"MO": mo, "NRR": ""})
|
16497
|
-
continue
|
16498
|
-
# выручка текущего месяца от тех же пользователей
|
16499
|
-
curr_existing = sum(
|
16500
|
-
user_month_rev[u][mo]
|
16501
|
-
for u in user_month_rev
|
16502
|
-
if prev_mo in user_month_rev[u] and mo in user_month_rev[u]
|
16503
|
-
)
|
16504
|
-
nrr = curr_existing / prev_total
|
16505
|
-
results.append({"MO": mo, "NRR": f"{nrr * 100:.2f}"})
|
16497
|
+
cohort_months = sorted(cohort_users.keys())
|
16498
|
+
# Определяем максимальный период
|
16499
|
+
max_offset = 0
|
16500
|
+
for c in cohort_months:
|
16501
|
+
if rev_by_cohort[c]:
|
16502
|
+
max_offset = max(max_offset, max(rev_by_cohort[c].keys()))
|
16506
16503
|
|
16507
|
-
#
|
16508
|
-
|
16509
|
-
avg_nrr = f"{(sum(vals) / len(vals)):.2f}" if vals else ""
|
16504
|
+
# Сумма выручки M1 для каждой когорты
|
16505
|
+
base_rev = {c: rev_by_cohort[c].get(0, 0.0) for c in cohort_months}
|
16510
16506
|
|
16507
|
+
# Формируем CSV-таблицу
|
16511
16508
|
path = os.path.join(EXTRA_D, "4_retention_metrics.csv")
|
16512
16509
|
with open(path, "w", newline="", encoding="utf-8") as f:
|
16513
16510
|
writer = csv.writer(f)
|
16514
|
-
|
16515
|
-
|
16516
|
-
|
16511
|
+
# Заголовок
|
16512
|
+
header = ["Месяц / Когорта"]
|
16513
|
+
for c in cohort_months:
|
16514
|
+
header.append(f"{c} ({len(cohort_users[c])})")
|
16515
|
+
header.append("∑")
|
16516
|
+
writer.writerow(header)
|
16517
|
+
|
16518
|
+
# Строки M1..M{max_offset+1}
|
16519
|
+
for i in range(max_offset + 1):
|
16520
|
+
row_label = f"M{i+1} ({i} мес)"
|
16521
|
+
row = [row_label]
|
16522
|
+
row_sum = 0.0
|
16523
|
+
for c in cohort_months:
|
16524
|
+
rev = rev_by_cohort[c].get(i, 0.0)
|
16525
|
+
if rev > 0 and base_rev[c] > 0:
|
16526
|
+
pct = rev / base_rev[c] * 100
|
16527
|
+
cell = f"{rev:.1f} ({pct:.0f}%)"
|
16528
|
+
row.append(cell)
|
16529
|
+
row_sum += rev
|
16530
|
+
else:
|
16531
|
+
row.append("")
|
16532
|
+
row.append(f"{row_sum:.1f}")
|
16533
|
+
writer.writerow(row)
|
16534
|
+
|
16535
|
+
# Средний рост NRR
|
16536
|
+
growths = []
|
16537
|
+
for c in cohort_months:
|
16538
|
+
for i in range(1, max_offset + 1):
|
16539
|
+
prev = rev_by_cohort[c].get(i - 1, 0.0)
|
16540
|
+
curr = rev_by_cohort[c].get(i, 0.0)
|
16541
|
+
if prev > 0:
|
16542
|
+
growths.append((curr - prev) / prev)
|
16543
|
+
avg_growth = (sum(growths) / len(growths) * 100) if growths else 0.0
|
16544
|
+
|
16517
16545
|
writer.writerow([])
|
16518
|
-
writer.writerow([f"Avg NRR
|
16546
|
+
writer.writerow([f"Avg monthly NRR growth:", f"{avg_growth:.2f}%"])
|
16519
16547
|
|
16520
16548
|
thumb = types.FSInputFile(os.path.join(EXTRA_D, "parse.jpg"))
|
16521
16549
|
await bot.send_document(chat_id=my_tid, document=types.FSInputFile(path), thumbnail=thumb)
|
16550
|
+
|
16522
16551
|
except Exception as e:
|
16523
16552
|
logger.info(log_ % str(e))
|
16524
16553
|
await asyncio.sleep(round(random.uniform(0, 1), 2))
|
16554
|
+
|
16525
16555
|
# endregion
|
16526
16556
|
|
16527
16557
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|