Add on-the-fly rank calculation; change "subscribed" to "subscribed_to_scores"

This commit is contained in:
Morgan Bazalgette
2017-04-18 21:08:06 +02:00
parent b2c3ada7c0
commit 330b90b172
6 changed files with 46 additions and 25 deletions

View File

@@ -4,8 +4,11 @@ import (
"database/sql"
"fmt"
"strconv"
"strings"
"gopkg.in/thehowl/go-osuapi.v1"
"zxq.co/ripple/rippleapi/common"
"zxq.co/x/getrank"
)
// Score is a score done on Ripple.
@@ -26,6 +29,7 @@ type Score struct {
PlayMode int `json:"play_mode"`
Accuracy float64 `json:"accuracy"`
PP float32 `json:"pp"`
Rank string `json:"rank"`
Completed int `json:"completed"`
}
@@ -112,6 +116,15 @@ WHERE scores.beatmap_md5 = ? AND scores.completed = '3' AND `+md.User.OnlyUserPu
continue
}
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.Code = 200

View File

@@ -2,8 +2,11 @@ package v1
import (
"fmt"
"strings"
"gopkg.in/thehowl/go-osuapi.v1"
"zxq.co/ripple/rippleapi/common"
"zxq.co/x/getrank"
)
type userScore struct {
@@ -106,6 +109,15 @@ func scoresPuts(md common.MethodData, whereClause string, params ...interface{})
}
b.Difficulty = b.Diff2.STD
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)
}
r := userScoresResponse{}

View File

@@ -69,10 +69,10 @@ var messageHandler = map[string]func(c *conn, message incomingMessage){
// Server Message Types
const (
TypeConnected = "connected"
TypeInvalidMessage = "invalid_message_type"
TypeSubscribed = "subscribed"
TypeNewScore = "new_score"
TypeConnected = "connected"
TypeInvalidMessage = "invalid_message_type"
TypeSubscribedToScores = "subscribed_to_scores"
TypeNewScore = "new_score"
)
// Client Message Types

View File

@@ -3,9 +3,12 @@ package websockets
import (
"encoding/json"
"fmt"
"strings"
"sync"
"gopkg.in/thehowl/go-osuapi.v1"
"zxq.co/ripple/rippleapi/app/v1"
"zxq.co/x/getrank"
)
type subscribeScoresUser struct {
@@ -40,7 +43,7 @@ func SubscribeScores(c *conn, message incomingMessage) {
scoreSubscriptionsMtx.Unlock()
c.WriteJSON(TypeSubscribed, ssu)
c.WriteJSON(TypeSubscribedToScores, ssu)
}
type scoreSubscription struct {
@@ -83,6 +86,15 @@ FROM scores WHERE id = ?`, id)
fmt.Println(err)
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()
cp := make([]scoreSubscription, len(scoreSubscriptions))
copy(cp, scoreSubscriptions)