Add rx and ap

This commit is contained in:
Alicia 2019-02-03 12:49:32 +00:00
parent 2eda6c7aff
commit 333ca2743d
3 changed files with 34 additions and 34 deletions

View File

@ -11,10 +11,10 @@ import (
"gopkg.in/redis.v5" "gopkg.in/redis.v5"
"zxq.co/ripple/rippleapi/app/internals" "zxq.co/ripple/rippleapi/app/internals"
"zxq.co/ripple/rippleapi/app/peppy" "zxq.co/ripple/rippleapi/app/peppy"
"zxq.co/ripple/rippleapi/app/v1" "github.com/qewc/api/app/v1"
"zxq.co/ripple/rippleapi/app/websockets" "zxq.co/ripple/rippleapi/app/websockets"
"zxq.co/ripple/rippleapi/common" "zxq.co/ripple/rippleapi/common"
) )
var ( var (
db *sqlx.DB db *sqlx.DB

View File

@ -21,12 +21,12 @@ type userScoresResponse struct {
const userScoreSelectBase = ` const userScoreSelectBase = `
SELECT SELECT
scores.id, scores.beatmap_md5, scores.score, scores_auto.id, scores_auto.beatmap_md5, scores_auto.score,
scores.max_combo, scores.full_combo, scores.mods, scores_auto.max_combo, scores_auto.full_combo, scores_auto.mods,
scores.300_count, scores.100_count, scores.50_count, scores_auto.300_count, scores_auto.100_count, scores_auto.50_count,
scores.gekis_count, scores.katus_count, scores.misses_count, scores_auto.gekis_count, scores_auto.katus_count, scores_auto.misses_count,
scores.time, scores.play_mode, scores.accuracy, scores.pp, scores_auto.time, scores_auto.play_mode, scores_auto.accuracy, scores_auto.pp,
scores.completed, scores_auto.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_std, beatmaps.song_name, beatmaps.ar, beatmaps.od, beatmaps.difficulty_std,
@ -34,35 +34,35 @@ SELECT
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
INNER JOIN beatmaps ON beatmaps.beatmap_md5 = scores.beatmap_md5 INNER JOIN beatmaps ON beatmaps.beatmap_md5 = scores_auto.beatmap_md5
INNER JOIN users ON users.id = scores.userid INNER JOIN users ON users.id = scores_auto.userid
` `
// UserScoresBestGET retrieves the best scores of an user, sorted by PP if // UserScoresBestGET retrieves the best scores of an user, sorted by PP if
// mode is standard and sorted by ranked score otherwise. // mode is standard and sorted by ranked score otherwise.
func UserScoresBestGET(md common.MethodData) common.CodeMessager { func UserScoresBestAPGET(md common.MethodData) common.CodeMessager {
cm, wc, param := whereClauseUser(md, "users") cm, wc, param := whereClauseUser(md, "users")
if cm != nil { if cm != nil {
return *cm return *cm
} }
mc := genModeClause(md) mc := genModeClause(md)
// For all modes that have PP, we leave out 0 PP scores. // For all modes that have PP, we leave out 0 PP scores_auto.
if getMode(md.Query("mode")) != "ctb" { if getMode(md.Query("mode")) != "ctb" {
mc += " AND scores.pp > 0" mc += " AND scores_auto.pp > 0"
} }
return scoresPuts(md, fmt.Sprintf( return scoresPuts(md, fmt.Sprintf(
`WHERE `WHERE
scores.completed = '3' scores_auto.completed = '3'
AND %s AND %s
%s %s
AND `+md.User.OnlyUserPublic(true)+` AND `+md.User.OnlyUserPublic(true)+`
ORDER BY scores.pp DESC, scores.score DESC %s`, ORDER BY scores_auto.pp DESC, scores_auto.score DESC %s`,
wc, mc, common.Paginate(md.Query("p"), md.Query("l"), 100), wc, mc, common.Paginate(md.Query("p"), md.Query("l"), 100),
), param) ), param)
} }
// UserScoresRecentGET retrieves an user's latest scores. // UserScoresRecentGET retrieves an user's latest scores_auto.
func UserScoresRecentGET(md common.MethodData) common.CodeMessager { func UserScoresRecentAPGET(md common.MethodData) common.CodeMessager {
cm, wc, param := whereClauseUser(md, "users") cm, wc, param := whereClauseUser(md, "users")
if cm != nil { if cm != nil {
return *cm return *cm
@ -72,7 +72,7 @@ func UserScoresRecentGET(md common.MethodData) common.CodeMessager {
%s %s
%s %s
AND `+md.User.OnlyUserPublic(true)+` AND `+md.User.OnlyUserPublic(true)+`
ORDER BY scores.id DESC %s`, ORDER BY scores_auto.id DESC %s`,
wc, genModeClause(md), common.Paginate(md.Query("p"), md.Query("l"), 100), wc, genModeClause(md), common.Paginate(md.Query("p"), md.Query("l"), 100),
), param) ), param)
} }

View File

@ -21,12 +21,12 @@ type userScoresResponse struct {
const userScoreSelectBase = ` const userScoreSelectBase = `
SELECT SELECT
scores.id, scores.beatmap_md5, scores.score, scores_relax.id, scores_relax.beatmap_md5, scores_relax.score,
scores.max_combo, scores.full_combo, scores.mods, scores_relax.max_combo, scores_relax.full_combo, scores_relax.mods,
scores.300_count, scores.100_count, scores.50_count, scores_relax.300_count, scores_relax.100_count, scores_relax.50_count,
scores.gekis_count, scores.katus_count, scores.misses_count, scores_relax.gekis_count, scores_relax.katus_count, scores_relax.misses_count,
scores.time, scores.play_mode, scores.accuracy, scores.pp, scores_relax.time, scores_relax.play_mode, scores_relax.accuracy, scores_relax.pp,
scores.completed, scores_relax.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_std, beatmaps.song_name, beatmaps.ar, beatmaps.od, beatmaps.difficulty_std,
@ -34,35 +34,35 @@ SELECT
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
INNER JOIN beatmaps ON beatmaps.beatmap_md5 = scores.beatmap_md5 INNER JOIN beatmaps ON beatmaps.beatmap_md5 = scores_relax.beatmap_md5
INNER JOIN users ON users.id = scores.userid INNER JOIN users ON users.id = scores_relax.userid
` `
// UserScoresBestGET retrieves the best scores of an user, sorted by PP if // UserScoresBestGET retrieves the best scores of an user, sorted by PP if
// mode is standard and sorted by ranked score otherwise. // mode is standard and sorted by ranked score otherwise.
func UserScoresBestGET(md common.MethodData) common.CodeMessager { func UserScoresBestRelaxGET(md common.MethodData) common.CodeMessager {
cm, wc, param := whereClauseUser(md, "users") cm, wc, param := whereClauseUser(md, "users")
if cm != nil { if cm != nil {
return *cm return *cm
} }
mc := genModeClause(md) mc := genModeClause(md)
// For all modes that have PP, we leave out 0 PP scores. // For all modes that have PP, we leave out 0 PP scores_relax.
if getMode(md.Query("mode")) != "ctb" { if getMode(md.Query("mode")) != "ctb" {
mc += " AND scores.pp > 0" mc += " AND scores_relax.pp > 0"
} }
return scoresPuts(md, fmt.Sprintf( return scoresPuts(md, fmt.Sprintf(
`WHERE `WHERE
scores.completed = '3' scores_relax.completed = '3'
AND %s AND %s
%s %s
AND `+md.User.OnlyUserPublic(true)+` AND `+md.User.OnlyUserPublic(true)+`
ORDER BY scores.pp DESC, scores.score DESC %s`, ORDER BY scores_relax.pp DESC, scores_relax.score DESC %s`,
wc, mc, common.Paginate(md.Query("p"), md.Query("l"), 100), wc, mc, common.Paginate(md.Query("p"), md.Query("l"), 100),
), param) ), param)
} }
// UserScoresRecentGET retrieves an user's latest scores. // UserScoresRecentGET retrieves an user's latest scores_relax.
func UserScoresRecentGET(md common.MethodData) common.CodeMessager { func UserScoresRecentRelaxGET(md common.MethodData) common.CodeMessager {
cm, wc, param := whereClauseUser(md, "users") cm, wc, param := whereClauseUser(md, "users")
if cm != nil { if cm != nil {
return *cm return *cm
@ -72,7 +72,7 @@ func UserScoresRecentGET(md common.MethodData) common.CodeMessager {
%s %s
%s %s
AND `+md.User.OnlyUserPublic(true)+` AND `+md.User.OnlyUserPublic(true)+`
ORDER BY scores.id DESC %s`, ORDER BY scores_relax.id DESC %s`,
wc, genModeClause(md), common.Paginate(md.Query("p"), md.Query("l"), 100), wc, genModeClause(md), common.Paginate(md.Query("p"), md.Query("l"), 100),
), param) ), param)
} }