diff --git a/cmd/dwelling-radio/main.go b/cmd/dwelling-radio/main.go index 669c7ed..7c84a87 100644 --- a/cmd/dwelling-radio/main.go +++ b/cmd/dwelling-radio/main.go @@ -112,7 +112,7 @@ func main() { switch <-sysSignal { case os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGABRT, syscall.SIGSEGV: if currentSong.Artist != "" { - currentSong.Listeners, currentSong.MaxListeners = lstnrs.Reset() + currentSong.Listeners, currentSong.PeakListeners = lstnrs.Reset() if err := stats.Add(¤tSong); err != nil { log.Println("failed to save a current song during a shutdown:", err) } diff --git a/internal/http/dj_handlers.go b/internal/http/dj_handlers.go index 60e56b4..824bf7a 100644 --- a/internal/http/dj_handlers.go +++ b/internal/http/dj_handlers.go @@ -108,7 +108,7 @@ func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) { newSong.Artist = "Nothing to play. Playing a fallback: " + newSong.Artist } - dj.curSong.Listeners, dj.curSong.MaxListeners = dj.listeners.Reset() + dj.curSong.Listeners, dj.curSong.PeakListeners = dj.listeners.Reset() if dj.curSong.Artist != "" { if err := dj.stats.Add(dj.curSong); err != nil { @@ -118,7 +118,7 @@ func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) { *dj.curSong = newSong dj.curSong.Listeners = 0 - dj.curSong.MaxListeners = 0 + dj.curSong.PeakListeners = 0 // }() fmt.Fprintln(w, nxt) diff --git a/internal/radio/song.go b/internal/radio/song.go index 55c97c9..a65940f 100644 --- a/internal/radio/song.go +++ b/internal/radio/song.go @@ -6,12 +6,12 @@ import ( ) type Song struct { - Artist string - Title string - StartAt time.Time - Duration time.Duration - Listeners int64 - MaxListeners int64 + Artist string + Title string + StartAt time.Time + Duration time.Duration + Listeners int64 + PeakListeners int64 } // DurationString returns song's duration as a string formatted as [H:]M:SS. @@ -24,17 +24,17 @@ func (s *Song) DurationString() string { func (s *Song) MarshalJSON() ([]byte, error) { return json.Marshal(&struct { - Artist string `json:"artist"` - Title string `json:"title"` - DurationMill int64 `json:"duration_msec,omitempty"` - Listeners int64 `json:"listeners"` - MaxListeners int64 `json:"max_listeners"` - StartAt string `json:"start_at"` + Artist string `json:"artist"` + Title string `json:"title"` + DurationMill int64 `json:"duration_msec,omitempty"` + Listeners int64 `json:"listeners"` + PeakListeners int64 `json:"max_listeners"` + StartAt string `json:"start_at"` }{ - Artist: s.Artist, - Title: s.Title, - DurationMill: s.Duration.Milliseconds(), - Listeners: s.Listeners, - MaxListeners: s.MaxListeners, - StartAt: s.StartAt.UTC().Format(time.RFC3339)}) + Artist: s.Artist, + Title: s.Title, + DurationMill: s.Duration.Milliseconds(), + Listeners: s.Listeners, + PeakListeners: s.PeakListeners, + StartAt: s.StartAt.UTC().Format(time.RFC3339)}) } diff --git a/internal/statistics/db/sqlite/db.go b/internal/statistics/db/sqlite/db.go index 495bab7..8f4b0d1 100644 --- a/internal/statistics/db/sqlite/db.go +++ b/internal/statistics/db/sqlite/db.go @@ -115,7 +115,7 @@ func (s *SQLiteStatistics) Add(song *radio.Song) error { } res, err := tx.Stmt(stmtHistoryAdd).Exec(song.StartAt.UTC().Format(dbDateFormat), - songID, song.Listeners, song.MaxListeners) + songID, song.Listeners, song.PeakListeners) if err != nil { return err } else if ra, err := res.RowsAffected(); ra == 0 || err != nil { @@ -150,7 +150,7 @@ func (s *SQLiteStatistics) LastNSongs(n int64) ([]radio.Song, error) { var startAt string if err := rows.Scan(&startAt, &songs[i].Artist, &songs[i].Title, - &songs[i].Listeners, &songs[i].MaxListeners); err != nil { + &songs[i].Listeners, &songs[i].PeakListeners); err != nil { return nil, err } diff --git a/web/index.templ b/web/index.templ index ce47d6e..8149dbc 100644 --- a/web/index.templ +++ b/web/index.templ @@ -83,7 +83,7 @@ if sl != nil && len(sl) != 0 { Start - O/M + O/P Song @@ -91,8 +91,8 @@ if sl != nil && len(sl) != 0 { for i := 0; i < len(sl); i++ { { utils.ToClientTimezone(sl[i].StartAt, r).Format("15:04") } - if sl[i].MaxListeners != 0 { - { strconv.FormatInt(sl[i].Listeners, 10) }/{ strconv.FormatInt(sl[i].MaxListeners, 10) } + if sl[i].PeakListeners != 0 { + { strconv.FormatInt(sl[i].Listeners, 10) }/{ strconv.FormatInt(sl[i].PeakListeners, 10) } } else { }