mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-02 11:58:10 -05:00
Merge pull request #1040 from codecombat/master
Made both game selections random
This commit is contained in:
commit
e5e1631363
1 changed files with 42 additions and 36 deletions
|
@ -112,46 +112,52 @@ module.exports.getTwoGames = (req, res) ->
|
||||||
"team":"humans"
|
"team":"humans"
|
||||||
selection = "team totalScore transpiledCode teamSpells levelID creatorName creator"
|
selection = "team totalScore transpiledCode teamSpells levelID creatorName creator"
|
||||||
LevelSession.count queryParams, (err, numberOfHumans) =>
|
LevelSession.count queryParams, (err, numberOfHumans) =>
|
||||||
query = LevelSession
|
if err? then return errors.serverError(res, "Couldn't get the number of human games")
|
||||||
.find(queryParams)
|
ogreCountParams =
|
||||||
.limit(1)
|
"levelID": "greed"
|
||||||
.select(selection)
|
"submitted":true
|
||||||
.skip(Math.floor(Math.random()*numberOfHumans))
|
"team":"ogres"
|
||||||
.lean()
|
LevelSession.count ogreCountParams, (err, numberOfOgres) =>
|
||||||
query.exec (err, randomSession) =>
|
if err? then return errors.serverError(res, "Couldnt' get the number of ogre games")
|
||||||
if err? then return errors.serverError(res, "Couldn't select a top 15 random session!")
|
|
||||||
randomSession = randomSession[0]
|
|
||||||
queryParams =
|
|
||||||
"levelID":"greed"
|
|
||||||
"submitted":true
|
|
||||||
"totalScore":
|
|
||||||
$lte: randomSession.totalScore
|
|
||||||
"team": "ogres"
|
|
||||||
query = LevelSession
|
query = LevelSession
|
||||||
.find(queryParams)
|
.find(queryParams)
|
||||||
.select(selection)
|
|
||||||
.sort(totalScore: -1)
|
|
||||||
.limit(1)
|
.limit(1)
|
||||||
|
.select(selection)
|
||||||
|
.skip(Math.floor(Math.random()*numberOfHumans))
|
||||||
.lean()
|
.lean()
|
||||||
query.exec (err, otherSession) =>
|
query.exec (err, randomSession) =>
|
||||||
if err? then return errors.serverError(res, "Couldnt' select the other top 15 random session!")
|
if err? then return errors.serverError(res, "Couldn't select a random session!")
|
||||||
otherSession = otherSession[0]
|
randomSession = randomSession[0]
|
||||||
taskObject =
|
queryParams =
|
||||||
"messageGenerated": Date.now()
|
"levelID":"greed"
|
||||||
"sessions": []
|
"submitted":true
|
||||||
for session in [randomSession, otherSession]
|
"team": "ogres"
|
||||||
sessionInformation =
|
query = LevelSession
|
||||||
"sessionID": session._id
|
.find(queryParams)
|
||||||
"team": session.team ? "No team"
|
.limit(1)
|
||||||
"transpiledCode": session.transpiledCode
|
.select(selection)
|
||||||
"teamSpells": session.teamSpells ? {}
|
.skip(Math.floor(Math.random()*numberOfOgres))
|
||||||
"levelID": session.levelID
|
.lean()
|
||||||
"creatorName": session.creatorName
|
|
||||||
"creator": session.creator
|
|
||||||
"totalScore": session.totalScore
|
|
||||||
|
|
||||||
taskObject.sessions.push sessionInformation
|
query.exec (err, otherSession) =>
|
||||||
sendResponseObject req, res, taskObject
|
if err? then return errors.serverError(res, "Couldnt' select the other random session!")
|
||||||
|
otherSession = otherSession[0]
|
||||||
|
taskObject =
|
||||||
|
"messageGenerated": Date.now()
|
||||||
|
"sessions": []
|
||||||
|
for session in [randomSession, otherSession]
|
||||||
|
sessionInformation =
|
||||||
|
"sessionID": session._id
|
||||||
|
"team": session.team ? "No team"
|
||||||
|
"transpiledCode": session.transpiledCode
|
||||||
|
"teamSpells": session.teamSpells ? {}
|
||||||
|
"levelID": session.levelID
|
||||||
|
"creatorName": session.creatorName
|
||||||
|
"creator": session.creator
|
||||||
|
"totalScore": session.totalScore
|
||||||
|
|
||||||
|
taskObject.sessions.push sessionInformation
|
||||||
|
sendResponseObject req, res, taskObject
|
||||||
else
|
else
|
||||||
LevelSession.findOne(_id: humansGameID).lean().exec (err, humanSession) =>
|
LevelSession.findOne(_id: humansGameID).lean().exec (err, humanSession) =>
|
||||||
if err? then return errors.serverError(res, "Couldn't find the human game")
|
if err? then return errors.serverError(res, "Couldn't find the human game")
|
||||||
|
|
Loading…
Reference in a new issue