mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-31 07:12:49 -04:00
Merge branch 'master' of https://github.com/codecombat/codecombat
This commit is contained in:
commit
29b51c470c
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!"
|
||||
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 "
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue