hey nyo i may or may not have fixed beatmap difficulties

This commit is contained in:
Howl 2016-07-18 23:27:37 +02:00
parent a999033e4b
commit 3a2928be53
2 changed files with 24 additions and 43 deletions

View File

@ -6,6 +6,13 @@ import (
"git.zxq.co/ripple/rippleapi/common" "git.zxq.co/ripple/rippleapi/common"
) )
type difficulty struct {
STD float64 `json:"std"`
Taiko float64 `json:"taiko"`
CTB float64 `json:"ctb"`
Mania float64 `json:"mania"`
}
type beatmap struct { type beatmap struct {
BeatmapID int `json:"beatmap_id"` BeatmapID int `json:"beatmap_id"`
BeatmapsetID int `json:"beatmapset_id"` BeatmapsetID int `json:"beatmapset_id"`
@ -14,6 +21,7 @@ type beatmap struct {
AR float32 `json:"ar"` AR float32 `json:"ar"`
OD float32 `json:"od"` OD float32 `json:"od"`
Difficulty float64 `json:"difficulty"` Difficulty float64 `json:"difficulty"`
Diff2 difficulty `json:"difficulty2"` // fuck nyo
MaxCombo int `json:"max_combo"` MaxCombo int `json:"max_combo"`
HitLength int `json:"hit_length"` HitLength int `json:"hit_length"`
Ranked int `json:"ranked"` Ranked int `json:"ranked"`
@ -21,41 +29,6 @@ type beatmap struct {
LatestUpdate common.UnixTimestamp `json:"latest_update"` LatestUpdate common.UnixTimestamp `json:"latest_update"`
} }
type beatmapMayOrMayNotExist struct {
BeatmapID *int
BeatmapsetID *int
BeatmapMD5 *string
SongName *string
AR *float32
OD *float32
Difficulty *float64
MaxCombo *int
HitLength *int
Ranked *int
RankedStatusFrozen *int
LatestUpdate *common.UnixTimestamp
}
func (b *beatmapMayOrMayNotExist) toBeatmap() *beatmap {
if b == nil || b.BeatmapID == nil {
return nil
}
return &beatmap{
BeatmapID: *b.BeatmapID,
BeatmapsetID: *b.BeatmapsetID,
BeatmapMD5: *b.BeatmapMD5,
SongName: *b.SongName,
AR: *b.AR,
OD: *b.OD,
Difficulty: *b.Difficulty,
MaxCombo: *b.MaxCombo,
HitLength: *b.HitLength,
Ranked: *b.Ranked,
RankedStatusFrozen: *b.RankedStatusFrozen,
LatestUpdate: *b.LatestUpdate,
}
}
type beatmapResponse struct { type beatmapResponse struct {
common.ResponseBase common.ResponseBase
beatmap beatmap
@ -131,7 +104,8 @@ func BeatmapGET(md common.MethodData) common.CodeMessager {
const baseBeatmapSelect = ` const baseBeatmapSelect = `
SELECT SELECT
beatmap_id, beatmapset_id, beatmap_md5, beatmap_id, beatmapset_id, beatmap_md5,
song_name, ar, od, difficulty, max_combo, song_name, ar, od, difficulty_std, difficulty_taiko,
difficulty_ctb, difficulty_mania, max_combo,
hit_length, ranked, ranked_status_freezed, hit_length, ranked, ranked_status_freezed,
latest_update latest_update
FROM beatmaps FROM beatmaps
@ -148,10 +122,12 @@ func getSet(md common.MethodData, setID int) common.CodeMessager {
var b beatmap var b beatmap
err = rows.Scan( err = rows.Scan(
&b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5, &b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5,
&b.SongName, &b.AR, &b.OD, &b.Difficulty, &b.MaxCombo, &b.SongName, &b.AR, &b.OD, &b.Diff2.STD, &b.Diff2.Taiko,
&b.Diff2.CTB, &b.Diff2.Mania, &b.MaxCombo,
&b.HitLength, &b.Ranked, &b.RankedStatusFrozen, &b.HitLength, &b.Ranked, &b.RankedStatusFrozen,
&b.LatestUpdate, &b.LatestUpdate,
) )
b.Difficulty = b.Diff2.STD
if err != nil { if err != nil {
md.Err(err) md.Err(err)
continue continue
@ -166,10 +142,12 @@ func getBeatmap(md common.MethodData, beatmapID int) common.CodeMessager {
var b beatmap var b beatmap
err := md.DB.QueryRow(baseBeatmapSelect+"WHERE beatmap_id = ? LIMIT 1", beatmapID).Scan( err := md.DB.QueryRow(baseBeatmapSelect+"WHERE beatmap_id = ? LIMIT 1", beatmapID).Scan(
&b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5, &b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5,
&b.SongName, &b.AR, &b.OD, &b.Difficulty, &b.MaxCombo, &b.SongName, &b.AR, &b.OD, &b.Diff2.STD, &b.Diff2.Taiko,
&b.Diff2.CTB, &b.Diff2.Mania, &b.MaxCombo,
&b.HitLength, &b.Ranked, &b.RankedStatusFrozen, &b.HitLength, &b.Ranked, &b.RankedStatusFrozen,
&b.LatestUpdate, &b.LatestUpdate,
) )
b.Difficulty = b.Diff2.STD
switch { switch {
case err == sql.ErrNoRows: case err == sql.ErrNoRows:
return common.SimpleResponse(404, "That beatmap could not be found!") return common.SimpleResponse(404, "That beatmap could not be found!")

View File

@ -30,7 +30,7 @@ type score struct {
type userScore struct { type userScore struct {
score score
Beatmap *beatmap `json:"beatmap"` Beatmap beatmap `json:"beatmap"`
} }
type userScoresResponse struct { type userScoresResponse struct {
@ -48,7 +48,8 @@ SELECT
scores.completed, scores.completed,
beatmaps.beatmap_id, beatmaps.beatmapset_id, beatmaps.beatmap_md5, beatmaps.beatmap_id, beatmaps.beatmapset_id, beatmaps.beatmap_md5,
beatmaps.song_name, beatmaps.ar, beatmaps.od, beatmaps.difficulty, beatmaps.song_name, beatmaps.ar, beatmaps.od, beatmaps.difficulty_std,
beatmaps.difficulty_taiko, beatmaps.difficulty_ctb, beatmaps.difficulty_mania,
beatmaps.max_combo, beatmaps.hit_length, beatmaps.ranked, beatmaps.max_combo, beatmaps.hit_length, beatmaps.ranked,
beatmaps.ranked_status_freezed, beatmaps.latest_update beatmaps.ranked_status_freezed, beatmaps.latest_update
FROM scores FROM scores
@ -130,7 +131,7 @@ func scoresPuts(md common.MethodData, whereClause string, params ...interface{})
var ( var (
us userScore us userScore
t string t string
b beatmapMayOrMayNotExist b beatmap
) )
err = rows.Scan( err = rows.Scan(
&us.ID, &us.BeatmapMD5, &us.Score, &us.ID, &us.BeatmapMD5, &us.Score,
@ -141,10 +142,12 @@ func scoresPuts(md common.MethodData, whereClause string, params ...interface{})
&us.Completed, &us.Completed,
&b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5, &b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5,
&b.SongName, &b.AR, &b.OD, &b.Difficulty, &b.SongName, &b.AR, &b.OD, &b.Diff2.STD,
&b.Diff2.Taiko, &b.Diff2.CTB, &b.Diff2.Mania,
&b.MaxCombo, &b.HitLength, &b.Ranked, &b.MaxCombo, &b.HitLength, &b.Ranked,
&b.RankedStatusFrozen, &b.LatestUpdate, &b.RankedStatusFrozen, &b.LatestUpdate,
) )
b.Difficulty = b.Diff2.STD
if err != nil { if err != nil {
md.Err(err) md.Err(err)
return Err500 return Err500
@ -155,7 +158,7 @@ func scoresPuts(md common.MethodData, whereClause string, params ...interface{})
md.Err(err) md.Err(err)
return Err500 return Err500
} }
us.Beatmap = b.toBeatmap() us.Beatmap = b
scores = append(scores, us) scores = append(scores, us)
} }
r := userScoresResponse{} r := userScoresResponse{}