- Allow ?dev=true in verifier

- Show progress bar and totals in verifier
- Fill in templates in solution source code.
This commit is contained in:
Rob 2016-05-03 11:46:10 -07:00
parent 074610095d
commit 3f41eaec01
3 changed files with 44 additions and 19 deletions
app
templates/editor/verifier
views/editor/verifier

View file

@ -2,9 +2,21 @@ extends /templates/base-flat
block content
.container
div.row(style="margin-top: 20px")
div.col-sm-3
p.alert.alert-success(style="padding: 5px")
| Passed: #{view.passed}
div.col-sm-3
p.alert.alert-danger(style="padding: 5px")
| Failed: #{view.failed}
if view.levelIDs
.progress
.progress-bar.progress-bar-success(role="progressbar" style="width: #{100*view.passed/view.testCount}%")
.progress-bar.progress-bar-danger(role="progressbar" style="width: #{100*view.failed/view.testCount}%")
each test, id in view.tests
if test.level
if !test.goals
h2(style='color: orange')= test.level.get('name')
small= ' in ' + test.language + ''
@ -40,11 +52,6 @@ block content
else
h1 Loading Level...
div#tome-view
div#goals-veiw
br
// TODO: show errors
// TODO: frame length

View file

@ -4,6 +4,7 @@ SuperModel = require 'models/SuperModel'
God = require 'lib/God'
GoalManager = require 'lib/world/GoalManager'
LevelLoader = require 'lib/LevelLoader'
utils = require 'core/utils'
module.exports = class VerifierTest extends CocoClass
constructor: (@levelID, @updateCallback, @supermodel, @language) ->
@ -12,6 +13,11 @@ module.exports = class VerifierTest extends CocoClass
# TODO: listen to Backbone.Mediator.publish 'god:non-user-code-problem', problem: event.data.problem, god: @shared.god from Angel to detect when we can't load the thing
# TODO: listen to the progress report from Angel to show a simulation progress bar (maybe even out of the number of frames we actually know it'll take)
@supermodel ?= new SuperModel()
if utils.getQueryVariable('dev')
@supermodel.shouldSaveBackups = (model) -> # Make sure to load possibly changed things from localStorage.
model.constructor.className in ['Level', 'LevelComponent', 'LevelSystem', 'ThangType']
@language ?= 'python'
@load()
@ -39,8 +45,12 @@ module.exports = class VerifierTest extends CocoClass
# TODO: reach into and find hero and get the config from the solution
try
hero = _.find level.get("thangs"), id: "Hero Placeholder"
programmable = _.find(hero.components, (x) -> x.config?.programmableMethods?.plan).config.programmableMethods.plan
session.solution = _.find (programmable.solutions ? []), language: session.get('codeLanguage')
config = _.find(hero.components, (x) -> x.config?.programmableMethods?.plan).config
programmable = config.programmableMethods.plan
solution = _.find (programmable.solutions ? []), language: session.get('codeLanguage')
solution.source = _.template(solution.source)(config?.programmableMethods?.plan.context)
session.solution = solution
session.set 'heroConfig', session.solution.heroConfig
session.set 'code', {'hero-placeholder': plan: session.solution.source}
state = session.get 'state'
@ -86,6 +96,7 @@ module.exports = class VerifierTest extends CocoClass
@updateCallback? state: @state
isSucessful: () ->
return false unless @solution?
return false unless @frames == @solution.frameCount
if @goals and @solution.goals
for k of @goals

View file

@ -6,30 +6,37 @@ module.exports = class VerifierView extends RootView
className: 'style-flat'
template: template
id: 'verifier-view'
events:
'input input': 'searchUpdate'
'change input': 'searchUpdate'
constructor: (options, @levelID) ->
super options
# TODO: rework to handle N at a time instead of all at once
# TODO: sort tests by unexpected result first
@passed = 0
@failed = 0
testLevels = ["dungeons-of-kithgard", "gems-in-the-deep", "shadow-guard", "kounter-kithwise", "crawlways-of-kithgard", "enemy-mine", "illusory-interruption", "forgetful-gemsmith", "signs-and-portents", "favorable-odds", "true-names", "the-prisoner", "banefire", "the-raised-sword", "kithgard-librarian", "fire-dancing", "loop-da-loop", "haunted-kithmaze", "riddling-kithmaze", "descending-further", "the-second-kithmaze", "dread-door", "cupboards-of-kithgard", "hack-and-dash", "known-enemy", "master-of-names", "lowly-kithmen", "closing-the-distance", "tactical-strike", "the-skeleton", "a-mayhem-of-munchkins", "the-final-kithmaze", "the-gauntlet", "radiant-aura", "kithgard-gates", "destroying-angel", "deadly-dungeon-rescue", "kithgard-brawl", "cavern-survival", "breakout", "attack-wisely", "kithgard-mastery", "kithgard-apprentice", "robot-ragnarok", "defense-of-plainswood", "peasant-protection", "forest-fire-dancing"]
#testLevels = testLevels.slice 0, 15
levelIDs = if @levelID then [@levelID] else testLevels
@levelIDs = if @levelID then [@levelID] else testLevels
@testCount = @levelIDs.length * 2 #One per langauge
#supermodel = if @levelID then @supermodel else undefined
@tests = []
async.eachSeries levelIDs, (levelID, lnext) =>
async.eachSeries @levelIDs, (levelID, lnext) =>
async.eachSeries ['python','javascript'], (lang, next) =>
@tests.unshift new VerifierTest levelID, (e) =>
@update(e)
next() if e.state in ['complete', 'error']
, @supermodel, lang
, -> lnext()
test = new VerifierTest levelID, (e) =>
@update(e)
if e.state in ['complete', 'error']
if test.isSucessful()
++@passed
else
++@failed
next()
, @supermodel, lang
@tests.unshift test
, -> lnext()
, () => @render()
update: (event) =>
# TODO: show unworkable tests instead of hiding them
# TODO: destroy them Tests after or something
console.log 'got event', event, 'on some test'
@tests = _.filter @tests, (test) -> test.state isnt 'error'
@render()
@render()