Skip to content

Commit

Permalink
chore(song): fractional scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Dec 18, 2024
1 parent deae2ee commit cc4b8d2
Show file tree
Hide file tree
Showing 14 changed files with 552 additions and 370 deletions.
3 changes: 2 additions & 1 deletion config/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ tui:
song:
interval_current_s: 5
interval_history_s: 5
interval_top_s: 300
interval_monthly_stats_s: 300
interval_stats_s: 3600

tap:
interval_s: 60
Expand Down
86 changes: 0 additions & 86 deletions config/production.yaml
Original file line number Diff line number Diff line change
@@ -1,86 +0,0 @@
# [server]
# host = "localhost"
# port = 3000

# [db]
# host = "localhost"
# port = 5432
# database = "scc"
# user = "postgres"
# password = "postgres"

# [song]
# spotify_api = "https://api.spotify.com/v1"
# spotify_account = "https://accounts.spotify.com/api/token"
# lrclib_api = "https://lrclib.net/api"

# [tap]
# api = "https://tap.zeus.gent"
# interval_s = 60
# beers = [
# "Schelfaut",
# "Duvel",
# "Fourchette",
# "Jupiler",
# "Karmeliet",
# "Kriek",
# "Chouffe",
# "Maes",
# "Somersby",
# "Sportzot",
# "Stella",
# ]

# [zess]
# api = "http://localhost:4000/api"
# interval_season_s = 300
# interval_scan_s = 60

# [gamification]
# api = "https://gamification.zeus.gent"
# interval_s = 3600

# [event]
# api = "https://zeus.gent/events"
# api_poster = "https://git.zeus.gent/ZeusWPI/visueel/raw/branch/master"
# interval_s = 86400

# [buzzer]
# song = [
# "-n", "-f880", "-l100", "-d0",
# "-n", "-f988", "-l100", "-d0",
# "-n", "-f588", "-l100", "-d0",
# "-n", "-f989", "-l100", "-d0",
# "-n", "-f660", "-l200", "-d0",
# "-n", "-f660", "-l200", "-d0",
# "-n", "-f588", "-l100", "-d0",
# "-n", "-f555", "-l100", "-d0",
# "-n", "-f495", "-l100", "-d0",
# ]

# [tui]

# [tui.screen]
# cammie_interval_change_s = 300

# [tui.zess]
# weeks = 10
# interval_scan_s = 60
# interval_season_s = 3600

# [tui.message]
# interval_s = 1

# [tui.tap]
# interval_s = 60

# [tui.gamification]
# interval_s = 3600

# [tui.song]
# interval_current_s = 5
# interval_history_s = 5
# interval_top_s = 3600

# [tui.event]
# interval_s = 3600
47 changes: 42 additions & 5 deletions db/queries/song.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ WHERE sh.created_at = (SELECT MAX(created_at) FROM song_history)
ORDER BY a.name, g.genre;

-- name: GetSongHistory :many
SELECT s.title
FROM song_history sh
JOIN song s ON sh.song_id = s.id
ORDER BY created_at DESC
LIMIT 10;
SELECT s.title, play_count, aggregated.created_at
FROM (
SELECT sh.song_id, MAX(sh.created_at) AS created_at, COUNT(sh.song_id) AS play_count
FROM song_history sh
GROUP BY sh.song_id
) aggregated
JOIN song s ON aggregated.song_id = s.id
ORDER BY aggregated.created_at DESC
LIMIT 20;

-- name: GetTopSongs :many
SELECT s.id AS song_id, s.title, COUNT(sh.id) AS play_count
Expand Down Expand Up @@ -106,3 +110,36 @@ JOIN song_genre g ON sag.genre_id = g.id
GROUP BY g.genre
ORDER BY total_plays DESC
LIMIT 10;

-- name: GetTopMonthlySongs :many
SELECT s.id AS song_id, s.title, COUNT(sh.id) AS play_count
FROM song_history sh
JOIN song s ON sh.song_id = s.id
WHERE sh.created_at > CURRENT_TIMESTAMP - INTERVAL '1 month'
GROUP BY s.id, s.title
ORDER BY play_count DESC
LIMIT 10;

-- name: GetTopMonthlyArtists :many
SELECT sa.id AS artist_id, sa.name AS artist_name, COUNT(sh.id) AS total_plays
FROM song_history sh
JOIN song s ON sh.song_id = s.id
JOIN song_artist_song sas ON s.id = sas.song_id
JOIN song_artist sa ON sas.artist_id = sa.id
WHERE sh.created_at > CURRENT_TIMESTAMP - INTERVAL '1 month'
GROUP BY sa.id, sa.name
ORDER BY total_plays DESC
LIMIT 10;

-- name: GetTopMonthlyGenres :many
SELECT g.genre AS genre_name, COUNT(sh.id) AS total_plays
FROM song_history sh
JOIN song s ON sh.song_id = s.id
JOIN song_artist_song sas ON s.id = sas.song_id
JOIN song_artist sa ON sas.artist_id = sa.id
JOIN song_artist_genre sag ON sa.id = sag.artist_id
JOIN song_genre g ON sag.genre_id = g.id
WHERE sh.created_at > CURRENT_TIMESTAMP - INTERVAL '1 month'
GROUP BY g.genre
ORDER BY total_plays DESC
LIMIT 10;
141 changes: 132 additions & 9 deletions internal/pkg/db/sqlc/song.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/pkg/lyrics/lrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type LRC struct {
i int
}

func newLRC(song *dto.Song) Lyrics {
return &LRC{song: *song, lyrics: parseLRC(song.Lyrics, time.Duration(song.DurationMS)), i: 0}
func newLRC(song dto.Song) Lyrics {
return &LRC{song: song, lyrics: parseLRC(song.Lyrics, time.Duration(song.DurationMS)), i: 0}
}

// GetSong returns the song associated to the lyrics
Expand Down
9 changes: 8 additions & 1 deletion internal/pkg/lyrics/lyrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ type Lyric struct {
}

// New returns a new object that implements the Lyrics interface
func New(song *dto.Song) Lyrics {
func New(song dto.Song) Lyrics {
// No lyrics
if song.LyricsType == "" {
return newMissing(song)
}

// Basic sync
if song.LyricsType == "synced" {
return newLRC(song)
}

// Lyrics but no syncing
return newPlain(song)
}
Loading

0 comments on commit cc4b8d2

Please sign in to comment.