[F] Fix rating calculation

This commit is contained in:
Azalea
2024-02-19 00:39:43 -05:00
parent f29f563e50
commit 1c541a4adf

View File

@@ -30,9 +30,13 @@ class Maimai2New(
// Precompute the play counts for each date in O(n)
val playCounts = d.groupingBy { it.playDate }.eachCount()
// Find the max afterRating on each date
val maxRating = d.groupingBy { it.playDate }.fold(0) { acc, e -> maxOf(acc, e.afterRating) }
// Use the precomputed play counts
return d.distinctBy { it.playDate }
.map { TrendOut(it.playDate, it.afterRating, playCounts[it.playDate] ?: 0) }
.map { TrendOut(it.playDate, maxRating[it.playDate] ?: 0,
playCounts[it.playDate] ?: 0) }
.sortedBy { it.date }
}