feat: add genre filtering and longest streak display in TopSongs

This commit is contained in:
Rémi Heredero 2025-04-07 13:05:27 +02:00
parent 7f01af5d93
commit ae0efe0756
Signed by: Klagarge
GPG Key ID: 735B36B074A65F0F

View File

@ -122,6 +122,14 @@ case class TopSongs(songs: List[Song] = List()) {
.toMap
}
// This function return the song spent the most weeks on the chart
// It uses reduce to find the song with the maximum streak value
def longestStreak(): Song = {
songs.reduce((s1, s2) => {
if (s1.rank._1.streak.getOrElse(0) > s2.rank._1.streak.getOrElse(0)) s1 else s2
})
}
// This function returns the top N songs by weeks on chart
// It sorts the songs by the streak value in descending order and takes the top N songs
def topNSongsByWeeks(n: Int): List[Song] = {