mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Fixes media consumption tracking, statistics, and reader page counting
This commit is contained in:
1 parent
e56712731f
commit
02bcf91661
40 files changed
+298
-168
No files matched your search
@@ -365,7 +365,7 @@ The optional `libraryId`, `mediaKind`, `fromUtc` and `toUtc` filters are the sam
|
||||
]
|
||||
```
|
||||
|
||||
The records are grouped to one row per media kind, media item and library first, so an item with several sessions contributes its tags once, not once per session. Only items in an accessible library with at least one counted session contribute. A name that appears twice on the same item contributes once. Names are normalized to lowercase, so `Horror` and `horror` share one bucket across media kinds. The rows are ordered by consumed item count, then consumed duration, both descending, with the name ascending as the tiebreaker. An item that no longer exists, or that moved to another library after it was consumed, does not contribute to the breakdown, because its terms cannot be resolved for the recorded library.
|
||||
The records are grouped to one row per media kind, media item and library first, so an item with several sessions contributes its tags once, not once per session. A music track with no tags of its own contributes the tags of its album, and then the tags of its artist when the album has none. Only items in an accessible library with at least one counted session contribute. A name that appears twice on the same item contributes once. Names are normalized to lowercase, so `Horror` and `horror` share one bucket across media kinds. The rows are ordered by consumed item count, then consumed duration, both descending, with the name ascending as the tiebreaker. An item that no longer exists, or that moved to another library after it was consumed, does not contribute to the breakdown, because its terms cannot be resolved for the recorded library.
|
||||
|
||||
`consumedItemCount` is the number of distinct items that carry the tag, not the number of sessions. `consumedDurationInSeconds` is the consumed duration of those items, over all of their sessions.
|
||||
|
||||
@@ -408,7 +408,7 @@ The optional `libraryId`, `mediaKind`, `fromUtc` and `toUtc` filters are the sam
|
||||
]
|
||||
```
|
||||
|
||||
The genre breakdown follows the same item level aggregation, lowercase normalization, ordering and availability rules as the tag breakdown.
|
||||
The genre breakdown follows the same item level aggregation, lowercase normalization, ordering and availability rules as the tag breakdown. A music track with no genres of its own contributes the genres of its album, and then the genres of its artist when the album has none.
|
||||
|
||||
### Delete Consumption Record
|
||||
|
||||
@@ -554,7 +554,7 @@ Every route in this document requires authentication.
|
||||
|
||||
The statistics and lists never expose the history of another user to a regular user. Display data is resolved per distinct library through the library ownership policy. An item in a library the current user can no longer access keeps its counts but has blank display data, so the history lists reveal no inaccessible title, collection, creator or cover. The service wide totals never include the records of a user that the caller cannot target.
|
||||
|
||||
Deleting a record, every record of an item, the whole history, or the resume points belongs to the same access rule. An administrator can delete any user's consumption activity through the per-user routes, and a regular user can delete only their own.
|
||||
Deleting a record, every record of an item, the whole history, or the resume points belongs to the same access rule. An administrator can delete any user's consumption activity through the per-user routes, and a regular user can delete only their own. Reading a resume point is not part of this surface; it stays owner only, as documented in [Media Consumption](../../media-consumption/Api.MediaConsumption.md).
|
||||
|
||||
### Private Responses
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ A session of a non-page-based kind cannot report consecutive pages above zero. A
|
||||
|
||||
A book page count of 5 does not count as a session for statistics, while 6 does, but that counting rule belongs to the statistics read model and does not change the stored progress.
|
||||
|
||||
The book reader counts spine sections as pages, because the reader exposes no pagination finer than a section. A PDF page is a section of its own, but a reflowable book can put a whole chapter, or several pages, in one section, so the reported page count approximates the pages a reader saw and the threshold counts sections rather than printed or viewport pages.
|
||||
The book reader counts a page as one visible reader viewport. A PDF page is a section of its own, while a reflowable section can hold several viewport pages, so the reported page count follows the pages the reader actually scrolled through rather than the printed pages of the source book.
|
||||
|
||||
#### Report Consumption Progress Response
|
||||
|
||||
@@ -463,6 +463,8 @@ Returns the resume point of the current user for the item named by the route. A
|
||||
|
||||
When the media item no longer exists, or no longer belongs to the library recorded in the resume point, the resume point is an orphan. It is deleted before the item is reported as not found. A client that reopens the item must therefore fall back to the beginning instead of assuming the stored point still exists.
|
||||
|
||||
When the library that recorded the resume point no longer tracks consumption progress, the stored resume point is deleted and reported as `MediaResumePointNotFound`, so turning tracking off takes effect for an existing position as well.
|
||||
|
||||
A kind whose catalogue does not exist yet is rejected with `UnsupportedMediaKind`, so a planned kind cannot return a resume point that start would never create. A photo is the exception among the planned kinds: it has no position representation, so it is rejected with `MediaKindCannotResume`. The invalid `None` kind is rejected with `UnsupportedMediaKind`.
|
||||
|
||||
#### Get Resume Point Response
|
||||
@@ -620,7 +622,7 @@ Errors are returned as problem details. A request without a valid token is rejec
|
||||
| `404` | `TrackNotFound` | The start route names a music track that does not exist, or that does not belong to the route library, or a resume point names a track that no longer exists or no longer belongs to its recorded library. |
|
||||
| `404` | `BookNotFound` | The start route names a book that does not exist, or that does not belong to the route library, or a resume point names a book that no longer exists or no longer belongs to its recorded library. |
|
||||
| `404` | `ConsumptionRecordNotFound` | The record does not exist, or it belongs to another user. |
|
||||
| `404` | `MediaResumePointNotFound` | The resume point does not exist, or it belongs to another user. |
|
||||
| `404` | `MediaResumePointNotFound` | The resume point does not exist, belongs to another user, or belongs to a library that no longer tracks consumption progress. |
|
||||
| `409` | `ConsumptionIsNotInProgress` | A progress report targets a session that is already completed or stopped. |
|
||||
| `409` | `ConsumptionIsAlreadyTerminal` | A complete or stop request targets a session that is already completed or stopped. |
|
||||
| `409` | `ConcurrencyConflict` | Another request changed the same row after this request read it, or the storage reported a busy or locked database. Repeating the request is safe when it reports the current values. |
|
||||
|
||||
+3
-3
@@ -33,8 +33,8 @@ The decision includes these rules:
|
||||
- **Completion is explicit or threshold based.** A session stopped at or after the library completion threshold is recorded as `Completed` and its resume point is deleted. Completion never requires playback to the final second of a media file. A library that tracks progress without a completion threshold completes only when completion is reported explicitly.
|
||||
- **Progress tracking and completion thresholds are per-library settings.** `ShouldTrackConsumptionProgress` and `CompletionThresholdPercentage` live in `LibraryConsumptionSettings` on the library aggregate. Defaults are applied by library type when a library is created, and when progress tracking is enabled later without a threshold. The per-library value always wins once it is set.
|
||||
- **Statistics are derived, never stored.** `ConsumptionStatistics` aggregates the records in the application layer on every request. There is no rollup table, no projection table and no counter aggregate, so deleting a record changes the statistics immediately. The `MediaConsumptionRule` value objects own the counting rules per media kind.
|
||||
- **Tags and genres are lowercase and shared across kinds.** `Tag` and `Genre` normalize names with `Trim().ToLowerInvariant()`, and the statistics group them by that normalized name across media kinds. The application resolves the terms of each consumed record through the catalogue repository of its media kind, in a per-kind branch, and the photo branch is added when the photo catalogue exists.
|
||||
- **Access is based on the user and the administrator role.** A regular user reads and deletes only their own history, statistics and resume points. An administrator reads and deletes any user's history, statistics and resume points. There is no per-user permission toggle. Lifecycle writes (`start`, `progress`, `complete`, `stop`) are owner only, so an administrator does not write another user's session.
|
||||
- **Tags and genres are lowercase and shared across kinds.** `Tag` and `Genre` normalize names with `Trim().ToLowerInvariant()`, and the statistics group them by that normalized name across media kinds. The application resolves the terms of each consumed record through the catalogue repository of its media kind, in a per-kind branch, and the photo branch is added when the photo catalogue exists. For a music track, the terms fall back from the track to its album and then to its artist.
|
||||
- **Access is based on the user and the administrator role.** A regular user reads and deletes only their own history, statistics and resume points. An administrator reads any user's history and statistics, and deletes any user's history and resume points. A resume point is readable only by its owner. There is no per-user permission toggle. Lifecycle writes (`start`, `progress`, `complete`, `stop`) are owner only, so an administrator does not write another user's session.
|
||||
|
||||
### Model
|
||||
|
||||
@@ -73,7 +73,7 @@ The statistics count a session when the rule of its media kind says so. Duration
|
||||
- **Complete**: loads the record of the current user, makes it terminal as `Completed`, and deletes the resume point for the same user, kind and item.
|
||||
- **Stop**: loads the record and the library settings. It stops the record without a threshold check when tracking is off or no threshold is set. When tracking is on and a threshold is set, a final fraction at or above it completes the record and deletes the resume point; otherwise the record is stopped and the resume point is upserted.
|
||||
- **Statistics**: the statistics repository binds the target user and every optional filter and returns read-only record entities. The application handlers aggregate the records, resolve display data and tags or genres through the catalogue repositories, paginate, and map the DTOs.
|
||||
- **Deletion**: deleting a record, every record of an item, or the whole history is idempotent and never deletes resume points. Clearing resume points never deletes history. An administrator may delete any user's history through the per-user routes.
|
||||
- **Deletion**: deleting a record, every record of an item, or the whole history is idempotent and never deletes resume points. Clearing resume points never deletes history. An administrator may delete any user's history or resume points through the per-user routes; reading a resume point stays owner only.
|
||||
|
||||
## Consequences
|
||||
|
||||
|
||||
Reference in new issue
Block a user