mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-31 15:19:42 +02:00
Add:User listening stats page and new library stats
This commit is contained in:
parent
7845e06a24
commit
b80d735750
13 changed files with 326 additions and 120 deletions
|
@ -458,14 +458,15 @@ class ApiController {
|
|||
books: {},
|
||||
days: {},
|
||||
dayOfWeek: {},
|
||||
today: 0
|
||||
today: 0,
|
||||
recentSessions: listeningSessions.slice(0, 10)
|
||||
}
|
||||
listeningSessions.forEach((s) => {
|
||||
if (s.dayOfWeek) {
|
||||
if (!listeningStats.dayOfWeek[s.dayOfWeek]) listeningStats.dayOfWeek[s.dayOfWeek] = 0
|
||||
listeningStats.dayOfWeek[s.dayOfWeek] += s.timeListening
|
||||
}
|
||||
if (s.date) {
|
||||
if (s.date && s.timeListening > 0) {
|
||||
if (!listeningStats.days[s.date]) listeningStats.days[s.date] = 0
|
||||
listeningStats.days[s.date] += s.timeListening
|
||||
|
||||
|
@ -473,8 +474,17 @@ class ApiController {
|
|||
listeningStats.today += s.timeListening
|
||||
}
|
||||
}
|
||||
if (!listeningStats.books[s.audiobookId]) listeningStats.books[s.audiobookId] = 0
|
||||
listeningStats.books[s.audiobookId] += s.timeListening
|
||||
if (!listeningStats.books[s.audiobookId]) {
|
||||
listeningStats.books[s.audiobookId] = {
|
||||
id: s.audiobookId,
|
||||
timeListening: s.timeListening,
|
||||
title: s.audiobookTitle,
|
||||
author: s.audiobookAuthor,
|
||||
lastUpdate: s.lastUpdate
|
||||
}
|
||||
} else {
|
||||
listeningStats.books[s.audiobookId].timeListening += s.timeListening
|
||||
}
|
||||
|
||||
listeningStats.totalTime += s.timeListening
|
||||
})
|
||||
|
|
|
@ -375,11 +375,14 @@ class LibraryController {
|
|||
|
||||
var authorsWithCount = libraryHelpers.getAuthorsWithCount(audiobooksInLibrary)
|
||||
var genresWithCount = libraryHelpers.getGenresWithCount(audiobooksInLibrary)
|
||||
var abDurationStats = libraryHelpers.getAudiobookDurationStats(audiobooksInLibrary)
|
||||
var stats = {
|
||||
totalBooks: audiobooksInLibrary.length,
|
||||
totalAuthors: Object.keys(authorsWithCount).length,
|
||||
totalGenres: Object.keys(genresWithCount).length,
|
||||
totalDuration: libraryHelpers.getAudiobooksTotalDuration(audiobooksInLibrary),
|
||||
totalDuration: abDurationStats.totalDuration,
|
||||
longestAudiobooks: abDurationStats.longstAudiobooks,
|
||||
numAudioTracks: abDurationStats.numAudioTracks,
|
||||
totalSize: libraryHelpers.getAudiobooksTotalSize(audiobooksInLibrary),
|
||||
authorsWithCount,
|
||||
genresWithCount
|
||||
|
|
|
@ -10,6 +10,7 @@ class UserListeningSession {
|
|||
this.audiobookId = null
|
||||
this.audiobookTitle = null
|
||||
this.audiobookAuthor = null
|
||||
this.audiobookDuration = 0
|
||||
this.audiobookGenres = []
|
||||
|
||||
this.date = null
|
||||
|
@ -32,6 +33,7 @@ class UserListeningSession {
|
|||
audiobookId: this.audiobookId,
|
||||
audiobookTitle: this.audiobookTitle,
|
||||
audiobookAuthor: this.audiobookAuthor,
|
||||
audiobookDuration: this.audiobookDuration,
|
||||
audiobookGenres: [...this.audiobookGenres],
|
||||
date: this.date,
|
||||
dayOfWeek: this.dayOfWeek,
|
||||
|
@ -48,6 +50,7 @@ class UserListeningSession {
|
|||
this.audiobookId = session.audiobookId
|
||||
this.audiobookTitle = session.audiobookTitle
|
||||
this.audiobookAuthor = session.audiobookAuthor
|
||||
this.audiobookDuration = session.audiobookDuration || 0
|
||||
this.audiobookGenres = session.audiobookGenres
|
||||
|
||||
this.date = session.date
|
||||
|
@ -64,6 +67,7 @@ class UserListeningSession {
|
|||
this.audiobookId = audiobook.id
|
||||
this.audiobookTitle = audiobook.title || ''
|
||||
this.audiobookAuthor = audiobook.authorFL || ''
|
||||
this.audiobookDuration = audiobook.duration || 0
|
||||
this.audiobookGenres = [...audiobook.genres]
|
||||
|
||||
this.timeListening = 0
|
||||
|
|
|
@ -182,12 +182,20 @@ module.exports = {
|
|||
return Object.values(authorsMap).sort((a, b) => b.count - a.count)
|
||||
},
|
||||
|
||||
getAudiobooksTotalDuration(audiobooks) {
|
||||
getAudiobookDurationStats(audiobooks) {
|
||||
var sorted = sort(audiobooks).desc(a => a.duration)
|
||||
var top10 = sorted.slice(0, 10).map(ab => ({ title: ab.book.title, duration: ab.duration })).filter(ab => ab.duration > 0)
|
||||
var totalDuration = 0
|
||||
var numAudioTracks = 0
|
||||
audiobooks.forEach((ab) => {
|
||||
totalDuration += ab.duration
|
||||
numAudioTracks += ab.tracks.length
|
||||
})
|
||||
return totalDuration
|
||||
return {
|
||||
totalDuration,
|
||||
numAudioTracks,
|
||||
longstAudiobooks: top10
|
||||
}
|
||||
},
|
||||
|
||||
getAudiobooksTotalSize(audiobooks) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue