Skip to content

Commit

Permalink
[+] New maimai api
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Feb 10, 2024
1 parent c3402e8 commit 5b2687a
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 }
}
}

0 comments on commit 5b2687a

Please sign in to comment.