Add on-the-fly rank calculation; change "subscribed" to "subscribed_to_scores"
This commit is contained in:
parent
b2c3ada7c0
commit
330b90b172
|
@ -4,8 +4,11 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/thehowl/go-osuapi.v1"
|
||||||
"zxq.co/ripple/rippleapi/common"
|
"zxq.co/ripple/rippleapi/common"
|
||||||
|
"zxq.co/x/getrank"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Score is a score done on Ripple.
|
// Score is a score done on Ripple.
|
||||||
|
@ -26,6 +29,7 @@ type Score struct {
|
||||||
PlayMode int `json:"play_mode"`
|
PlayMode int `json:"play_mode"`
|
||||||
Accuracy float64 `json:"accuracy"`
|
Accuracy float64 `json:"accuracy"`
|
||||||
PP float32 `json:"pp"`
|
PP float32 `json:"pp"`
|
||||||
|
Rank string `json:"rank"`
|
||||||
Completed int `json:"completed"`
|
Completed int `json:"completed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +116,15 @@ WHERE scores.beatmap_md5 = ? AND scores.completed = '3' AND `+md.User.OnlyUserPu
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.User = u
|
s.User = u
|
||||||
|
s.Rank = strings.ToUpper(getrank.GetRank(
|
||||||
|
osuapi.Mode(s.PlayMode),
|
||||||
|
osuapi.Mods(s.Mods),
|
||||||
|
s.Accuracy,
|
||||||
|
s.Count300,
|
||||||
|
s.Count100,
|
||||||
|
s.Count50,
|
||||||
|
s.CountMiss,
|
||||||
|
))
|
||||||
r.Scores = append(r.Scores, s)
|
r.Scores = append(r.Scores, s)
|
||||||
}
|
}
|
||||||
r.Code = 200
|
r.Code = 200
|
||||||
|
|
|
@ -2,8 +2,11 @@ package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/thehowl/go-osuapi.v1"
|
||||||
"zxq.co/ripple/rippleapi/common"
|
"zxq.co/ripple/rippleapi/common"
|
||||||
|
"zxq.co/x/getrank"
|
||||||
)
|
)
|
||||||
|
|
||||||
type userScore struct {
|
type userScore struct {
|
||||||
|
@ -106,6 +109,15 @@ func scoresPuts(md common.MethodData, whereClause string, params ...interface{})
|
||||||
}
|
}
|
||||||
b.Difficulty = b.Diff2.STD
|
b.Difficulty = b.Diff2.STD
|
||||||
us.Beatmap = b
|
us.Beatmap = b
|
||||||
|
us.Rank = strings.ToUpper(getrank.GetRank(
|
||||||
|
osuapi.Mode(us.PlayMode),
|
||||||
|
osuapi.Mods(us.Mods),
|
||||||
|
us.Accuracy,
|
||||||
|
us.Count300,
|
||||||
|
us.Count100,
|
||||||
|
us.Count50,
|
||||||
|
us.CountMiss,
|
||||||
|
))
|
||||||
scores = append(scores, us)
|
scores = append(scores, us)
|
||||||
}
|
}
|
||||||
r := userScoresResponse{}
|
r := userScoresResponse{}
|
||||||
|
|
|
@ -71,7 +71,7 @@ var messageHandler = map[string]func(c *conn, message incomingMessage){
|
||||||
const (
|
const (
|
||||||
TypeConnected = "connected"
|
TypeConnected = "connected"
|
||||||
TypeInvalidMessage = "invalid_message_type"
|
TypeInvalidMessage = "invalid_message_type"
|
||||||
TypeSubscribed = "subscribed"
|
TypeSubscribedToScores = "subscribed_to_scores"
|
||||||
TypeNewScore = "new_score"
|
TypeNewScore = "new_score"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,12 @@ package websockets
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"gopkg.in/thehowl/go-osuapi.v1"
|
||||||
"zxq.co/ripple/rippleapi/app/v1"
|
"zxq.co/ripple/rippleapi/app/v1"
|
||||||
|
"zxq.co/x/getrank"
|
||||||
)
|
)
|
||||||
|
|
||||||
type subscribeScoresUser struct {
|
type subscribeScoresUser struct {
|
||||||
|
@ -40,7 +43,7 @@ func SubscribeScores(c *conn, message incomingMessage) {
|
||||||
|
|
||||||
scoreSubscriptionsMtx.Unlock()
|
scoreSubscriptionsMtx.Unlock()
|
||||||
|
|
||||||
c.WriteJSON(TypeSubscribed, ssu)
|
c.WriteJSON(TypeSubscribedToScores, ssu)
|
||||||
}
|
}
|
||||||
|
|
||||||
type scoreSubscription struct {
|
type scoreSubscription struct {
|
||||||
|
@ -83,6 +86,15 @@ FROM scores WHERE id = ?`, id)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.Rank = strings.ToUpper(getrank.GetRank(
|
||||||
|
osuapi.Mode(s.PlayMode),
|
||||||
|
osuapi.Mods(s.Mods),
|
||||||
|
s.Accuracy,
|
||||||
|
s.Count300,
|
||||||
|
s.Count100,
|
||||||
|
s.Count50,
|
||||||
|
s.CountMiss,
|
||||||
|
))
|
||||||
scoreSubscriptionsMtx.RLock()
|
scoreSubscriptionsMtx.RLock()
|
||||||
cp := make([]scoreSubscription, len(scoreSubscriptions))
|
cp := make([]scoreSubscription, len(scoreSubscriptions))
|
||||||
copy(cp, scoreSubscriptions)
|
copy(cp, scoreSubscriptions)
|
||||||
|
|
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
|
@ -201,10 +201,10 @@
|
||||||
"revisionTime": "2016-11-23T19:03:31Z"
|
"revisionTime": "2016-11-23T19:03:31Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "ItsAqvnH+Qa+ewmWbnSxT6EzSBk=",
|
"checksumSHA1": "9wL5kcCkaY+bXT/mEp+67/M+6rU=",
|
||||||
"path": "zxq.co/x/getrank",
|
"path": "zxq.co/x/getrank",
|
||||||
"revision": "e62f5bd6998d8d75fe3a2ff1becc9df06e88e3a6",
|
"revision": "97d2823cf77de9e0c95e89485df768518b6262a9",
|
||||||
"revisionTime": "2016-05-28T18:25:35Z"
|
"revisionTime": "2017-04-18T18:31:09Z"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"rootPath": "zxq.co/ripple/rippleapi"
|
"rootPath": "zxq.co/ripple/rippleapi"
|
||||||
|
|
18
vendor/zxq.co/x/getrank/getrank.go
vendored
18
vendor/zxq.co/x/getrank/getrank.go
vendored
|
@ -13,7 +13,7 @@ func GetRank(gameMode osuapi.Mode, mods osuapi.Mods, acc float64, c300, c100, c5
|
||||||
total := c300 + c100 + c50 + cmiss
|
total := c300 + c100 + c50 + cmiss
|
||||||
|
|
||||||
switch gameMode {
|
switch gameMode {
|
||||||
case osuapi.ModeOsu:
|
case osuapi.ModeOsu, osuapi.ModeTaiko:
|
||||||
var (
|
var (
|
||||||
c300f = float64(c300)
|
c300f = float64(c300)
|
||||||
totalf = float64(total)
|
totalf = float64(total)
|
||||||
|
@ -33,22 +33,6 @@ func GetRank(gameMode osuapi.Mode, mods osuapi.Mods, acc float64, c300, c100, c5
|
||||||
}
|
}
|
||||||
return "d"
|
return "d"
|
||||||
|
|
||||||
case osuapi.ModeTaiko:
|
|
||||||
switch {
|
|
||||||
case acc == 100:
|
|
||||||
return s(true, mods)
|
|
||||||
case acc >= 95:
|
|
||||||
return s(false, mods)
|
|
||||||
case acc >= 90:
|
|
||||||
return "a"
|
|
||||||
case acc >= 80:
|
|
||||||
return "b"
|
|
||||||
// untested
|
|
||||||
case acc >= 70:
|
|
||||||
return "c"
|
|
||||||
}
|
|
||||||
return "d"
|
|
||||||
|
|
||||||
case osuapi.ModeCatchTheBeat:
|
case osuapi.ModeCatchTheBeat:
|
||||||
if acc == 100 {
|
if acc == 100 {
|
||||||
if mods&silver > 0 {
|
if mods&silver > 0 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user