videogen/scripts/funnel-readout.py
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
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.
2026-12-04 02:10:26 +03:00

86 lines
3.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""Funnel read-out on the command line (MR1). Read-only.
Prints one line per user who signed up since ``--since`` (default 2026-09-25):
sign-up, card check, first render, first kept reel, first payment, plan and
source, then the totals. ``--json`` prints the same payload the admin page
reads (the scoreboard, XR-D2, reads it too). ``--sync`` first runs the
idempotent funnel sync (``app.services.funnel.store.sync_events``), which only
inserts missing first-time rows into ``funnel_events``.
Uses the API's configured database (``DATABASE_URL``). Run from the repo root:
PYTHONPATH=apps/api python scripts/funnel-readout.py --since 2026-09-25
"""
from __future__ import annotations
import argparse
import json
import sys
from datetime import datetime, timezone
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "apps" / "api"))
COLUMNS = (
("signed_up", "signed up"),
("card_check", "card"),
("first_render", "render"),
("first_kept", "kept"),
("first_payment", "paid"),
("plan", "plan"),
("source", "source"),
("utm_source", "utm_source"),
("utm_campaign", "campaign"),
("referrer", "referrer"),
)
def _day(value: str | None) -> str:
return value[:10] if value else "no"
def render_table(payload: dict) -> str:
lines = ["\t".join(["user"] + [label for _, label in COLUMNS])]
for row in payload["rows"]:
cells = [row["user_id"][:8]]
for key, _ in COLUMNS:
value = row[key]
cells.append(_day(value) if key in ("signed_up", "card_check", "first_render",
"first_kept", "first_payment") else str(value))
lines.append("\t".join(cells))
totals = payload["totals"]
lines.append("")
lines.append(f"users: {totals['users']}")
lines.append("reach: " + ", ".join(f"{k}={v}" for k, v in totals["reach"].items()))
lines.append("source: " + ", ".join(f"{k}={v}" for k, v in sorted(totals["by_source"].items())))
lines.append("plan: " + ", ".join(f"{k}={v}" for k, v in sorted(totals["by_plan"].items())))
return "\n".join(lines)
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("--since", default="2026-09-25", help="YYYY-MM-DD (UTC)")
parser.add_argument("--json", action="store_true", help="print the JSON payload")
parser.add_argument("--sync", action="store_true", help="run the idempotent funnel sync first")
args = parser.parse_args(argv)
since = datetime.strptime(args.since, "%Y-%m-%d").replace(tzinfo=timezone.utc)
import app.models.db.base as db_base
from app.domains.funnel_readout.service import readout_payload
if args.sync:
from app.services.funnel.store import sync_events
print(json.dumps({"sync": sync_events()}), file=sys.stderr)
with db_base.get_session() as session:
payload = readout_payload(session, since)
print(json.dumps(payload, indent=2) if args.json else render_table(payload))
return 0
if __name__ == "__main__":
raise SystemExit(main())