mirror of
https://gitlab.com/Deukhoofd/BattleSim.git
synced 2025-10-27 18:00:03 +00:00
Overhauled leaderboard screen
This commit is contained in:
@@ -65,19 +65,31 @@ CLIENT_VERSION = assets.getVersion()
|
||||
page = req.param('page')
|
||||
perPage = req.param('per_page')
|
||||
ratings.listRatings page, perPage, (err, results) ->
|
||||
if err
|
||||
res.json(500, err.message)
|
||||
else
|
||||
res.render('leaderboard.jade', players: results)
|
||||
temparr = results.map((e) -> e.username)
|
||||
ratioarr = []
|
||||
ratings.getRatios temparr, (err, ratios)->
|
||||
for username in temparr
|
||||
index = temparr.indexOf(username)
|
||||
results[index].ratio = ratios[username]
|
||||
if err
|
||||
res.json(500, err.message)
|
||||
else
|
||||
res.render('leaderboard.jade', players: results)
|
||||
|
||||
app.get '/leaderboard/json', (req, res) ->
|
||||
page = req.param('page')
|
||||
perPage = req.param('per_page')
|
||||
ratings.listRatings page, perPage, (err, results) ->
|
||||
if err
|
||||
res.json(500, err.message)
|
||||
else
|
||||
res.json(players: results)
|
||||
temparr = results.map((e) -> e.username)
|
||||
ratioarr = []
|
||||
ratings.getRatios temparr, (err, ratios)->
|
||||
for username in temparr
|
||||
index = temparr.indexOf(username)
|
||||
results[index].ratio = ratios[username]
|
||||
if err
|
||||
res.json(500, err.message)
|
||||
else
|
||||
res.json(players: results)
|
||||
|
||||
app.get '/pokeuse/json', (req, res) ->
|
||||
user= req.user
|
||||
|
||||
@@ -14,7 +14,7 @@ RATINGS_SUBKEYS = {}
|
||||
for attribute in RATINGS_ATTRIBUTES
|
||||
RATINGS_SUBKEYS[attribute] = [RATINGS_KEY, attribute].join(':')
|
||||
RATINGS_MAXKEY = "ratings:max"
|
||||
RATINGS_PER_PAGE = 15
|
||||
RATINGS_PER_PAGE = 20
|
||||
|
||||
ALGORITHM_OPTIONS =
|
||||
systemConstant: 0.2 # Glicko2 tau
|
||||
@@ -203,6 +203,35 @@ updateMaxStreak = (id, next) =>
|
||||
return next(err) if err
|
||||
updateMaxRatings(idArray, next)
|
||||
|
||||
@getRatio = (id, next) ->
|
||||
id = id.toLowerCase()
|
||||
multi = redis.multi()
|
||||
for attribute, key of RATIOS_SUBKEYS
|
||||
multi = multi.hget(key, id)
|
||||
multi.exec (err, results) ->
|
||||
return next(err) if err
|
||||
hash = {}
|
||||
for attribute, i in RATIOS_ATTRIBUTES
|
||||
hash[attribute] = Number(results[i]) || 0
|
||||
return next(null, hash)
|
||||
|
||||
@getRatios = (users, next) ->
|
||||
multi = redis.multi()
|
||||
for id in users
|
||||
for attribute, key of RATIOS_SUBKEYS
|
||||
multi = multi.hget(key, id)
|
||||
multi.exec (err, results) ->
|
||||
return next(err) if err
|
||||
hasharray = {}
|
||||
iter = 0
|
||||
for id, i in users
|
||||
hash = {}
|
||||
for attribute, j in RATIOS_ATTRIBUTES
|
||||
hash[attribute] = Number(results[iter]) || 0
|
||||
iter++
|
||||
hasharray[id] = hash
|
||||
next(null, hasharray)
|
||||
|
||||
@listRatings = (page = 1, perPage = RATINGS_PER_PAGE, next) ->
|
||||
if arguments.length == 2 && typeof perPage == 'function'
|
||||
[perPage, next] = [RATINGS_PER_PAGE, perPage]
|
||||
@@ -218,18 +247,6 @@ updateMaxStreak = (id, next) =>
|
||||
array.push(username: username, score: score)
|
||||
next(null, array)
|
||||
|
||||
@getRatio = (id, next) ->
|
||||
id = id.toLowerCase()
|
||||
multi = redis.multi()
|
||||
for attribute, key of RATIOS_SUBKEYS
|
||||
multi = multi.hget(key, id)
|
||||
multi.exec (err, results) ->
|
||||
return next(err) if err
|
||||
hash = {}
|
||||
for attribute, i in RATIOS_ATTRIBUTES
|
||||
hash[attribute] = Number(results[i]) || 0
|
||||
return next(null, hash)
|
||||
|
||||
@getStreak = (id, next) ->
|
||||
id = id.toLowerCase()
|
||||
multi = redis.multi()
|
||||
|
||||
Reference in New Issue
Block a user