[M] Rename database fields

pull/29/head
Azalea 2024-03-29 00:47:54 -04:00
parent abc21badb1
commit 26a72244c0
9 changed files with 57 additions and 63 deletions

View File

@ -109,7 +109,6 @@ abstract class GameApiController<T : IGenericUserData>(name: String, userDataCla
return GenericGameSummary(
name = user.userName,
iconId = user.iconId,
aquaUser = card.aquaUser?.publicFields,
serverRank = userDataRepo.getRanking(user.playerRating),
accuracy = plays.acc(),

View File

@ -25,7 +25,6 @@ data class RankCount(val name: String, val count: Int)
data class GenericGameSummary(
val name: String,
val iconId: Int,
val aquaUser: Map<String, Any?>?,

View File

@ -346,11 +346,6 @@ public class UserData implements Serializable, IGenericUserData {
@Transient
private UserEmoney userEmoney;
@Override
public int getIconId() {
return characterId;
}
@Override
public long getTotalScore() {
return totalHiScore;

View File

@ -6,8 +6,8 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import icu.samnyan.aqua.net.games.BaseEntity
import icu.samnyan.aqua.net.games.IGenericUserData
import icu.samnyan.aqua.sega.general.model.Card
import icu.samnyan.aqua.sega.general.IntegerListConverter
import icu.samnyan.aqua.sega.general.model.Card
import icu.samnyan.aqua.sega.util.jackson.AccessCodeSerializer
import jakarta.persistence.*
@ -30,7 +30,7 @@ class Mai2UserDetail(
@JsonInclude
@Transient
var nameplateId: Int = 0,
override var iconId: Int = 0,
var iconId: Int = 0,
@JsonInclude
@Transient

View File

@ -158,11 +158,6 @@ public class UserData implements Serializable, IGenericUserData {
private int lastEmoneyBrand;
@Override
public int getIconId() {
return characterId;
}
@Override
public long getTotalScore() {
return sumTechHighScore;

View File

@ -291,25 +291,25 @@ fun WaccaServer.init() {
addItems(items as List<List<Int>>, u, itmGrp(u))
// Upsert playlog
val song = WcUserPlayLog.parse(details as List<*>)
rp.playLog.save(song.apply { user = u })
val pl = WcUserPlayLog.parse(details as List<*>)
rp.playLog.save(pl.apply { user = u })
// Update best record
val best = rp.bestScore.save((rp.bestScore.findByUserAndSongIdAndDifficulty(u, song.songId, song.difficulty)
?: WcUserScore().apply { user = u; songId = song.songId; difficulty = song.difficulty }).apply {
val best = rp.bestScore.save((rp.bestScore.findByUserAndMusicIdAndLevel(u, pl.musicId, pl.level)
?: WcUserScore().apply { user = u; musicId = pl.musicId; level = pl.level }).apply {
grades[WaccaGrades.valueMap[song.grade]?.ordinal ?: (400 - "Grade ${song.grade} invalid")]++
clears = clears.zip(song.clears()) { a, b -> a + b }.toMutableList()
score = max(score, song.score)
bestCombo = max(bestCombo, song.maxCombo)
lowestMissCt = min(lowestMissCt, song.judgements[3])
rating = waccaRating(score, song.level)
grades[WaccaGrades.valueMap[pl.grade]?.ordinal ?: (400 - "Grade ${pl.grade} invalid")]++
clears = clears.zip(pl.clears()) { a, b -> a + b }.toMutableList()
achievement = max(achievement, pl.achievement)
bestCombo = max(bestCombo, pl.maxCombo)
lowestMissCt = min(lowestMissCt, pl.judgements[3])
rating = waccaRating(achievement, pl.levelConst)
})
// Re-calculate user total score
rp.user.save(u.apply { totalScore = rp.bestScore.sumScoreByUser(u) })
ls(best.lsMusicUpdate(), ls(song.songId, best.clears[0]), "seasonalInfo" - (1..11).map { 0 }, "ranking" - empty)
ls(best.lsMusicUpdate(), ls(pl.musicId, best.clears[0]), "seasonalInfo" - (1..11).map { 0 }, "ranking" - empty)
}
"user/music/UpdateCoop" redirect "user/music/update"
"user/music/UpdateVersus" redirect "user/music/update"
@ -341,7 +341,7 @@ fun WaccaServer.init() {
// Update best record
(songs as List<List<Any>>).forEach { (songId, diff, newRating) ->
val best = rp.bestScore.findByUserAndSongIdAndDifficulty(u, songId.int(), diff.int()) ?: return@forEach
val best = rp.bestScore.findByUserAndMusicIdAndLevel(u, songId.int(), diff.int()) ?: return@forEach
best.rating = newRating.int()
rp.bestScore.save(best)
}

View File

@ -1,5 +1,6 @@
package icu.samnyan.aqua.sega.wacca.model.db
import icu.samnyan.aqua.net.games.GenericPlaylogRepo
import jakarta.transaction.Transactional
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
@ -31,11 +32,11 @@ interface WcUserItemRepo : IWaccaUserLinked<WcUserItem> {
fun findByUserAndItemIdAndType(user: WaccaUser, itemId: Int, type: Int): WcUserItem?
}
interface WcUserBestScoreRepo : IWaccaUserLinked<WcUserScore> {
fun findByUserAndSongIdAndDifficulty(user: WaccaUser, songId: Int, difficulty: Int): WcUserScore?
@Query("SELECT SUM(score) FROM WcUserScore WHERE user = :user")
fun findByUserAndMusicIdAndLevel(user: WaccaUser, songId: Int, level: Int): WcUserScore?
@Query("SELECT SUM(achievement) FROM WcUserScore WHERE user = :user")
fun sumScoreByUser(user: WaccaUser): Long
}
interface WcUserPlayLogRepo : IWaccaUserLinked<WcUserPlayLog>
interface WcUserPlayLogRepo : IWaccaUserLinked<WcUserPlayLog>, GenericPlaylogRepo<WcUserPlayLog>
interface WcUserStageUpRepo : IWaccaUserLinked<WcUserStageUp>
@Component

View File

@ -3,6 +3,7 @@ package icu.samnyan.aqua.sega.wacca.model.db
import com.fasterxml.jackson.annotation.JsonIgnore
import ext.*
import icu.samnyan.aqua.net.games.BaseEntity
import icu.samnyan.aqua.net.games.IGenericGamePlaylog
import icu.samnyan.aqua.sega.general.IntegerListConverter
import icu.samnyan.aqua.sega.wacca.WaccaItemType
import icu.samnyan.aqua.sega.wacca.WaccaItemType.*
@ -90,11 +91,11 @@ class WcUserItem(
infix fun isType(t: WaccaItemType) = type == t()
}
@Entity @Table(name = "wacca_user_score", uniqueConstraints = [UC("", ["user_id", "song_id", "chart_id"])])
@Entity @Table(name = "wacca_user_score", uniqueConstraints = [UC("", ["user_id", "music_id", "level"])])
class WcUserScore : WaccaUserEntity() {
var songId = 0
var difficulty = 0 // aka difficulty
var score = 0
var musicId = 0
var level = 0 // aka difficulty
var achievement = 0
@Convert(converter = IntegerListConverter::class)
var clears: MutableList<Int> = mutableListOf(0, 0, 0, 0, 0) // Played, Clear, Full Combo, Missless, All Marv
@ -105,37 +106,39 @@ class WcUserScore : WaccaUserEntity() {
var lowestMissCt = Int.MAX_VALUE
var rating = 0
fun ls() = ls(songId, difficulty, clears, clears, grades, score, bestCombo, lowestMissCt, 1, rating)
fun lsMusicUpdate() = ls(songId, difficulty, clears, clears, grades, score, lowestMissCt, 0, 1, rating)
fun ls() = ls(musicId, level, clears, clears, grades, achievement, bestCombo, lowestMissCt, 1, rating)
fun lsMusicUpdate() = ls(musicId, level, clears, clears, grades, achievement, lowestMissCt, 0, 1, rating)
}
@Entity @Table(name = "wacca_user_playlog", uniqueConstraints = [UC("", ["user_id", "song_id", "chart_id", "date_scored"])])
class WcUserPlayLog : WaccaUserEntity() {
var songId = 0
var difficulty = 0
var level = 0.0
var score = 0
@Entity @Table(name = "wacca_user_playlog", uniqueConstraints = [UC("", ["user_id", "music_id", "level", "user_play_date"])])
class WcUserPlayLog : WaccaUserEntity(), IGenericGamePlaylog {
override var musicId = 0
override var level = 0
var levelConst = 0.0
override var achievement = 0
@Convert(converter = IntegerListConverter::class)
var judgements: MutableList<Int> = mutableListOf(0, 0, 0, 0) // Marv, Great, Good, Miss
var maxCombo = 0
override var maxCombo = 0
var grade = 0
var clear = false
var missless = false
var fullCombo = false
var allMarv = false
var isClear = false
var isMissless = false
override var isFullCombo = false
override var isAllPerfect = false
var giveUp = false
var skillPt = 0
var fastCt = 0
var lateCt = 0
var newRecord = false
override var beforeRating = 0
override var afterRating = 0
@Temporal(TemporalType.TIMESTAMP)
var dateScored = Date()
override var userPlayDate = Date()
fun clears() = ls(1, +clear, +fullCombo, +missless, +allMarv)
fun clears() = ls(1, +isClear, +isFullCombo, +isMissless, +isAllPerfect)
companion object {
val keys = ls("songId", "difficulty", "level", "score", "judgements", "maxCombo", "grade", "clear", "missless", "fullCombo", "allMarv", "giveUp", "skillPt", "fastCt", "lateCt", "newRecord")
val keys = ls("musicId", "level", "levelConst", "achievement", "judgements", "maxCombo", "grade", "clear", "missless", "isFullCombo", "isAllPerfect", "giveUp", "skillPt", "fastCt", "lateCt", "newRecord")
fun parse(l: List<*>) = JACKSON.parse<WcUserPlayLog>(keys.zip(l).toMap())
}
}

View File

@ -126,25 +126,27 @@ create table wacca_user_playlog
id bigint auto_increment
primary key,
user_id bigint not null,
song_id int not null,
difficulty int not null,
score int not null,
music_id int not null,
level int not null,
level_const double not null,
achievement int not null,
grade int not null,
max_combo int not null,
fast_ct int not null,
late_ct int not null,
all_marv bit not null,
full_combo bit not null,
is_clear bit not null,
is_missless bit not null,
is_full_combo bit not null,
is_all_perfect bit not null,
give_up bit not null,
judgements varchar(255) not null,
level double not null,
missless bit not null,
new_record bit not null,
skill_pt int not null,
clear bit not null,
date_scored datetime not null,
user_play_date datetime not null,
after_rating int not null,
before_rating int not null,
constraint wacca_user_playlog_unique
unique (user_id, song_id, difficulty, date_scored),
unique (user_id, music_id, level, user_play_date),
constraint fku_wacca_user_playlog
foreign key (user_id) references wacca_user (id)
on update cascade on delete cascade
@ -155,16 +157,16 @@ create table wacca_user_score
id bigint auto_increment
primary key,
user_id bigint not null,
song_id int not null,
difficulty int not null,
score int not null,
music_id int not null,
level int not null,
achievement int not null,
best_combo int not null,
lowest_miss_ct int not null,
rating int not null,
clears varchar(255) not null,
grades varchar(255) not null,
constraint wacca_user_score_unique
unique (user_id, song_id, difficulty),
unique (user_id, music_id, level),
constraint fku_wacca_user_score
foreign key (user_id) references wacca_user (id)
on update cascade on delete cascade