[+] Music popularity api

This commit is contained in:
Azalea
2025-05-01 20:54:27 -04:00
parent 88ea5c83b5
commit c87889ba41
3 changed files with 10 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ import icu.samnyan.aqua.net.components.JWT
import icu.samnyan.aqua.sega.allnet.AllNetProps import icu.samnyan.aqua.sega.allnet.AllNetProps
import icu.samnyan.aqua.sega.allnet.KeyChipRepo import icu.samnyan.aqua.sega.allnet.KeyChipRepo
import icu.samnyan.aqua.sega.allnet.KeychipSession import icu.samnyan.aqua.sega.allnet.KeychipSession
import icu.samnyan.aqua.sega.general.GameMusicPopularity
import icu.samnyan.aqua.sega.general.dao.CardRepository import icu.samnyan.aqua.sega.general.dao.CardRepository
import icu.samnyan.aqua.sega.general.model.Card import icu.samnyan.aqua.sega.general.model.Card
import jakarta.persistence.* import jakarta.persistence.*
@@ -117,7 +118,8 @@ class AquaUserServices(
val keyChipRepo: KeyChipRepo, val keyChipRepo: KeyChipRepo,
val allNetProps: AllNetProps, val allNetProps: AllNetProps,
val jwt: JWT, val jwt: JWT,
val em: EntityManager val em: EntityManager,
val pop: GameMusicPopularity
) { ) {
companion object { companion object {
val SETTING_FIELDS = AquaUserServices::class.functions val SETTING_FIELDS = AquaUserServices::class.functions

View File

@@ -226,4 +226,7 @@ abstract class GameApiController<T : IUserData>(val name: String, userDataClass:
recommendedMusic = data recommendedMusic = data
logger.info("Recommender updated with ${data.size} users") logger.info("Recommender updated with ${data.size} users")
} }
@API("song-pop")
fun songPopRanking() = us.pop.ranking[name]
} }

View File

@@ -2,12 +2,13 @@ package icu.samnyan.aqua.sega.general
import ext.* import ext.*
import icu.samnyan.aqua.net.db.AquaUserServices import icu.samnyan.aqua.net.db.AquaUserServices
import jakarta.persistence.EntityManager
import org.springframework.scheduling.annotation.Scheduled import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import java.time.LocalDate import java.time.LocalDate
@Component @Component
class GameMusicPopularity(val us: AquaUserServices) { class GameMusicPopularity(val em: EntityManager) {
companion object { companion object {
val log = logger() val log = logger()
@@ -23,8 +24,8 @@ class GameMusicPopularity(val us: AquaUserServices) {
// Get the play count of each music in the last N days // Get the play count of each music in the last N days
val after = LocalDate.now().minusDays(LOOK_BACK_DAYS).isoDate() val after = LocalDate.now().minusDays(LOOK_BACK_DAYS).isoDate()
ranking = ls("chusan", "ongeki").associateWith { game -> ranking = ls("maimai2", "chusan", "ongeki", "wacca").associateWith { game ->
us.em.createNativeQuery(""" em.createNativeQuery("""
SELECT music_id, count(user_id) as count SELECT music_id, count(user_id) as count
FROM ${game}_user_playlog_view FROM ${game}_user_playlog_view
WHERE user_play_date >= '${after}' WHERE user_play_date >= '${after}'