caelum0x d56639a594
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
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

70 lines
3.3 KiB
Python

"""QoE beacons and hourly rollups (MV12); migration c9f1b3d5e7a0.
Numbers come only from our own player beacons: no third-party tracker. The
viewer is stored as a salted hash (never an email, IP or account id) and raw
beacons are kept 30 days; the hourly rollups keep the totals.
"""
from __future__ import annotations
import uuid
from datetime import datetime
from sqlalchemy import DateTime, Float, Index, Integer, String, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column
from app.models.db.base import Base
EVENTS = ("start", "heartbeat", "stall", "bitrate", "error", "end")
def _id() -> str:
return uuid.uuid4().hex
class OttBeacon(Base):
__tablename__ = "ott_beacons"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_id)
channel_id: Mapped[str] = mapped_column(String(32), nullable=False)
title_id: Mapped[str] = mapped_column(String(32), nullable=False)
session_id: Mapped[str] = mapped_column(String(40), nullable=False)
viewer_hash: Mapped[str] = mapped_column(String(32), nullable=False)
event: Mapped[str] = mapped_column(String(12), nullable=False)
hour: Mapped[str] = mapped_column(String(13), nullable=False)
watched_s: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
startup_ms: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
stall_ms: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
bitrate_kbps: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
error_code: Mapped[str] = mapped_column(String(40), nullable=False, default="")
device: Mapped[str] = mapped_column(String(12), nullable=False, default="web")
country: Mapped[str] = mapped_column(String(2), nullable=False, default="XX")
received_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
__table_args__ = (Index("ix_ott_beacons_title_hour", "title_id", "hour"),
Index("ix_ott_beacons_received", "received_at"))
class OttQoeHourly(Base):
__tablename__ = "ott_qoe_hourly"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_id)
channel_id: Mapped[str] = mapped_column(String(32), nullable=False)
title_id: Mapped[str] = mapped_column(String(32), nullable=False)
hour: Mapped[str] = mapped_column(String(13), nullable=False)
plays: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
viewers: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
watch_s: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
startup_p50_ms: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
startup_p95_ms: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
stalls: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
stall_ms: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
errors: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
beacons: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
__table_args__ = (UniqueConstraint("title_id", "hour", name="uq_ott_qoe_hourly_title_hour"),
Index("ix_ott_qoe_hourly_channel_hour", "channel_id", "hour"))
__all__ = ["EVENTS", "OttBeacon", "OttQoeHourly"]