refactor: 重构数据库逻辑

This commit is contained in:
lixiangwuxian
2024-10-11 00:14:11 +08:00
parent 7aebdeae56
commit 769308389a
16 changed files with 289 additions and 164 deletions

View File

@@ -129,6 +129,7 @@ type RecordDataLite struct {
MissedNotes int `json:"missedNotes" db:"missed_notes"`
MaxCombo int `json:"maxCombo" db:"max_combo"`
Score int `json:"score" db:"score"`
MaxScore int `json:"maxScore" db:"max_score"`
FullCombo bool `json:"fullCombo" db:"full_combo"`
DeviceHmd string `json:"deviceHmd" db:"device_hmd"`
DeviceControllerLeft string `json:"deviceControllerLeft" db:"device_controller_left"`
@@ -137,19 +138,19 @@ type RecordDataLite struct {
}
func (r RecordDataLite) ToString() string {
formatedStrRanked := "使用 %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分pp 为 %.2f。"
formatedStrUnranked := "使用 %s 在 %s 的 %s 难度中获得了 %d 分。"
formatedStrWithoutDevice := "在 %s 的 %s 难度(%.1f星级)中获得了 %d 分pp 为 %.2f。"
formatedStrWithoutDeviceAndRank := "在 %s 的 %s 难度(%.1f星级)中获得了 %d 分。"
formatedStrRanked := "%s 使用 %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分pp 为 %.2f,准度为 %s。"
formatedStrUnranked := "%s 使用 %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。"
formatedStrWithoutDevice := "%s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分pp 为 %.2f,准度为 %s。"
formatedStrWithoutDeviceAndRank := "%s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,准度为 %s。"
hardStr := strings.Split(r.DifficultyRaw, "_")[1]
if r.Stars == 0 && r.DeviceHmd != "" {
return fmt.Sprintf(formatedStrUnranked, r.DeviceHmd, r.SongName, hardStr, r.Score)
return fmt.Sprintf(formatedStrUnranked, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
} else if r.Stars != 0 && r.DeviceHmd != "" {
return fmt.Sprintf(formatedStrRanked, r.DeviceHmd, r.SongName, hardStr, r.Stars, r.Score, r.PP)
return fmt.Sprintf(formatedStrRanked, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
} else if r.Stars != 0 && r.DeviceHmd == "" {
return fmt.Sprintf(formatedStrWithoutDevice, r.SongName, hardStr, r.Stars, r.Score, r.PP)
return fmt.Sprintf(formatedStrWithoutDevice, r.Name, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
} else {
return fmt.Sprintf(formatedStrWithoutDeviceAndRank, r.SongName, hardStr, r.Stars, r.Score)
return fmt.Sprintf(formatedStrWithoutDeviceAndRank, r.Name, r.SongName, hardStr, r.Stars, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
}
}
@@ -186,20 +187,20 @@ type PlayerData struct {
}
type PlayerDataLite struct {
ID string `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Country string `json:"country" db:"country"`
Device string `json:"device" db:"device"`
PP float64 `json:"pp" db:"pp"`
Rank int `json:"rank" db:"rank"`
CountryRank int `json:"countryRank" db:"country_rank"`
TotalScore int `json:"totalScore" db:"total_score"`
TotalRankedScore int `json:"totalRankedScore" db:"total_ranked_score"`
AverageRankedAccuracy float64 `json:"averageRankedAccuracy" db:"average_ranked_accuracy"`
TotalPlayCount int `json:"totalPlayCount" db:"total_play_count"`
RankedPlayCount int `json:"rankedPlayCount" db:"ranked_play_count"`
ReplaysWatched int `json:"replaysWatched" db:"replays_watched"`
GeneratedTime time.Time `json:"generatedTime" db:"generated_time"`
ID string `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Country string `json:"country" db:"country"`
Device string `json:"device" db:"device"`
PP float64 `json:"pp" db:"pp"`
Rank int `json:"rank" db:"rank"`
CountryRank int `json:"countryRank" db:"country_rank"`
TotalScore int `json:"totalScore" db:"total_score"`
TotalRankedScore int `json:"totalRankedScore" db:"total_ranked_score"`
AverageRankedAccuracy float64 `json:"averageRankedAccuracy" db:"average_ranked_accuracy"`
TotalPlayCount int `json:"totalPlayCount" db:"total_play_count"`
RankedPlayCount int `json:"rankedPlayCount" db:"ranked_play_count"`
ReplaysWatched int `json:"replaysWatched" db:"replays_watched"`
GeneratedTime string `json:"generatedTime" db:"generated_time"`
}
func (p PlayerData) ToString() string {