[+] New maimai api

pull/10/head
Azalea 2024-02-10 05:30:06 -05:00
parent c3402e8d44
commit 5b2687ae83
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package icu.samnyan.aqua.api.controller.sega.game.maimai2
import icu.samnyan.aqua.sega.maimai2.dao.userdata.UserPlaylogRepository
import icu.samnyan.aqua.sega.maimai2.model.userdata.UserPlaylog
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import java.util.*
@RestController
@RequestMapping("api/game/maimai2new")
class Maimai2New(
private val userPlaylogRepository: UserPlaylogRepository
)
{
data class TrendOut(val date: String, val rating: Int)
@GetMapping("trend")
fun trend(@RequestParam userId: Long): List<TrendOut> {
// O(n log n) sort TODO: It might be possible to optimize this
val d = userPlaylogRepository.findByUser_Card_ExtId(userId).sortedBy { it.playDate }.toList()
// Assume it's sorted by date, map the values O(n)
val map = d.associate { it.playDate to it.afterRating }
// Is sorting here necessary?
return map.map { TrendOut(it.key, it.value) }.sortedBy { it.date }
}
}