Files
OrbitTv/tools/taste-report.py
T

73 lines
3.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""Taste Stage 1 review (9 November 2026): reads the Taste events in one or more install snapshots and prints the
findings as Markdown. Read-only; works on snapshots already pulled (backups/<install>/after), never on the TV.
Usage: taste-report.py <snapshot-dir> [<another room's snapshot-dir> ...]
"""
import collections, datetime, glob, html, json, os, re, sys
BRIEF_MS, STAYED_MS = 5 * 60_000, 20 * 60_000
def profiles(snap):
p = os.path.join(snap, "shared_prefs/orbit_profiles.xml")
if not os.path.exists(p):
return {}
m = re.search(r'name="profiles">(.*?)</string>', open(p).read(), re.S)
return {x["id"]: (x["name"], x["kind"]) for x in json.loads(html.unescape(m.group(1)))} if m else {}
def events(snap):
out = collections.defaultdict(list)
for f in glob.glob(os.path.join(snap, "no_backup/schedule/taste/*.events.jsonl")):
for line in open(f):
try:
e = json.loads(line)
except ValueError:
out["damaged"].append(line)
continue
out[e.get("p", "?")].append(e)
return out
def day(ms):
return datetime.datetime.fromtimestamp(ms / 1000).strftime("%a %d %b")
def report(snaps):
print(f"# Taste Stage 1 findings, from {len(snaps)} snapshot(s)\n")
rooms = [(s, profiles(s), events(s)) for s in snaps]
for snap, people, evs in rooms:
print(f"## {os.path.basename(os.path.dirname(snap.rstrip('/')))}\n")
size = sum(os.path.getsize(f) for f in glob.glob(os.path.join(snap, "no_backup/schedule/taste/*")))
print(f"Storage: {size:,} bytes in {len(glob.glob(os.path.join(snap, 'no_backup/schedule/taste/*')))} files.\n")
for pid, (name, kind) in people.items():
ev = sorted(evs.get(pid, []), key=lambda e: e["w"])
print(f"### {name} ({kind}): {len(ev)} events")
if not ev:
print("No events recorded.\n")
continue
print(f"- From {day(ev[0]['w'])} to {day(ev[-1]['w'])}, on {len({day(e['w']) for e in ev})} days")
print("- Kinds: " + ", ".join(f"{k} {n}" for k, n in collections.Counter(e["k"] for e in ev).most_common()))
print("- Sources: " + ", ".join(f"{k} {n}" for k, n in collections.Counter(e["src"] for e in ev).most_common()))
print("- Channels: " + ", ".join(f"{k} {n}" for k, n in collections.Counter(e["c"] for e in ev).most_common(8)))
fin = [e for e in ev if e["k"] == "finished"]
quick = [e for e in fin if (e.get("ms") or 0) < BRIEF_MS]
print(f"- Finished with under 5 minutes watched: {len(quick)} of {len(fin)} (tuned in near the end; weighted 2.0 today)")
pairs = sum(1 for a, b in zip(ev, ev[1:]) if a["k"] == "brief" and b["k"] == "finished" and a["i"] == b["i"])
print(f"- A brief visit followed by finished on the same title: {pairs}")
dup = [k for k, n in collections.Counter((e["k"], e["i"]) for e in ev).items() if n > 1]
print(f"- Same kind on the same title more than once: {len(dup)}")
titles = collections.Counter(e["t"] for e in ev if e["k"] in ("finished", "stayed", "chose", "saved"))
print("- Strongest titles: " + "; ".join(f"{t} ({n})" for t, n in titles.most_common(6)))
print()
stray = [p for p in evs if p not in people]
if stray:
print(f"Events for profiles that no longer exist (or damaged lines): {', '.join(f'{p} {len(evs[p])}' for p in stray)}\n")
if len(rooms) > 1:
ids = [{e["id"] for v in r[2].values() for e in v if isinstance(e, dict)} for r in rooms]
print(f"## Rooms\nEvents in every room: {len(set.intersection(*ids))}; only in one room: {len(set.union(*ids) - set.intersection(*ids))}.\n")
if __name__ == "__main__":
report(sys.argv[1:])