2016-05-14 19:02:05 +00:00
|
|
|
package v1
|
|
|
|
|
2016-05-19 15:15:17 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2017-04-18 19:08:06 +00:00
|
|
|
"strings"
|
2016-05-14 19:02:05 +00:00
|
|
|
|
2017-04-18 19:08:06 +00:00
|
|
|
"gopkg.in/thehowl/go-osuapi.v1"
|
2019-02-25 21:04:55 +00:00
|
|
|
"github.com/osuyozora/api/common"
|
2017-04-18 19:08:06 +00:00
|
|
|
"zxq.co/x/getrank"
|
2016-05-19 15:15:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type userScore struct {
|
2017-02-19 17:19:59 +00:00
|
|
|
Score
|
2016-07-18 21:27:37 +00:00
|
|
|
Beatmap beatmap `json:"beatmap"`
|
2016-05-19 15:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type userScoresResponse struct {
|
|
|
|
common.ResponseBase
|
|
|
|
Scores []userScore `json:"scores"`
|
|
|
|
}
|
|
|
|
|
|
|
|
const userScoreSelectBase = `
|
|
|
|
SELECT
|
|
|
|
scores.id, scores.beatmap_md5, scores.score,
|
|
|
|
scores.max_combo, scores.full_combo, scores.mods,
|
|
|
|
scores.300_count, scores.100_count, scores.50_count,
|
|
|
|
scores.gekis_count, scores.katus_count, scores.misses_count,
|
|
|
|
scores.time, scores.play_mode, scores.accuracy, scores.pp,
|
2016-05-22 14:22:13 +00:00
|
|
|
scores.completed,
|
2016-07-03 19:55:03 +00:00
|
|
|
|
2016-05-19 15:15:17 +00:00
|
|
|
beatmaps.beatmap_id, beatmaps.beatmapset_id, beatmaps.beatmap_md5,
|
2016-07-18 21:27:37 +00:00
|
|
|
beatmaps.song_name, beatmaps.ar, beatmaps.od, beatmaps.difficulty_std,
|
|
|
|
beatmaps.difficulty_taiko, beatmaps.difficulty_ctb, beatmaps.difficulty_mania,
|
2016-05-19 15:15:17 +00:00
|
|
|
beatmaps.max_combo, beatmaps.hit_length, beatmaps.ranked,
|
|
|
|
beatmaps.ranked_status_freezed, beatmaps.latest_update
|
|
|
|
FROM scores
|
2016-07-20 08:49:29 +00:00
|
|
|
INNER JOIN beatmaps ON beatmaps.beatmap_md5 = scores.beatmap_md5
|
|
|
|
INNER JOIN users ON users.id = scores.userid
|
2016-05-19 15:15:17 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
// UserScoresBestGET retrieves the best scores of an user, sorted by PP if
|
|
|
|
// mode is standard and sorted by ranked score otherwise.
|
|
|
|
func UserScoresBestGET(md common.MethodData) common.CodeMessager {
|
|
|
|
cm, wc, param := whereClauseUser(md, "users")
|
|
|
|
if cm != nil {
|
|
|
|
return *cm
|
|
|
|
}
|
2016-05-26 19:13:36 +00:00
|
|
|
mc := genModeClause(md)
|
2017-09-18 19:38:33 +00:00
|
|
|
// For all modes that have PP, we leave out 0 PP scores.
|
|
|
|
if getMode(md.Query("mode")) != "ctb" {
|
2016-05-26 19:13:36 +00:00
|
|
|
mc += " AND scores.pp > 0"
|
|
|
|
}
|
2016-05-19 15:15:17 +00:00
|
|
|
return scoresPuts(md, fmt.Sprintf(
|
|
|
|
`WHERE
|
2016-07-03 19:55:03 +00:00
|
|
|
scores.completed = '3'
|
2016-05-19 15:15:17 +00:00
|
|
|
AND %s
|
|
|
|
%s
|
2016-08-27 10:04:12 +00:00
|
|
|
AND `+md.User.OnlyUserPublic(true)+`
|
2016-05-19 15:15:17 +00:00
|
|
|
ORDER BY scores.pp DESC, scores.score DESC %s`,
|
2016-08-15 17:59:46 +00:00
|
|
|
wc, mc, common.Paginate(md.Query("p"), md.Query("l"), 100),
|
2016-05-19 15:31:49 +00:00
|
|
|
), param)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserScoresRecentGET retrieves an user's latest scores.
|
|
|
|
func UserScoresRecentGET(md common.MethodData) common.CodeMessager {
|
|
|
|
cm, wc, param := whereClauseUser(md, "users")
|
|
|
|
if cm != nil {
|
|
|
|
return *cm
|
|
|
|
}
|
|
|
|
return scoresPuts(md, fmt.Sprintf(
|
|
|
|
`WHERE
|
|
|
|
%s
|
|
|
|
%s
|
2016-08-27 10:04:12 +00:00
|
|
|
AND `+md.User.OnlyUserPublic(true)+`
|
2016-10-29 15:07:29 +00:00
|
|
|
ORDER BY scores.id DESC %s`,
|
2016-08-15 17:59:46 +00:00
|
|
|
wc, genModeClause(md), common.Paginate(md.Query("p"), md.Query("l"), 100),
|
2016-05-19 15:15:17 +00:00
|
|
|
), param)
|
|
|
|
}
|
|
|
|
|
|
|
|
func scoresPuts(md common.MethodData, whereClause string, params ...interface{}) common.CodeMessager {
|
|
|
|
rows, err := md.DB.Query(userScoreSelectBase+whereClause, params...)
|
|
|
|
if err != nil {
|
|
|
|
md.Err(err)
|
|
|
|
return Err500
|
|
|
|
}
|
|
|
|
var scores []userScore
|
|
|
|
for rows.Next() {
|
|
|
|
var (
|
2016-07-06 20:32:30 +00:00
|
|
|
us userScore
|
2016-07-18 21:27:37 +00:00
|
|
|
b beatmap
|
2016-05-19 15:15:17 +00:00
|
|
|
)
|
|
|
|
err = rows.Scan(
|
2017-02-19 18:01:13 +00:00
|
|
|
&us.ID, &us.BeatmapMD5, &us.Score.Score,
|
2016-05-19 15:15:17 +00:00
|
|
|
&us.MaxCombo, &us.FullCombo, &us.Mods,
|
|
|
|
&us.Count300, &us.Count100, &us.Count50,
|
|
|
|
&us.CountGeki, &us.CountKatu, &us.CountMiss,
|
2016-08-15 17:59:46 +00:00
|
|
|
&us.Time, &us.PlayMode, &us.Accuracy, &us.PP,
|
2016-05-22 14:22:13 +00:00
|
|
|
&us.Completed,
|
2016-05-19 15:15:17 +00:00
|
|
|
|
|
|
|
&b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5,
|
2016-07-18 21:27:37 +00:00
|
|
|
&b.SongName, &b.AR, &b.OD, &b.Diff2.STD,
|
|
|
|
&b.Diff2.Taiko, &b.Diff2.CTB, &b.Diff2.Mania,
|
2016-05-19 15:15:17 +00:00
|
|
|
&b.MaxCombo, &b.HitLength, &b.Ranked,
|
2016-07-06 20:32:30 +00:00
|
|
|
&b.RankedStatusFrozen, &b.LatestUpdate,
|
2016-05-19 15:15:17 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
md.Err(err)
|
|
|
|
return Err500
|
|
|
|
}
|
2016-08-15 17:59:46 +00:00
|
|
|
b.Difficulty = b.Diff2.STD
|
2016-07-18 21:27:37 +00:00
|
|
|
us.Beatmap = b
|
2017-04-18 19:08:06 +00:00
|
|
|
us.Rank = strings.ToUpper(getrank.GetRank(
|
|
|
|
osuapi.Mode(us.PlayMode),
|
|
|
|
osuapi.Mods(us.Mods),
|
|
|
|
us.Accuracy,
|
|
|
|
us.Count300,
|
|
|
|
us.Count100,
|
|
|
|
us.Count50,
|
|
|
|
us.CountMiss,
|
|
|
|
))
|
2016-05-19 15:15:17 +00:00
|
|
|
scores = append(scores, us)
|
|
|
|
}
|
|
|
|
r := userScoresResponse{}
|
|
|
|
r.Code = 200
|
|
|
|
r.Scores = scores
|
|
|
|
return r
|
2016-05-14 19:02:05 +00:00
|
|
|
}
|