2014-05-12 20:16:31 -04:00
|
|
|
do (setupLodash = this) ->
|
|
|
|
GLOBAL._ = require 'lodash'
|
|
|
|
_.str = require 'underscore.string'
|
|
|
|
_.mixin _.str.exports()
|
2014-09-03 19:14:33 -04:00
|
|
|
GLOBAL.Aether = Aether = require 'aether'
|
2014-05-12 20:16:31 -04:00
|
|
|
async = require 'async'
|
|
|
|
|
|
|
|
serverSetup = require '../server_setup'
|
2014-06-19 11:47:31 -04:00
|
|
|
Level = require '../server/levels/Level'
|
|
|
|
LevelSession = require '../server/levels/sessions/LevelSession'
|
2014-08-30 16:43:56 -04:00
|
|
|
{createAetherOptions} = require '../app/lib/aether_utils'
|
2014-05-12 20:16:31 -04:00
|
|
|
|
2014-06-05 19:48:31 -04:00
|
|
|
i = 0
|
2014-05-12 20:16:31 -04:00
|
|
|
transpileLevelSession = (sessionID, cb) ->
|
2014-06-30 22:16:26 -04:00
|
|
|
query = LevelSession.findOne('_id': sessionID).select('team teamSpells submittedCode submittedCodeLanguage').lean()
|
2014-05-12 20:16:31 -04:00
|
|
|
query.exec (err, session) ->
|
|
|
|
if err then return cb err
|
|
|
|
submittedCode = session.submittedCode
|
2014-06-05 17:06:28 -04:00
|
|
|
unless session.submittedCodeLanguage
|
2014-06-30 22:16:26 -04:00
|
|
|
throw 'SUBMITTED CODE LANGUAGE DOESN\'T EXIST'
|
2014-06-05 17:06:28 -04:00
|
|
|
else
|
2014-06-05 19:48:31 -04:00
|
|
|
console.log "Transpiling code for session #{i++} #{session._id} in language #{session.submittedCodeLanguage}"
|
2014-05-12 20:16:31 -04:00
|
|
|
transpiledCode = {}
|
2014-06-05 17:06:28 -04:00
|
|
|
#console.log "Updating session #{sessionID}"
|
2014-05-12 20:16:31 -04:00
|
|
|
for thang, spells of submittedCode
|
|
|
|
transpiledCode[thang] = {}
|
|
|
|
for spellID, spell of spells
|
2014-06-30 22:16:26 -04:00
|
|
|
spellName = thang + '/' + spellID
|
2014-08-30 16:43:56 -04:00
|
|
|
continue if session.teamSpells and not (spellName in session.teamSpells[session.team])
|
2014-06-05 19:48:31 -04:00
|
|
|
#console.log "Transpiling spell #{spellName}"
|
2014-08-30 16:43:56 -04:00
|
|
|
aetherOptions = createAetherOptions functionName: spellID, codeLanguage: session.submittedCodeLanguage
|
2014-05-12 20:16:31 -04:00
|
|
|
aether = new Aether aetherOptions
|
|
|
|
transpiledCode[thang][spellID] = aether.transpile spell
|
2014-05-25 15:15:32 -04:00
|
|
|
conditions =
|
2014-06-30 22:16:26 -04:00
|
|
|
'_id': sessionID
|
2014-05-25 15:15:32 -04:00
|
|
|
update =
|
2014-06-30 22:16:26 -04:00
|
|
|
'transpiledCode': transpiledCode
|
|
|
|
query = LevelSession.update(conditions, update)
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-05-14 13:14:18 -04:00
|
|
|
query.exec (err, numUpdated) -> cb err
|
2014-05-12 20:16:31 -04:00
|
|
|
|
|
|
|
findLadderLevelSessions = (levelID, cb) ->
|
2014-05-25 15:15:32 -04:00
|
|
|
queryParameters =
|
2014-06-30 22:16:26 -04:00
|
|
|
'level.original': levelID + ''
|
2014-05-12 20:16:31 -04:00
|
|
|
submitted: true
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
selectString = '_id'
|
2014-05-14 13:14:18 -04:00
|
|
|
query = LevelSession.find(queryParameters).select(selectString).lean()
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
query.exec (err, levelSessions) ->
|
|
|
|
if err then return cb err
|
2014-06-30 22:16:26 -04:00
|
|
|
levelSessionIDs = _.pluck levelSessions, '_id'
|
2014-05-14 13:14:18 -04:00
|
|
|
async.eachSeries levelSessionIDs, transpileLevelSession, (err) ->
|
|
|
|
if err then return cb err
|
2014-06-05 19:48:31 -04:00
|
|
|
return cb null
|
2014-05-25 15:15:32 -04:00
|
|
|
|
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
transpileLadderSessions = ->
|
2014-05-25 15:15:32 -04:00
|
|
|
queryParameters =
|
2014-06-30 22:16:26 -04:00
|
|
|
type: 'ladder'
|
|
|
|
'version.isLatestMajor': true
|
|
|
|
'version.isLatestMinor': true
|
|
|
|
selectString = 'original'
|
2014-05-14 13:14:18 -04:00
|
|
|
query = Level.find(queryParameters).select(selectString).lean()
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
query.exec (err, ladderLevels) ->
|
|
|
|
throw err if err
|
2014-06-30 22:16:26 -04:00
|
|
|
ladderLevels = _.pluck ladderLevels, 'original'
|
2014-05-14 13:14:18 -04:00
|
|
|
async.eachSeries ladderLevels, findLadderLevelSessions, (err) ->
|
2014-05-12 20:16:31 -04:00
|
|
|
throw err if err
|
2014-05-14 13:14:18 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
serverSetup.connectToDatabase()
|
2014-06-19 18:41:35 -04:00
|
|
|
transpileLadderSessions()
|
2014-06-22 01:31:10 -04:00
|
|
|
# 2014-06-21: took about an hour to do 5480 sessions, ~93/min
|
|
|
|
# eta: db.level.sessions.find({submitted: true}).count() / 93
|