watched: single DONE_RATIO source constant replaces the seven hardcoded 0.95 literals
server/app.py DONE_RATIO is injected into index.html like {{VERSION}}, app.js
reads it as window.DONE_RATIO (fallback = same default). Change the threshold
in exactly one place now.
This commit is contained in:
1 parent
5f7aa010f1
commit
731f44b99c
3 files changed
+22
-9
No files matched your search
+10
-3
@@ -44,6 +44,11 @@ def _version():
|
||||
|
||||
VERSION = _version()
|
||||
|
||||
# An episode counts as "watched" once you're this far through it (fraction of
|
||||
# duration). One knob for client + server: injected into index.html below so
|
||||
# app.js uses the same value as these stats. Change here only.
|
||||
DONE_RATIO = 0.95
|
||||
|
||||
# latest probe result + last 20 samples (~1h at 3-min spacing), for GET /api/cdn
|
||||
_CDN = {"state": "unknown", "kbps": 0.0, "ts": 0.0, "hist": []}
|
||||
# origin (primary provider pages/API) health — separate host, separate failure
|
||||
@@ -455,7 +460,7 @@ def api_stats(request: Request, days: int = Query(30, ge=1, le=365),
|
||||
if s["last_ts"] > a["last_seen"]:
|
||||
a["last_seen"] = s["last_ts"]
|
||||
a["cur_ep"] = s["last_ep"]
|
||||
if s["dur"] > 0 and s["max"] >= s["dur"] * 0.95:
|
||||
if s["dur"] > 0 and s["max"] >= s["dur"] * DONE_RATIO:
|
||||
a["completed"] += 1
|
||||
completed += 1
|
||||
now = time.time()
|
||||
@@ -700,8 +705,10 @@ def stream(token: str):
|
||||
@app.get("/index.html", include_in_schema=False)
|
||||
def index():
|
||||
# index.html is served (not mounted) so ?v={{VERSION}} becomes the git
|
||||
# SHA at startup; other statics go through the mount below
|
||||
return HTMLResponse(_INDEX_HTML.replace("{{VERSION}}", VERSION))
|
||||
# SHA and {{DONE_RATIO}} the watched threshold at startup; other statics
|
||||
# go through the mount below
|
||||
return HTMLResponse(_INDEX_HTML.replace("{{VERSION}}", VERSION)
|
||||
.replace("{{DONE_RATIO}}", repr(DONE_RATIO)))
|
||||
|
||||
|
||||
_INDEX_HTML = (ROOT / "static" / "index.html").read_text()
|
||||
|
||||
Reference in new issue
Block a user