annals.listening#
What each reader has heard of each audio document: percent heard, listens, where they stopped.
The page reports what was played, a few seconds at a time, as spans of the audio’s own
timeline ([[start, end], ...] in seconds). The server keeps the union of those spans
per reader and document, so the percent heard counts each second once, however often it was
replayed or skipped back to, and two devices reporting the same minute add nothing twice.
A listen is counted when playback reaches the end of audio that has been heard almost
whole (DONE_SHARE), so dragging to the end is not a listen; a report carries the
id of the play it belongs to, so a report sent twice (a retry, a page closing) counts one.
A record, per reader and document:
{"heard": [[0.0, 61.5], [90.0, 120.0]], "duration": 300.0, "position": 120.0,
"listens": 1, "done": true, "updated": "2026-11-09T10:00:00+00:00"}
done is the reader’s own mark (“I have heard this”), set or cleared from the page; it
is absent until they set it. status() reads a record as one of STATUSES.
Records live under the data root, one JSON file per reader (listening/<reader>.json),
through annals.jsonstore.JsonFileStore. for_reader() is the seam: any
(reader) -> store callable whose stores are Records can replace it
(mk_api(listening=...)).
>>> merge_spans([[5, 10], [0, 3], [2, 6], [20, 20]])
[[0.0, 10.0]]
>>> rec = apply_report(None, {"spans": [[0, 30]], "duration": 100, "position": 30})
>>> percent(rec), status(rec)
(30, 'started')
>>> apply_report(None, {"spans": [[95, 100]], "duration": 100, "ended": "p0"})["listens"] # dragged to the end
0
>>> rec = apply_report(rec, {"spans": [[30, 100]], "duration": 100, "position": 100, "ended": "p1"})
>>> rec = apply_report(rec, {"spans": [], "duration": 100, "position": 100, "ended": "p1"})
>>> percent(rec), rec["listens"], status(rec)
(100, 1, 'done')
Module Attributes
what a record reads as, in the order the page offers them as filters |
|
heard at least this share of the audio counts as done, without a listen to the end |
|
heard less than this many seconds is not started (a stray tap on play) |
|
at most this many separate spans are kept; past it the closest ones are joined |
|
a report holds at most this many spans |
|
longest audio a report may claim, in seconds (a sanity bound, not a feature limit) |
|
the plays that reached the end, remembered so a retried report counts none twice |
Functions
|
|
|
|
|
The default seam: each reader's records in |
|
How many distinct seconds of the audio were heard. |
|
The union of |
|
The share of the audio heard, 0 to 100 (0 while the duration is unknown). |
|
The file name a reader's records are kept under: their identity, percent-encoded. |
|
|
|
A record as the page shows it: the record plus |
Classes
|
One reader's records: |
|
One reader's records, as the API uses them. |
- annals.listening.DONE_SHARE = 0.95#
heard at least this share of the audio counts as done, without a listen to the end
- class annals.listening.ListeningStore(path)[source]#
Bases:
JsonFileStoreOne reader’s records:
{doc id: record}in one JSON file.
- annals.listening.MAX_DURATION_S = 86400#
longest audio a report may claim, in seconds (a sanity bound, not a feature limit)
- annals.listening.MAX_REPORT_SPANS = 500#
a report holds at most this many spans
- annals.listening.MAX_SPANS = 200#
at most this many separate spans are kept; past it the closest ones are joined
- annals.listening.MIN_STARTED_S = 3.0#
heard less than this many seconds is not started (a stray tap on play)
- annals.listening.RECENT_PLAYS = 20#
the plays that reached the end, remembered so a retried report counts none twice
- class annals.listening.Records(*args, **kwargs)[source]#
Bases:
ProtocolOne reader’s records, as the API uses them.
- annals.listening.STATUSES = ('not_started', 'started', 'done')#
what a record reads as, in the order the page offers them as filters
- annals.listening.apply_mark(record, done)[source]#
recordwith the reader’s own mark set (True/False) or cleared (None).
- annals.listening.apply_report(record, report)[source]#
recordwith a report from the page folded in. RaisesValueErroron a bad report.A report:
{"spans": [[a, b], ...], "duration": s, "position": s, "ended"?: play_id}.endednames the play that reached the end; each play id counts one listen.- Return type:
- annals.listening.for_reader(root)[source]#
The default seam: each reader’s records in
<root>/listening/<reader>.json.
- annals.listening.heard_seconds(record)[source]#
How many distinct seconds of the audio were heard.
- Return type:
- annals.listening.merge_spans(spans, *, max_spans=200)[source]#
The union of
spansas sorted, disjoint[start, end]pairs; empty spans dropped.Past
max_spanspairs, the ones with the smallest gap between them are joined, so a record stays small whatever a reader does (the percent heard can only grow by that).
- annals.listening.percent(record)[source]#
The share of the audio heard, 0 to 100 (0 while the duration is unknown).
- Return type:
- annals.listening.reader_file(reader)[source]#
The file name a reader’s records are kept under: their identity, percent-encoded.
The encoding is one-to-one, so two readers never share a file, and never a path.
- Return type: