Added simulation counts.

This commit is contained in:
Nick Winter 2014-03-20 15:40:02 -07:00
parent 6e9daf59c9
commit ca1e3742c0
8 changed files with 38 additions and 14 deletions

View file

@ -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 "

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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')()
@ -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
@ -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

View file

@ -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)

View file

@ -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

View file

@ -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