1
0

A MaxListeners field of a Song struct was renamed to a more logically appropriate PeakListeners.

This commit is contained in:
Alexander Andreev 2024-05-11 04:52:40 +04:00
parent 4feeb518fc
commit 872e8f4978
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
5 changed files with 26 additions and 26 deletions

View File

@ -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(&currentSong); err != nil {
log.Println("failed to save a current song during a shutdown:", err)
}

View File

@ -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)

View File

@ -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)})
}

View File

@ -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
}

View File

@ -83,7 +83,7 @@ if sl != nil && len(sl) != 0 {
<thead class="small">
<tr>
<td>Start</td>
<td><abbr title="Overall/Max listeners">O/M</abbr></td>
<td><abbr title="Overall/Peak listeners">O/P</abbr></td>
<td>Song</td>
</tr>
</thead>
@ -91,8 +91,8 @@ if sl != nil && len(sl) != 0 {
for i := 0; i < len(sl); i++ {
<tr>
<td>{ utils.ToClientTimezone(sl[i].StartAt, r).Format("15:04") }</td>
if sl[i].MaxListeners != 0 {
<td>{ strconv.FormatInt(sl[i].Listeners, 10) }/{ strconv.FormatInt(sl[i].MaxListeners, 10) }</td>
if sl[i].PeakListeners != 0 {
<td>{ strconv.FormatInt(sl[i].Listeners, 10) }/{ strconv.FormatInt(sl[i].PeakListeners, 10) }</td>
} else {
<td></td>
}