Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
122 lines
4.7 KiB
Python
122 lines
4.7 KiB
Python
"""Growth Digest — pure aggregation over data this account already has.
|
|
|
|
Python port of ``apps/web/src/features/growth-digest/digest.ts`` (kept in
|
|
sync deliberately — same constants, same rules), reused here so the weekly
|
|
email and the dashboard page always agree on what "winning" and "dying" mean.
|
|
|
|
Every input is a plain dict already returned by
|
|
:func:`app.services.hook_performance.winning_hooks`,
|
|
:func:`app.services.hook_performance.winning_templates` and
|
|
:func:`app.services.insights.user_insights` — real, self-reported, per-user
|
|
data. Nothing here calls the network, mutates anything, or sends a message:
|
|
it is a pure read a human looks at and acts on themselves.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Optional
|
|
|
|
#: A hook needs at least this many logged reels before "low score" means anything.
|
|
DYING_MIN_REELS: int = 2
|
|
#: Below this fraction of the best score (with enough reels), a hook is "dying".
|
|
DYING_SCORE_RATIO: float = 0.25
|
|
#: How many hooks/templates each list shows.
|
|
ROTATION_LIMIT: int = 5
|
|
|
|
|
|
def hook_rotation(
|
|
hooks: list[dict[str, Any]], limit: int = ROTATION_LIMIT
|
|
) -> dict[str, list[dict[str, Any]]]:
|
|
"""Split the account's logged hooks into "keep running" and "stop running"."""
|
|
logged = [h for h in hooks if int(h.get("reels", 0) or 0) > 0]
|
|
winning = sorted(logged, key=lambda h: -float(h.get("win_score", 0) or 0))[:limit]
|
|
best = float(winning[0]["win_score"]) if winning else 0.0
|
|
dying: list[dict[str, Any]] = []
|
|
if best > 0:
|
|
dying = sorted(
|
|
(
|
|
h
|
|
for h in logged
|
|
if int(h.get("reels", 0) or 0) >= DYING_MIN_REELS
|
|
and float(h.get("win_score", 0) or 0) < best * DYING_SCORE_RATIO
|
|
),
|
|
key=lambda h: float(h.get("win_score", 0) or 0),
|
|
)[:limit]
|
|
return {"winning": winning, "dying": dying}
|
|
|
|
|
|
def hook_variations(hook: str) -> list[str]:
|
|
"""Deterministic, rule-based starter variations on a proven hook.
|
|
|
|
These are NOT AI-generated and are not claimed to be — they are plain
|
|
rewrites of the account's own best-logged hook, meant to be edited before
|
|
use, same spirit as the "5 new variations of the winners to test next"
|
|
step in the Viktor pattern but with zero model cost and no new required
|
|
input.
|
|
"""
|
|
trimmed = hook.strip().rstrip(".?!").strip()
|
|
if not trimmed:
|
|
return []
|
|
lower = trimmed[0].lower() + trimmed[1:]
|
|
return [
|
|
f"Stop scrolling: {lower}",
|
|
f"POV: {lower}",
|
|
f"Nobody told you this — {lower}",
|
|
]
|
|
|
|
|
|
def draft_creator_brief(
|
|
winning_hooks: list[dict[str, Any]], winning_templates: list[dict[str, Any]]
|
|
) -> Optional[dict[str, Any]]:
|
|
"""Draft (never sent) a creator brief from this account's own best-logged
|
|
hook/template. Returns ``None`` when there is nothing logged yet — the
|
|
caller should prompt the user to log a reel's performance first rather
|
|
than show a brief built on no data.
|
|
"""
|
|
top = winning_hooks[0] if winning_hooks else None
|
|
if not top:
|
|
return None
|
|
reels = int(top.get("reels", 0) or 0)
|
|
templates = winning_templates[0].get("template") if winning_templates else None
|
|
return {
|
|
"headline": f"This week's brief — built from {reels} of your own logged reel{'' if reels == 1 else 's'}",
|
|
"proven_hook": top.get("hook", ""),
|
|
"proven_template": templates,
|
|
"test_hooks": hook_variations(str(top.get("hook", ""))),
|
|
"note": "Draft only — nothing is sent to a creator or posted automatically. Copy what you want to use.",
|
|
}
|
|
|
|
|
|
def has_growth_digest_access(plan: dict[str, Any] | None) -> bool:
|
|
"""Whether the account's plan unlocks the Growth Digest (any paid personal plan).
|
|
|
|
Mirrors ``hasGrowthDigestAccess`` in the web feature: truthy ``plan`` (the
|
|
same shape returned by ``GET /billing/monthly-plan``'s ``"plan"`` key).
|
|
"""
|
|
return bool(plan)
|
|
|
|
|
|
def daily_digest_line(insights: dict[str, Any] | None) -> str:
|
|
"""A short "today" line from ``user_insights``, for the daily-digest section."""
|
|
if not insights:
|
|
return ""
|
|
complete = int((insights.get("jobs_by_state") or {}).get("complete", 0) or 0)
|
|
videos = max(0, int(insights.get("videos_generated", 0) or 0))
|
|
credits = max(0, int(insights.get("credits_balance", 0) or 0))
|
|
return (
|
|
f"{videos} reel{'' if videos == 1 else 's'} made all-time, "
|
|
f"{complete} finished so far, {credits} credit{'' if credits == 1 else 's'} left."
|
|
)
|
|
|
|
|
|
__all__ = [
|
|
"DYING_MIN_REELS",
|
|
"DYING_SCORE_RATIO",
|
|
"ROTATION_LIMIT",
|
|
"daily_digest_line",
|
|
"draft_creator_brief",
|
|
"has_growth_digest_access",
|
|
"hook_rotation",
|
|
"hook_variations",
|
|
]
|