diff --git a/app/locale/en.coffee b/app/locale/en.coffee index 26346f12d..69cd93343 100644 --- a/app/locale/en.coffee +++ b/app/locale/en.coffee @@ -530,6 +530,8 @@ module.exports = nativeDescription: "English", englishDescription: "English", tr simulation_explanation: "By simulating games you can get your game ranked faster!" simulate_games: "Simulate Games!" simulate_all: "RESET AND SIMULATE GAMES" + games_simulated_by: "Games simulated by you:" + games_simulated_for: "Games simulated for you:" leaderboard: "Leaderboard" battle_as: "Battle as " summary_your: "Your " diff --git a/app/templates/play/ladder.jade b/app/templates/play/ladder.jade index 3d445da64..6c0c68790 100644 --- a/app/templates/play/ladder.jade +++ b/app/templates/play/ladder.jade @@ -47,3 +47,13 @@ block content if false && me.isAdmin() p 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 \ No newline at end of file diff --git a/app/views/play/ladder/my_matches_tab.coffee b/app/views/play/ladder/my_matches_tab.coffee index 2772defa5..d8729051e 100644 --- a/app/views/play/ladder/my_matches_tab.coffee +++ b/app/views/play/ladder/my_matches_tab.coffee @@ -88,8 +88,8 @@ module.exports = class MyMatchesTabView extends CocoView # Let's try being independent of time. times = (i for s, i in scoreHistory) scores = (s[1] for s in scoreHistory) - lowest = _.min scores.concat([0]) - highest = _.max scores.concat(50) + lowest = _.min scores #.concat([0]) + highest = _.max scores #.concat(50) scores = (Math.round(100 * (s - lowest) / (highest - lowest)) for s in scores) team.chartData = times.join(',') + '|' + scores.join(',') team.minScore = Math.round(100 * lowest) diff --git a/app/views/play/ladder_view.coffee b/app/views/play/ladder_view.coffee index 45cdbbc49..653f1961d 100644 --- a/app/views/play/ladder_view.coffee +++ b/app/views/play/ladder_view.coffee @@ -72,7 +72,7 @@ module.exports = class LadderView extends RootView @showPlayModal(hash) if @sessions.loaded 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}) refreshViews: => @@ -83,7 +83,7 @@ module.exports = class LadderView extends RootView console.log "Refreshed sessions for ladder and matches." onIdleChanged: (e) -> - @refreshViews() unless e.idle + @fetchSessionsAndRefreshViews() unless e.idle # Simulations diff --git a/server/queues/scoring.coffee b/server/queues/scoring.coffee index 329b5a6a6..b9883347e 100644 --- a/server/queues/scoring.coffee +++ b/server/queues/scoring.coffee @@ -9,6 +9,7 @@ mongoose = require 'mongoose' queues = require '../commons/queue' LevelSession = require '../levels/sessions/LevelSession' Level = require '../levels/Level' +User = require '../users/User' TaskLog = require './task/ScoringTask' 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}" scoringTaskQueue = data log.info "Connected to scoring task queue!" - + module.exports.messagesInQueueCount = (req, res) -> scoringTaskQueue.totalMessagesInQueue (err, count) -> 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) -> 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 originalSessionTeam = clientResponseObject.originalSessionTeam originalSessionRank = parseInt clientResponseObject.originalSessionRank @@ -225,7 +229,7 @@ findNearestBetterSessionID = (levelOriginalID, levelMajorVersion, sessionID, ses submittedCode: $exists: true team: opposingTeam - + if opponentSessionTotalScore < 30 queryParameters["totalScore"]["$gt"] = opponentSessionTotalScore + 1 @@ -265,6 +269,11 @@ calculateOpposingTeam = (sessionTeam) -> opposingTeams = _.pull teams, sessionTeam 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) -> if isUserAnonymous req then return callback null, false diff --git a/server/routes/mail.coffee b/server/routes/mail.coffee index ae7d1efd7..9fb277698 100644 --- a/server/routes/mail.coffee +++ b/server/routes/mail.coffee @@ -156,8 +156,8 @@ getScoreHistoryGraphURL = (session, daysAgo) -> times = (s[0] for s in scoreHistory) times = ((100 * (t - times[0]) / (times[times.length - 1] - times[0])).toFixed(1) for t in times) scores = (s[1] for s in scoreHistory) - lowest = _.min scores.concat([0]) - highest = _.max scores.concat(50) + lowest = _.min scores #.concat([0]) + highest = _.max scores #.concat(50) scores = (Math.round(100 * (s - lowest) / (highest - lowest)) for s in scores) currentScore = Math.round scoreHistory[scoreHistory.length - 1][1] * 100 minScore = Math.round(100 * lowest) diff --git a/server/users/user_handler.coffee b/server/users/user_handler.coffee index 919588c0a..5d6e9be06 100644 --- a/server/users/user_handler.coffee +++ b/server/users/user_handler.coffee @@ -18,7 +18,7 @@ UserHandler = class UserHandler extends Handler 'name', 'photoURL', 'password', 'anonymous', 'wizardColor1', 'volume', 'firstName', 'lastName', 'gender', 'facebookID', 'emailSubscriptions', 'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage', - 'wizard', 'aceConfig' + 'wizard', 'aceConfig', 'simulatedBy', 'simulatedFor' ] jsonSchema: schema @@ -108,17 +108,17 @@ UserHandler = class UserHandler extends Handler if req.user?._id.equals(id) return @sendSuccess(res, @formatEntity(req, req.user)) super(req, res, id) - + getNamesByIds: (req, res) -> ids = req.query.ids or req.body.ids ids = ids.split(',') if _.isString ids ids = _.uniq ids - + # 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. returnWizard = req.query.wizard or req.body.wizard query = if returnWizard then {name:1, wizard:1} else {name:1} - + makeFunc = (id) -> (callback) -> 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 {}}) else callback(null, document?.get('name') or '') - + funcs = {} for id in ids return errors.badInput(res, "Given an invalid id: #{id}") unless Handler.isID(id) funcs[id] = makeFunc(id) - + async.parallel funcs, (err, results) -> return errors.serverError err if err res.send results diff --git a/server/users/user_schema.coffee b/server/users/user_schema.coffee index 650d680d6..d56463d3e 100644 --- a/server/users/user_schema.coffee +++ b/server/users/user_schema.coffee @@ -51,6 +51,9 @@ UserSchema = c.object {}, indentGuides: {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' module.exports = UserSchema