Include transpiled code in submission process

This commit is contained in:
Michael Schmatz 2014-05-14 11:42:15 -07:00
parent 9f9d651b3b
commit a1360d6cb8
2 changed files with 34 additions and 3 deletions

View file

@ -182,8 +182,15 @@ module.exports = class MyMatchesTabView extends CocoView
failure = (jqxhr, textStatus, errorThrown) =>
console.log jqxhr.responseText
@setRankingButtonText(button, 'failed')
transpiledCode = @transpileSession session
ajaxData =
session: sessionID
levelID: @level.id
originalLevelID: @level.attributes.original
levelMajorVersion: @level.attributes.version.major
transpiledCode: transpiledCode
ajaxData = {session: sessionID, levelID: @level.id, originalLevelID: @level.attributes.original, levelMajorVersion: @level.attributes.version.major}
$.ajax '/queue/scoring', {
type: 'POST'
data: ajaxData
@ -191,6 +198,28 @@ module.exports = class MyMatchesTabView extends CocoView
error: failure
}
transpileSession: (session) ->
submittedCode = session.get('code')
transpiledCode = {}
for thang, spells of submittedCode
transpiledCode[thang] = {}
for spellID, spell of spells
#DRY this
aetherOptions =
problems: {}
language: "javascript"
functionName: spellID
functionParameters: []
yieldConditionally: spellID is "plan"
globals: ['Vector', '_']
protectAPI: true
includeFlow: false
if spellID is "hear" then aetherOptions["functionParameters"] = ["speaker","message","data"]
aether = new Aether aetherOptions
transpiledCode[thang][spellID] = aether.transpile spell
transpiledCode
setRankingButtonText: (rankButton, spanClass) ->
rankButton.find('span').addClass('hidden')
rankButton.find(".#{spanClass}").removeClass('hidden')

View file

@ -104,13 +104,14 @@ module.exports.createNewTask = (req, res) ->
requestSessionID = req.body.session
originalLevelID = req.body.originalLevelID
currentLevelID = req.body.levelID
transpiledCode = req.body.transpiledCode
requestLevelMajorVersion = parseInt(req.body.levelMajorVersion)
async.waterfall [
validatePermissions.bind(@,req,requestSessionID)
fetchAndVerifyLevelType.bind(@,currentLevelID)
fetchSessionObjectToSubmit.bind(@, requestSessionID)
updateSessionToSubmit
updateSessionToSubmit.bind(@, transpiledCode)
fetchInitialSessionsToRankAgainst.bind(@, requestLevelMajorVersion, originalLevelID)
generateAndSendTaskPairsToTheQueue
], (err, successMessageObject) ->
@ -163,10 +164,11 @@ fetchSessionObjectToSubmit = (sessionID, callback) ->
query.exec (err, session) ->
callback err, session?.toObject()
updateSessionToSubmit = (sessionToUpdate, callback) ->
updateSessionToSubmit = (transpiledCode, sessionToUpdate, callback) ->
sessionUpdateObject =
submitted: true
submittedCode: sessionToUpdate.code
transpiledCode: transpiledCode
submitDate: new Date()
meanStrength: 25
standardDeviation: 25/3