Added simulation counts.
This commit is contained in:
parent
6e9daf59c9
commit
ca1e3742c0
8 changed files with 38 additions and 14 deletions
app
server
|
@ -530,6 +530,8 @@ module.exports = nativeDescription: "English", englishDescription: "English", tr
|
||||||
simulation_explanation: "By simulating games you can get your game ranked faster!"
|
simulation_explanation: "By simulating games you can get your game ranked faster!"
|
||||||
simulate_games: "Simulate Games!"
|
simulate_games: "Simulate Games!"
|
||||||
simulate_all: "RESET AND SIMULATE GAMES"
|
simulate_all: "RESET AND SIMULATE GAMES"
|
||||||
|
games_simulated_by: "Games simulated by you:"
|
||||||
|
games_simulated_for: "Games simulated for you:"
|
||||||
leaderboard: "Leaderboard"
|
leaderboard: "Leaderboard"
|
||||||
battle_as: "Battle as "
|
battle_as: "Battle as "
|
||||||
summary_your: "Your "
|
summary_your: "Your "
|
||||||
|
|
|
@ -47,3 +47,13 @@ block content
|
||||||
if false && me.isAdmin()
|
if false && me.isAdmin()
|
||||||
p
|
p
|
||||||
button(data-i18n="ladder.simulate_all").btn.btn-danger.btn-lg.highlight#simulate-all-button RESET AND SIMULATE GAMES
|
button(data-i18n="ladder.simulate_all").btn.btn-danger.btn-lg.highlight#simulate-all-button RESET AND SIMULATE GAMES
|
||||||
|
|
||||||
|
p.simulation-count
|
||||||
|
span(data-i18n="ladder.games_simulated_by") Games simulated by you:
|
||||||
|
|
|
||||||
|
span#simulated-by-you= me.get('simulatedBy') || 0
|
||||||
|
|
||||||
|
p.simulation-count
|
||||||
|
span(data-i18n="ladder.games_simulated_by") Games simulated for you:
|
||||||
|
|
|
||||||
|
span#simulated-for-you= me.get('simulatedFor') || 0
|
|
@ -88,8 +88,8 @@ module.exports = class MyMatchesTabView extends CocoView
|
||||||
# Let's try being independent of time.
|
# Let's try being independent of time.
|
||||||
times = (i for s, i in scoreHistory)
|
times = (i for s, i in scoreHistory)
|
||||||
scores = (s[1] for s in scoreHistory)
|
scores = (s[1] for s in scoreHistory)
|
||||||
lowest = _.min scores.concat([0])
|
lowest = _.min scores #.concat([0])
|
||||||
highest = _.max scores.concat(50)
|
highest = _.max scores #.concat(50)
|
||||||
scores = (Math.round(100 * (s - lowest) / (highest - lowest)) for s in scores)
|
scores = (Math.round(100 * (s - lowest) / (highest - lowest)) for s in scores)
|
||||||
team.chartData = times.join(',') + '|' + scores.join(',')
|
team.chartData = times.join(',') + '|' + scores.join(',')
|
||||||
team.minScore = Math.round(100 * lowest)
|
team.minScore = Math.round(100 * lowest)
|
||||||
|
|
|
@ -72,7 +72,7 @@ module.exports = class LadderView extends RootView
|
||||||
@showPlayModal(hash) if @sessions.loaded
|
@showPlayModal(hash) if @sessions.loaded
|
||||||
|
|
||||||
fetchSessionsAndRefreshViews: ->
|
fetchSessionsAndRefreshViews: ->
|
||||||
return if @destroyed or application.userIsIdle or @$el.find('#simulate.active').length or (new Date() - 2000 < @lastRefreshTime)
|
return if @destroyed or application.userIsIdle or @$el.find('#simulate.active').length or (new Date() - 2000 < @lastRefreshTime) or @startsLoading
|
||||||
@sessions.fetch({"success": @refreshViews})
|
@sessions.fetch({"success": @refreshViews})
|
||||||
|
|
||||||
refreshViews: =>
|
refreshViews: =>
|
||||||
|
@ -83,7 +83,7 @@ module.exports = class LadderView extends RootView
|
||||||
console.log "Refreshed sessions for ladder and matches."
|
console.log "Refreshed sessions for ladder and matches."
|
||||||
|
|
||||||
onIdleChanged: (e) ->
|
onIdleChanged: (e) ->
|
||||||
@refreshViews() unless e.idle
|
@fetchSessionsAndRefreshViews() unless e.idle
|
||||||
|
|
||||||
# Simulations
|
# Simulations
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ mongoose = require 'mongoose'
|
||||||
queues = require '../commons/queue'
|
queues = require '../commons/queue'
|
||||||
LevelSession = require '../levels/sessions/LevelSession'
|
LevelSession = require '../levels/sessions/LevelSession'
|
||||||
Level = require '../levels/Level'
|
Level = require '../levels/Level'
|
||||||
|
User = require '../users/User'
|
||||||
TaskLog = require './task/ScoringTask'
|
TaskLog = require './task/ScoringTask'
|
||||||
bayes = new (require 'bayesian-battle')()
|
bayes = new (require 'bayesian-battle')()
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ connectToScoringQueue = ->
|
||||||
if error? then throw new Error "There was an error registering the scoring queue: #{error}"
|
if error? then throw new Error "There was an error registering the scoring queue: #{error}"
|
||||||
scoringTaskQueue = data
|
scoringTaskQueue = data
|
||||||
log.info "Connected to scoring task queue!"
|
log.info "Connected to scoring task queue!"
|
||||||
|
|
||||||
module.exports.messagesInQueueCount = (req, res) ->
|
module.exports.messagesInQueueCount = (req, res) ->
|
||||||
scoringTaskQueue.totalMessagesInQueue (err, count) ->
|
scoringTaskQueue.totalMessagesInQueue (err, count) ->
|
||||||
if err? then return errors.serverError res, "There was an issue finding the Mongoose count:#{err}"
|
if err? then return errors.serverError res, "There was an issue finding the Mongoose count:#{err}"
|
||||||
|
@ -148,6 +149,9 @@ module.exports.processTaskResult = (req, res) ->
|
||||||
addMatchToSessions clientResponseObject, newScoresObject, (err, data) ->
|
addMatchToSessions clientResponseObject, newScoresObject, (err, data) ->
|
||||||
if err? then return errors.serverError res, "There was an error updating the sessions with the match! #{JSON.stringify err}"
|
if err? then return errors.serverError res, "There was an error updating the sessions with the match! #{JSON.stringify err}"
|
||||||
|
|
||||||
|
incrementUserSimulationCount req.user._id, 'simulatedBy'
|
||||||
|
incrementUserSimulationCount levelSession.creator, 'simulatedFor'
|
||||||
|
|
||||||
originalSessionID = clientResponseObject.originalSessionID
|
originalSessionID = clientResponseObject.originalSessionID
|
||||||
originalSessionTeam = clientResponseObject.originalSessionTeam
|
originalSessionTeam = clientResponseObject.originalSessionTeam
|
||||||
originalSessionRank = parseInt clientResponseObject.originalSessionRank
|
originalSessionRank = parseInt clientResponseObject.originalSessionRank
|
||||||
|
@ -225,7 +229,7 @@ findNearestBetterSessionID = (levelOriginalID, levelMajorVersion, sessionID, ses
|
||||||
submittedCode:
|
submittedCode:
|
||||||
$exists: true
|
$exists: true
|
||||||
team: opposingTeam
|
team: opposingTeam
|
||||||
|
|
||||||
if opponentSessionTotalScore < 30
|
if opponentSessionTotalScore < 30
|
||||||
queryParameters["totalScore"]["$gt"] = opponentSessionTotalScore + 1
|
queryParameters["totalScore"]["$gt"] = opponentSessionTotalScore + 1
|
||||||
|
|
||||||
|
@ -265,6 +269,11 @@ calculateOpposingTeam = (sessionTeam) ->
|
||||||
opposingTeams = _.pull teams, sessionTeam
|
opposingTeams = _.pull teams, sessionTeam
|
||||||
return opposingTeams[0]
|
return opposingTeams[0]
|
||||||
|
|
||||||
|
incrementUserSimulationCount = (userID, type) ->
|
||||||
|
inc = {}
|
||||||
|
inc[type] = 1
|
||||||
|
User.update {_id: userID}, {$inc: inc}, (err, affected) ->
|
||||||
|
log.error "Error incrementing #{type} for #{userID}: #{err}" if err
|
||||||
|
|
||||||
validatePermissions = (req, sessionID, callback) ->
|
validatePermissions = (req, sessionID, callback) ->
|
||||||
if isUserAnonymous req then return callback null, false
|
if isUserAnonymous req then return callback null, false
|
||||||
|
|
|
@ -156,8 +156,8 @@ getScoreHistoryGraphURL = (session, daysAgo) ->
|
||||||
times = (s[0] for s in scoreHistory)
|
times = (s[0] for s in scoreHistory)
|
||||||
times = ((100 * (t - times[0]) / (times[times.length - 1] - times[0])).toFixed(1) for t in times)
|
times = ((100 * (t - times[0]) / (times[times.length - 1] - times[0])).toFixed(1) for t in times)
|
||||||
scores = (s[1] for s in scoreHistory)
|
scores = (s[1] for s in scoreHistory)
|
||||||
lowest = _.min scores.concat([0])
|
lowest = _.min scores #.concat([0])
|
||||||
highest = _.max scores.concat(50)
|
highest = _.max scores #.concat(50)
|
||||||
scores = (Math.round(100 * (s - lowest) / (highest - lowest)) for s in scores)
|
scores = (Math.round(100 * (s - lowest) / (highest - lowest)) for s in scores)
|
||||||
currentScore = Math.round scoreHistory[scoreHistory.length - 1][1] * 100
|
currentScore = Math.round scoreHistory[scoreHistory.length - 1][1] * 100
|
||||||
minScore = Math.round(100 * lowest)
|
minScore = Math.round(100 * lowest)
|
||||||
|
|
|
@ -18,7 +18,7 @@ UserHandler = class UserHandler extends Handler
|
||||||
'name', 'photoURL', 'password', 'anonymous', 'wizardColor1', 'volume',
|
'name', 'photoURL', 'password', 'anonymous', 'wizardColor1', 'volume',
|
||||||
'firstName', 'lastName', 'gender', 'facebookID', 'emailSubscriptions',
|
'firstName', 'lastName', 'gender', 'facebookID', 'emailSubscriptions',
|
||||||
'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage',
|
'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage',
|
||||||
'wizard', 'aceConfig'
|
'wizard', 'aceConfig', 'simulatedBy', 'simulatedFor'
|
||||||
]
|
]
|
||||||
|
|
||||||
jsonSchema: schema
|
jsonSchema: schema
|
||||||
|
@ -108,17 +108,17 @@ UserHandler = class UserHandler extends Handler
|
||||||
if req.user?._id.equals(id)
|
if req.user?._id.equals(id)
|
||||||
return @sendSuccess(res, @formatEntity(req, req.user))
|
return @sendSuccess(res, @formatEntity(req, req.user))
|
||||||
super(req, res, id)
|
super(req, res, id)
|
||||||
|
|
||||||
getNamesByIds: (req, res) ->
|
getNamesByIds: (req, res) ->
|
||||||
ids = req.query.ids or req.body.ids
|
ids = req.query.ids or req.body.ids
|
||||||
ids = ids.split(',') if _.isString ids
|
ids = ids.split(',') if _.isString ids
|
||||||
ids = _.uniq ids
|
ids = _.uniq ids
|
||||||
|
|
||||||
# TODO: Extend and repurpose this handler to return other public info about a user more flexibly,
|
# TODO: Extend and repurpose this handler to return other public info about a user more flexibly,
|
||||||
# say by a query parameter that lists public properties to return.
|
# say by a query parameter that lists public properties to return.
|
||||||
returnWizard = req.query.wizard or req.body.wizard
|
returnWizard = req.query.wizard or req.body.wizard
|
||||||
query = if returnWizard then {name:1, wizard:1} else {name:1}
|
query = if returnWizard then {name:1, wizard:1} else {name:1}
|
||||||
|
|
||||||
makeFunc = (id) ->
|
makeFunc = (id) ->
|
||||||
(callback) ->
|
(callback) ->
|
||||||
User.findById(id, query).exec (err, document) ->
|
User.findById(id, query).exec (err, document) ->
|
||||||
|
@ -127,12 +127,12 @@ UserHandler = class UserHandler extends Handler
|
||||||
callback(null, {name:document.get('name'), wizard:document.get('wizard') or {}})
|
callback(null, {name:document.get('name'), wizard:document.get('wizard') or {}})
|
||||||
else
|
else
|
||||||
callback(null, document?.get('name') or '')
|
callback(null, document?.get('name') or '')
|
||||||
|
|
||||||
funcs = {}
|
funcs = {}
|
||||||
for id in ids
|
for id in ids
|
||||||
return errors.badInput(res, "Given an invalid id: #{id}") unless Handler.isID(id)
|
return errors.badInput(res, "Given an invalid id: #{id}") unless Handler.isID(id)
|
||||||
funcs[id] = makeFunc(id)
|
funcs[id] = makeFunc(id)
|
||||||
|
|
||||||
async.parallel funcs, (err, results) ->
|
async.parallel funcs, (err, results) ->
|
||||||
return errors.serverError err if err
|
return errors.serverError err if err
|
||||||
res.send results
|
res.send results
|
||||||
|
|
|
@ -51,6 +51,9 @@ UserSchema = c.object {},
|
||||||
indentGuides: {type: 'boolean', 'default': false}
|
indentGuides: {type: 'boolean', 'default': false}
|
||||||
behaviors: {type: 'boolean', 'default': false}
|
behaviors: {type: 'boolean', 'default': false}
|
||||||
|
|
||||||
|
simulatedBy: {type: 'integer', minimum: 0, default: 0}
|
||||||
|
simulatedFor: {type: 'integer', minimum: 0, default: 0}
|
||||||
|
|
||||||
c.extendBasicProperties UserSchema, 'user'
|
c.extendBasicProperties UserSchema, 'user'
|
||||||
|
|
||||||
module.exports = UserSchema
|
module.exports = UserSchema
|
||||||
|
|
Reference in a new issue