Merge pull request #1017 from codecombat/master

Add playtime, opponent name, totalScore to match
This commit is contained in:
Michael Schmatz 2014-05-16 14:53:17 -07:00
commit 1b9b145da7
2 changed files with 13 additions and 6 deletions

View file

@ -199,6 +199,8 @@ module.exports = class Simulator extends CocoClass
sessionID: session.sessionID sessionID: session.sessionID
submitDate: session.submitDate submitDate: session.submitDate
creator: session.creator creator: session.creator
name: session.creatorName
totalScore: session.totalScore
metrics: metrics:
rank: @calculateSessionRank session.sessionID, simulationResults.goalStates, @task.generateTeamToSessionMap() rank: @calculateSessionRank session.sessionID, simulationResults.goalStates, @task.generateTeamToSessionMap()
if session.sessionID is taskResults.originalSessionID if session.sessionID is taskResults.originalSessionID

View file

@ -277,6 +277,7 @@ constructTaskObject = (taskMessageBody, message, callback) ->
"levelID": session.levelID "levelID": session.levelID
"creator": session.creator "creator": session.creator
"creatorName":session.creatorName "creatorName":session.creatorName
"totalScore": session.totalScore
taskObject.sessions.push sessionInformation taskObject.sessions.push sessionInformation
callback null, taskObject, message callback null, taskObject, message
@ -297,7 +298,7 @@ processTaskObject = (taskObject,taskLogObject, message, cb) ->
getSessionInformation = (sessionIDString, callback) -> getSessionInformation = (sessionIDString, callback) ->
findParameters = findParameters =
_id: sessionIDString _id: sessionIDString
selectString = 'submitDate team submittedCode teamSpells levelID creator creatorName transpiledCode' selectString = 'submitDate team submittedCode teamSpells levelID creator creatorName transpiledCode totalScore'
query = LevelSession query = LevelSession
.findOne(findParameters) .findOne(findParameters)
.select(selectString) .select(selectString)
@ -445,6 +446,8 @@ addMatchToSessions = (newScoreObject, callback) ->
matchObject.opponents[sessionID] = {} matchObject.opponents[sessionID] = {}
matchObject.opponents[sessionID].sessionID = sessionID matchObject.opponents[sessionID].sessionID = sessionID
matchObject.opponents[sessionID].userID = session.creator matchObject.opponents[sessionID].userID = session.creator
matchObject.opponents[sessionID].name = session.name
matchObject.opponents[sessionID].totalScore = session.totalScore
matchObject.opponents[sessionID].metrics = {} matchObject.opponents[sessionID].metrics = {}
matchObject.opponents[sessionID].metrics.rank = Number(newScoreObject[sessionID].gameRanking) matchObject.opponents[sessionID].metrics.rank = Number(newScoreObject[sessionID].gameRanking)
@ -462,11 +465,13 @@ updateMatchesInSession = (matchObject, sessionID, callback) ->
opponentsClone = _.omit opponentsClone, sessionID opponentsClone = _.omit opponentsClone, sessionID
opponentsArray = _.toArray opponentsClone opponentsArray = _.toArray opponentsClone
currentMatchObject.opponents = opponentsArray currentMatchObject.opponents = opponentsArray
LevelSession.findOne {"_id": sessionID}, (err, session) ->
sessionUpdateObject = session = session.toObject()
$push: {matches: {$each: [currentMatchObject], $slice: -200}} currentMatchObject.playtime = session.playtime ? 0
#log.info "Updating session #{sessionID}" sessionUpdateObject =
LevelSession.update {"_id":sessionID}, sessionUpdateObject, callback $push: {matches: {$each: [currentMatchObject], $slice: -200}}
#log.info "Updating session #{sessionID}"
LevelSession.update {"_id":sessionID}, sessionUpdateObject, callback
updateUserSimulationCounts = (reqUserID,callback) -> updateUserSimulationCounts = (reqUserID,callback) ->
incrementUserSimulationCount reqUserID, 'simulatedBy', (err) => incrementUserSimulationCount reqUserID, 'simulatedBy', (err) =>