codecombat/app/views/artisans/LevelAnalyticsView.coffee

162 lines
4.8 KiB
CoffeeScript
Raw Normal View History

RootView = require 'views/core/RootView'
template = require 'templates/artisans/levelAnalyticsView'
Level = require 'models/Level'
Campaign = require 'models/Campaign'
2016-04-07 14:48:40 -07:00
Level = require 'models/Level'
CocoCollection = require 'collections/CocoCollection'
module.exports = class LevelAnalyticsView extends RootView
template: template
id: 'level-analytics-view'
2016-04-07 14:48:40 -07:00
excludedCampaigns = [
"picoctf"
"auditions"
2016-04-20 11:15:26 -07:00
"dungeon"
"forest"
"desert"
"mountain"
"glacier"
"dungeon-branching-test"
"forest-branching-test"
"desert-branching-test"
"course-6"
]
excludedSimulationLevels = [
"wakka-maul"
"cross-bones"
2016-04-07 14:48:40 -07:00
]
2016-04-20 11:15:26 -07:00
levelOffset: 0
isReady: 0
constructor: (options) ->
super options
@campaigns = new CocoCollection([],
url: '/db/campaign?project=name,slug,tasks'
model: Campaign
)
@campaigns.fetch()
@listenTo(@campaigns, 'sync', @onCampaignsLoaded)
@supermodel.loadCollection(@campaigns, 'campaigns')
2016-04-07 14:48:40 -07:00
2016-04-20 11:15:26 -07:00
@levels = new CocoCollection([],
url: '/db/level?project=slug,thangs&limit=100&skip=' + @levelOffset
model: Level
)
2016-04-07 14:48:40 -07:00
@levels.fetch()
@listenTo(@levels, 'sync', @onLevelsLoaded)
@supermodel.loadCollection(@levels, 'levels')
onCampaignsLoaded: ->
2016-04-07 14:48:40 -07:00
@levelSlugs = []
for campaign in @campaigns.models
continue unless excludedCampaigns.indexOf(campaign.get 'slug') is -1
2016-04-20 11:15:26 -07:00
console.log(campaign.get 'slug')
2016-04-07 14:48:40 -07:00
levels = campaign.get('levels')
for key, level of levels
2016-04-08 15:50:04 -07:00
if @levelSlugs.indexOf(level.slug) is -1
@levelSlugs.push level.slug
2016-04-20 11:15:26 -07:00
console.log "???"
@isReady += 1
if @isReady is 2
2016-04-07 14:48:40 -07:00
@readyUp()
2016-04-20 11:15:26 -07:00
2016-04-08 15:50:04 -07:00
console.log @levelSlugs.length
2016-04-07 14:48:40 -07:00
onLevelsLoaded: ->
2016-04-20 11:15:26 -07:00
@loadedLevels ?= []
@loadedLevels = @loadedLevels.concat(@levels.models)
if(@levels.length is 100)
console.log("Not done yet...")
@levelOffset += 100
@levels = new CocoCollection([],
url: '/db/level?project=slug,thangs&limit=100&skip=' + @levelOffset
model: Level
)
@levels.fetch()
@listenTo(@levels, 'sync', @onLevelsLoaded)
@supermodel.loadCollection(@levels, 'levels')
else
@isReady += 1
if @isReady is 2
@readyUp()
2016-04-08 15:50:04 -07:00
2016-04-07 14:48:40 -07:00
readyUp: ->
2016-04-20 11:15:26 -07:00
console.log("All done!")
console.log(@loadedLevels.length)
2016-04-08 15:50:04 -07:00
@parsedLevels = []
2016-04-20 11:15:26 -07:00
console.log @loadedLevels
2016-04-07 14:48:40 -07:00
for levelSlug in @levelSlugs
2016-04-20 11:15:26 -07:00
level = @loadedLevels.find((elem) ->
return elem.get('slug') is levelSlug
)
2016-04-07 14:48:40 -07:00
unless level?
continue
thangs = level.get('thangs')
2016-04-08 15:50:04 -07:00
component = null
thang = _.findWhere(thangs, (elem) ->
2016-04-20 11:15:26 -07:00
return elem.id is "Hero Placeholder" and _.findWhere(elem.components, (elem2) ->
2016-04-08 15:50:04 -07:00
if elem2.config?.programmableMethods?.plan?
component = elem2
return true
)
)
2016-04-20 11:15:26 -07:00
unless thang? and component
2016-04-08 15:50:04 -07:00
console.log("Cannot find programmableMethods component in: " + levelSlug)
continue
unless component?.config?.programmableMethods?.plan?
console.log("Cannot find plannable method inside component: " + levelSlug)
continue
2016-04-20 11:15:26 -07:00
plan = component.config.programmableMethods.plan
solutions = plan.solutions
2016-04-08 15:50:04 -07:00
problems = []
2016-04-20 11:15:26 -07:00
for lang in ["python", "javascript"]
2016-04-08 15:50:04 -07:00
unless _.findWhere(solutions, (elem) -> return elem.language is lang)
problems.push {
"type":"Missing Solution Language",
"value":lang
}
2016-04-20 11:15:26 -07:00
2016-04-08 15:50:04 -07:00
for solutionIndex of solutions
solution = solutions[solutionIndex]
2016-04-20 11:15:26 -07:00
if excludedSimulationLevels.indexOf(levelSlug) is -1
for req in ["seed", "succeeds", "heroConfig", 'lastHash', 'frameCount', 'goals']
unless solution[req]?
problems.push {
"type":"Solution is not simulatable",
"value":solution.language
}
break
if solution.source.indexOf("<%=") is -1
problems.push {
"type":"Solution is not i18n'd",
"value":solution.language
}
if solution.source.indexOf("pass") isnt -1
problems.push {
"type":"Solution contains pass",
"value":solution.language
}
if solution.language is 'javascript'
if solution.source is plan.source
2016-04-08 15:50:04 -07:00
problems.push {
2016-04-20 11:15:26 -07:00
"type":"Solution is identical to source",
"value":solution.language
}
else
console.log solution.source
console.log plan.languages[solution.language]
if solution.source is plan.languages[solution.language]
problems.push {
"type":"Solution is identical to source",
2016-04-08 15:50:04 -07:00
"value":solution.language
}
@parsedLevels.push {
level: level
problems: problems
}
2016-04-20 11:15:26 -07:00
@renderSelectors '#levelTable'