From 5b2687ae83f2cad89f89c454e2f81f100102a2c6 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Sat, 10 Feb 2024 05:30:06 -0500 Subject: [PATCH] [+] New maimai api --- .../sega/game/maimai2/Maimai2New.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/icu/samnyan/aqua/api/controller/sega/game/maimai2/Maimai2New.kt diff --git a/src/main/java/icu/samnyan/aqua/api/controller/sega/game/maimai2/Maimai2New.kt b/src/main/java/icu/samnyan/aqua/api/controller/sega/game/maimai2/Maimai2New.kt new file mode 100644 index 00000000..254ad902 --- /dev/null +++ b/src/main/java/icu/samnyan/aqua/api/controller/sega/game/maimai2/Maimai2New.kt @@ -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 { + // 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 } + } +} \ No newline at end of file