yeref 0.24.76__tar.gz → 0.24.77__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.24.76
3
+ Version: 0.24.77
4
4
  Summary: desc-f
5
5
  Author: john smith
6
6
  Dynamic: author
@@ -2,7 +2,7 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='yeref',
5
- version='0.24.76',
5
+ version='0.24.77',
6
6
  description='desc-f',
7
7
  author='john smith',
8
8
  packages=['yeref'],
@@ -16496,54 +16496,58 @@ async def return_retention_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
16496
16496
  if not cohort_months:
16497
16497
  return
16498
16498
 
16499
- # Функция прибавления месяцев
16500
- def add_months(mo_str, n):
16501
- y, m = map(int, mo_str.split("-"))
16502
- total = m + n
16503
- new_y = y + (total - 1) // 12
16504
- new_m = (total - 1) % 12 + 1
16505
- return f"{new_y:04d}-{new_m:02d}"
16506
-
16507
- num_cohorts = len(cohort_months)
16508
- first_cohort = cohort_months[0]
16499
+ # вычисляем максимальный offset (M-1)
16500
+ max_offset = 0
16501
+ for c in cohort_months:
16502
+ if rev_by_cohort[c]:
16503
+ max_offset = max(max_offset, max(rev_by_cohort[c].keys()))
16509
16504
 
16510
16505
  path = os.path.join(EXTRA_D, "4_retention_metrics.csv")
16511
16506
  with open(path, "w", newline="", encoding="utf-8") as f:
16512
16507
  writer = csv.writer(f)
16508
+
16509
+ # заголовок
16513
16510
  header = ["Месяц/Когорта"] + [
16514
- f"{c} ({len(cohort_users[c])})" for c in cohort_months
16511
+ f"{c} ({len(cohort_users[c])})"
16512
+ for c in cohort_months
16515
16513
  ] + ["∑"]
16516
16514
  writer.writerow(header)
16517
16515
 
16518
- for i in range(num_cohorts):
16519
- calendar_mo = add_months(first_cohort, i)
16516
+ # строки M1..M{max_offset+1} по offset
16517
+ for i in range(max_offset + 1):
16520
16518
  row = [f"M{i+1}"]
16521
16519
  row_sum = 0.0
16522
16520
  for c in cohort_months:
16523
- y0, m0 = map(int, c.split("-"))
16524
- y1, m1 = map(int, calendar_mo.split("-"))
16525
- offset = (y1 - y0) * 12 + (m1 - m0)
16526
- if offset < 0:
16527
- row.append("")
16521
+ rev = rev_by_cohort[c].get(i, 0.0)
16522
+ if rev > 0:
16523
+ cell = f"{rev:.1f}"
16524
+ row.append(cell)
16525
+ row_sum += rev
16528
16526
  else:
16529
- rev = rev_by_cohort[c].get(offset, 0.0)
16530
- if rev > 0:
16531
- cell = f"{rev:.1f}"
16532
- row.append(cell)
16533
- row_sum += rev
16534
- else:
16535
- row.append("")
16527
+ row.append("")
16536
16528
  row.append(f"{row_sum:.1f}")
16537
16529
  writer.writerow(row)
16538
16530
 
16531
+ # вычисляем средний NRR-множитель (геометрическое среднее факторов роста)
16532
+ import math
16533
+ factors = []
16534
+ for c in cohort_months:
16535
+ for i in range(1, max_offset + 1):
16536
+ prev_rev = rev_by_cohort[c].get(i - 1, 0.0)
16537
+ curr_rev = rev_by_cohort[c].get(i, 0.0)
16538
+ if prev_rev > 0 and curr_rev > 0:
16539
+ factors.append(curr_rev / prev_rev)
16540
+ avg_multiplier = math.prod(factors) ** (1 / len(factors)) if factors else 1.0
16541
+
16542
+ writer.writerow([])
16543
+ writer.writerow([f"NRR ~ ×{avg_multiplier:.2f} monthly"])
16544
+
16539
16545
  thumb = types.FSInputFile(os.path.join(EXTRA_D, "parse.jpg"))
16540
16546
  await bot.send_document(chat_id=my_tid, document=types.FSInputFile(path), thumbnail=thumb)
16541
-
16542
16547
  except Exception as e:
16543
16548
  logger.info(log_ % str(e))
16544
16549
  await asyncio.sleep(round(random.uniform(0, 1), 2))
16545
16550
 
16546
-
16547
16551
  # endregion
16548
16552
 
16549
16553
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.24.76
3
+ Version: 0.24.77
4
4
  Summary: desc-f
5
5
  Author: john smith
6
6
  Dynamic: author
File without changes
File without changes
File without changes
File without changes
File without changes