feat(growth): same-day 1-day baselines for new videos
Let 1-day view growth use a zero baseline for videos published today, and the first successful sample for older videos ingested today, without mixing those into 7/30-day rankings.
This commit is contained in:
1 parent
8e7ead1669
commit
c5b7185675
21 files changed
+411
-59
No files matched your search
@@ -313,15 +313,20 @@ def compute_growth(
|
||||
current: int | float | None,
|
||||
previous: int | float | None,
|
||||
gap_days: int | float | None,
|
||||
*,
|
||||
allow_zero_gap: bool = False,
|
||||
) -> Growth:
|
||||
"""计算累计差值、日均差值和相对增速。
|
||||
|
||||
缺失基线或间隔不足 1 天时返回不可用,不把 0 当作真实增长。
|
||||
缺失基线或间隔为负时返回不可用。默认间隔不足 1 天也不可用,不把 0 当成真实增长。
|
||||
``allow_zero_gap=True`` 时允许同一天的两次采样(或相对 0)计算增量,``per_day`` 为 None。
|
||||
"""
|
||||
if current is None or previous is None or gap_days is None:
|
||||
return Growth(available=False)
|
||||
gap = int(gap_days)
|
||||
if gap <= 0:
|
||||
if gap < 0:
|
||||
return Growth(available=False)
|
||||
if gap == 0 and not allow_zero_gap:
|
||||
return Growth(available=False)
|
||||
current_value = max(0, int(current))
|
||||
previous_value = max(0, int(previous))
|
||||
@@ -329,7 +334,7 @@ def compute_growth(
|
||||
return Growth(
|
||||
available=True,
|
||||
delta=delta,
|
||||
per_day=delta / gap,
|
||||
per_day=None if gap == 0 else delta / gap,
|
||||
rate=delta / max(previous_value, 1),
|
||||
gap_days=gap,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user