mirror of https://github.com/hykilpikonna/AquaDX
[+] Allow querying card user ids
parent
fa9b738cba
commit
63cf1f5fa1
|
@ -5,6 +5,7 @@ import ext.Str
|
|||
import ext.isValidEmail
|
||||
import ext.minus
|
||||
import icu.samnyan.aqua.sega.allnet.KeychipSession
|
||||
import icu.samnyan.aqua.sega.general.dao.CardRepository
|
||||
import icu.samnyan.aqua.sega.general.model.Card
|
||||
import jakarta.persistence.*
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
@ -12,6 +13,7 @@ import org.springframework.security.crypto.password.PasswordEncoder
|
|||
import org.springframework.stereotype.Repository
|
||||
import org.springframework.stereotype.Service
|
||||
import java.io.Serializable
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.reflect.KMutableProperty
|
||||
import kotlin.reflect.full.functions
|
||||
|
@ -96,6 +98,7 @@ data class SettingField(
|
|||
@Service
|
||||
class AquaUserServices(
|
||||
val userRepo: AquaNetUserRepo,
|
||||
val cardRepo: CardRepository,
|
||||
val hasher: PasswordEncoder,
|
||||
) {
|
||||
companion object {
|
||||
|
@ -111,6 +114,12 @@ class AquaUserServices(
|
|||
fun <T> byName(username: Str, callback: (AquaNetUser) -> T) =
|
||||
userRepo.findByUsernameIgnoreCase(username)?.let(callback) ?: (404 - "User not found")
|
||||
|
||||
fun <T> cardByName(username: Str, callback: (Card) -> T) =
|
||||
if (username.startsWith("card")) username.substring(4).toLongOrNull()
|
||||
?.let { cardRepo.findByExtId(it).getOrNull() }
|
||||
?.let(callback) ?: (404 - "Card not found")
|
||||
else byName(username) { callback(it.ghostCard) }
|
||||
|
||||
fun checkUsername(username: Str) = username.apply {
|
||||
// Check if username is valid
|
||||
if (length < 2) 400 - "Username must be at least 2 letters"
|
||||
|
|
|
@ -19,25 +19,25 @@ class Chusan(
|
|||
val userGeneralDataRepository: UserGeneralDataRepository
|
||||
): GameApiController
|
||||
{
|
||||
override fun trend(@RP username: Str): List<TrendOut> = us.byName(username) { u ->
|
||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(u.ghostCard.extId)
|
||||
override fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||
.map { TrendLog(it.playDate.toString(), it.playerRating) })
|
||||
}
|
||||
|
||||
// Only show > AAA rank
|
||||
private val shownRanks = chu3Scores.filter { it.first >= 95 * 10000 }
|
||||
|
||||
override fun userSummary(@RP username: Str) = us.byName(username) { u ->
|
||||
override fun userSummary(@RP username: Str) = us.cardByName(username) { card ->
|
||||
// Summary values: total plays, player rating, server-wide ranking
|
||||
// number of each rank, max combo, number of full combo, number of all perfect
|
||||
val extra = userGeneralDataRepository.findByUser_Card_ExtId(u.ghostCard.extId)
|
||||
val extra = userGeneralDataRepository.findByUser_Card_ExtId(card.extId)
|
||||
.associate { it.propertyKey to it.propertyValue }
|
||||
|
||||
val ratingComposition = mapOf(
|
||||
"recent" to (extra["recent_rating_list"] ?: ""),
|
||||
)
|
||||
|
||||
genericUserSummary(u, userDataRepository, userPlaylogRepository, shownRanks, ratingComposition)
|
||||
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, ratingComposition)
|
||||
}
|
||||
|
||||
override fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
||||
|
|
|
@ -19,16 +19,16 @@ class Maimai2(
|
|||
val userGeneralDataRepository: UserGeneralDataRepository
|
||||
): GameApiController
|
||||
{
|
||||
override fun trend(@RP username: Str): List<TrendOut> = us.byName(username) { u ->
|
||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(u.ghostCard.extId)
|
||||
override fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||
.map { TrendLog(it.playDate, it.afterRating) })
|
||||
}
|
||||
|
||||
// Only show > S rank
|
||||
private val shownRanks = mai2Scores.filter { it.first >= 97 * 10000 }
|
||||
|
||||
override fun userSummary(@RP username: Str) = us.byName(username) { u ->
|
||||
val extra = userGeneralDataRepository.findByUser_Card_ExtId(u.ghostCard.extId)
|
||||
override fun userSummary(@RP username: Str) = us.cardByName(username) { card ->
|
||||
val extra = userGeneralDataRepository.findByUser_Card_ExtId(card.extId)
|
||||
.associate { it.propertyKey to it.propertyValue }
|
||||
|
||||
val ratingComposition = mapOf(
|
||||
|
@ -36,7 +36,7 @@ class Maimai2(
|
|||
"best15" to (extra["recent_rating_new"] ?: "")
|
||||
)
|
||||
|
||||
genericUserSummary(u, userDataRepository, userPlaylogRepository, shownRanks, ratingComposition)
|
||||
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, ratingComposition)
|
||||
}
|
||||
|
||||
override fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
||||
|
|
|
@ -16,20 +16,20 @@ class Ongeki(
|
|||
val userDataRepository: UserDataRepository,
|
||||
val userGeneralDataRepository: UserGeneralDataRepository
|
||||
): GameApiController {
|
||||
override fun trend(username: String) = us.byName(username) { u ->
|
||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(u.ghostCard.extId)
|
||||
override fun trend(username: String) = us.cardByName(username) { card ->
|
||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||
.map { TrendLog(it.playDate, it.playerRating) })
|
||||
}
|
||||
|
||||
private val shownRanks = ongekiScores.filter { it.first >= 950000 }
|
||||
|
||||
override fun userSummary(username: String) = us.byName(username) { u ->
|
||||
override fun userSummary(username: String) = us.cardByName(username) { card ->
|
||||
// val extra = userGeneralDataRepository.findByUser_Card_ExtId(u.ghostCard.extId)
|
||||
// .associate { it.propertyKey to it.propertyValue }
|
||||
|
||||
// TODO: Rating composition
|
||||
|
||||
genericUserSummary(u, userDataRepository, userPlaylogRepository, shownRanks, mapOf())
|
||||
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, mapOf())
|
||||
}
|
||||
|
||||
override fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
||||
|
|
|
@ -2,7 +2,6 @@ package icu.samnyan.aqua.net.utils
|
|||
|
||||
import ext.millis
|
||||
import ext.minus
|
||||
import icu.samnyan.aqua.net.db.AquaNetUser
|
||||
import icu.samnyan.aqua.net.games.GenericGameSummary
|
||||
import icu.samnyan.aqua.net.games.GenericRankingPlayer
|
||||
import icu.samnyan.aqua.net.games.RankCount
|
||||
|
@ -71,7 +70,7 @@ interface GenericPlaylogRepo {
|
|||
fun List<IGenericGamePlaylog>.acc() = if (isEmpty()) 0.0 else sumOf { it.achievement }.toDouble() / size / 10000.0
|
||||
|
||||
fun genericUserSummary(
|
||||
u: AquaNetUser,
|
||||
card: Card,
|
||||
userDataRepo: GenericUserDataRepo<*, *>,
|
||||
userPlaylogRepo: GenericPlaylogRepo,
|
||||
shownRanks: List<Pair<Int, String>>,
|
||||
|
@ -79,8 +78,8 @@ fun genericUserSummary(
|
|||
): GenericGameSummary {
|
||||
// Summary values: total plays, player rating, server-wide ranking
|
||||
// number of each rank, max combo, number of full combo, number of all perfect
|
||||
val user = userDataRepo.findByCard(u.ghostCard) ?: (404 - "User not found")
|
||||
val plays = userPlaylogRepo.findByUserCardExtId(u.ghostCard.extId)
|
||||
val user = userDataRepo.findByCard(card) ?: (404 - "User not found")
|
||||
val plays = userPlaylogRepo.findByUserCardExtId(card.extId)
|
||||
|
||||
// O(6n) ranks algorithm: Loop through the entire list of plays,
|
||||
// count the number of each rank
|
||||
|
|
Loading…
Reference in New Issue