-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3402e8
commit 5b2687a
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/icu/samnyan/aqua/api/controller/sega/game/maimai2/Maimai2New.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |