diff --git a/internal/radio/song.go b/internal/radio/song.go index a65940f..45a02ce 100644 --- a/internal/radio/song.go +++ b/internal/radio/song.go @@ -28,7 +28,7 @@ func (s *Song) MarshalJSON() ([]byte, error) { Title string `json:"title"` DurationMill int64 `json:"duration_msec,omitempty"` Listeners int64 `json:"listeners"` - PeakListeners int64 `json:"max_listeners"` + PeakListeners int64 `json:"peak_listeners"` StartAt string `json:"start_at"` }{ Artist: s.Artist, diff --git a/internal/statistics/db/sqlite/queries/history_add.sql b/internal/statistics/db/sqlite/queries/history_add.sql index b422896..609416b 100644 --- a/internal/statistics/db/sqlite/queries/history_add.sql +++ b/internal/statistics/db/sqlite/queries/history_add.sql @@ -1,3 +1,3 @@ INSERT OR IGNORE INTO `history` - (`start_at`, `song_id`, `listeners`, `max_listeners`) + (`start_at`, `song_id`, `listeners`, `peak_listeners`) VALUES (?,?,?,?); \ No newline at end of file diff --git a/internal/statistics/db/sqlite/queries/last_n_songs.sql b/internal/statistics/db/sqlite/queries/last_n_songs.sql index 4969d7c..b5fb511 100644 --- a/internal/statistics/db/sqlite/queries/last_n_songs.sql +++ b/internal/statistics/db/sqlite/queries/last_n_songs.sql @@ -3,14 +3,14 @@ SELECT `artist`, `title`, `listeners`, - `max_listeners` + `peak_listeners` FROM (SELECT `start_at`, `artist`, `title`, `listeners`, - `max_listeners` + `peak_listeners` FROM `history` LEFT JOIN `song` ON `song`.`song_id` = `history`.`song_id` diff --git a/internal/statistics/db/sqlite/queries/most_simultaneous_listeners.sql b/internal/statistics/db/sqlite/queries/most_simultaneous_listeners.sql index 2c7eeca..1128ba9 100644 --- a/internal/statistics/db/sqlite/queries/most_simultaneous_listeners.sql +++ b/internal/statistics/db/sqlite/queries/most_simultaneous_listeners.sql @@ -2,7 +2,7 @@ SELECT MAX(`start_at`) AS `start_at`, `artist`, `title`, - MAX(`max_listeners`) AS `max_listeners` + MAX(`peak_listeners`) AS `peak_listeners` FROM `history` LEFT JOIN `song` ON `song`.`song_id` = `history`.`song_id`; \ No newline at end of file diff --git a/internal/statistics/db/sqlite/queries/schema.sql b/internal/statistics/db/sqlite/queries/schema.sql index a3538c9..998ccf9 100644 --- a/internal/statistics/db/sqlite/queries/schema.sql +++ b/internal/statistics/db/sqlite/queries/schema.sql @@ -6,10 +6,10 @@ CREATE TABLE IF NOT EXISTS `song` ( UNIQUE (`artist`, `title`) ); CREATE TABLE IF NOT EXISTS `history` ( - `start_at` TEXT NOT NULL DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now')), - `song_id` INTEGER NOT NULL, - `listeners` INTEGER NOT NULL, - `max_listeners` INTEGER NOT NULL, + `start_at` TEXT NOT NULL DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now')), + `song_id` INTEGER NOT NULL, + `listeners` INTEGER NOT NULL, + `peak_listeners` INTEGER NOT NULL, PRIMARY KEY (`start_at`), FOREIGN KEY (`song_id`) REFERENCES `song` (`song_id`) ON UPDATE CASCADE ON DELETE CASCADE ); diff --git a/web/assets/js/main.js b/web/assets/js/main.js index fd38619..45e36b1 100644 --- a/web/assets/js/main.js +++ b/web/assets/js/main.js @@ -27,7 +27,7 @@ async function updateStatus() { for (let i = 0; i < s.last_songs.length; ++i) { let row = $("last-songs").lastChild.insertRow(); row.insertCell().appendChild(document.createTextNode(formatStartAt(new Date(s.last_songs[i].start_at)))); - row.insertCell().appendChild(document.createTextNode((s.last_songs[i].listeners == 0 ? "" : s.last_songs[i].listeners + "/") + (s.last_songs[i].max_listeners == 0 ? "" : s.last_songs[i].max_listeners))); + row.insertCell().appendChild(document.createTextNode((s.last_songs[i].listeners == 0 ? "" : s.last_songs[i].listeners + "/") + (s.last_songs[i].peak_listeners == 0 ? "" : s.last_songs[i].peak_listeners))); row.insertCell().appendChild(document.createTextNode(`${s.last_songs[i].artist} - ${s.last_songs[i].title}`)); } }