Kaleb (aka perlmonkey2) and I have been rounding out WebGUI‘s Survey wobject with a bunch of features over the past couple of weeks. Here’s a run-down of some of the highlights:
Improved Visual Feedback
The Survey Edit page now uses “Loading…” progress masks whenever it’s busy doing something. When you’re dealing with large data sets (and slow servers) it’s really handy to be able to see when the page is busy doing loading/saving/etc..

Multi-choice Bundles
Survey ships with a bunch of useful multiple-choice question bundles to get you going. Some of these are very generic such as Gender (Male/Female), Yes/No, etc.. Others are more specific to single domain, such as Confidence (an 11 answer scale from “0 – Not at all confident” to “10 – Extremely confident”). Of course, every site is going to want a different set of re-usable bundles. You can now create your own bundles, and add/edit/delete the default ones.

Validation Warnings
Now that Survey is a complex beast, allowing you to do all sorts of fancy things, it pays to have some automated checking of various things that could go wrong. The Edit Survey page constantly checks your Survey instance for warnings, and alerts you if anything smells bad.. everything from using Jump Expressions when enableSurveyExpressionEngine is disabled for your site, to duplicate Section/Question variable names, circular Jump targets, all the way up to full-blown Expression Engine compilation & pseudo-execution checking.
Survey Summaries
This is a long-awaited feature curtesy of Kaleb. You can now define which answers are correct, and assign arbitraty numeric scores to them. Then, when the user reaches the end of the Survey, they get shown their quiz results – both numerically (in a YUI DataTable) and graphically (with YUI Charts).
Coming soon to this department will be the ability to display quiz summaries at the end of individual sections rather than just all at the end.
Visualisation
Meanwhile, I’ve been building a tool to allow you to visualise the branching structure of a Survey using GraphViz. Here is an example of a real-world Survey instance that has ~500 questions. Turning this into a button that allows you to generate visualisations on the fly from the Edit Survey page on your own site is just a matter of sorting out the last remaining issues with GraphViz/ImageMagick support in the wre.
Branch Expressions
This has been the main focus of my work, and probably deserves a post all to itself. Survey now has a dedicated expression engine, which allows you to control branching using a large sub-set of the Perl language. Expressions are evaluated using Safe module, which limits what opcodes the expression can generate and limits access to only the variables that we chose to expose. Of course, even Safe.pm has caveats about what it can and can’t protect you from (for example infinite loops), so it’s important to note that the expression engine is disabled by default, and can only be enabled by site administrators in the WebGUI site config file.
When it comes down to it, branch expressions are just perl code, so you have a whole lot of power at your disposal. You can access recorded responses for the user by supplying the Section/Question variable name to the value() sub:
value(variable_name);
To actually trigger a branch, you call the jump() sub:
jump { value(q1) == 1 } section3
That says, if the user’s recorded response value to q1 has a numeric value of 1, jump to section 3.
Here’s a more advanced one:
jump { score(q1) > 5 and value(q2) =~ m/textmatch/ } section3;
jump { avg(value(q1), value(q2), value(home/anotherSurvey, q3)) > 10 } section4;
The above expression demonstrates some of the cooler branch expression features:
- Two alternative jump clauses
- Branching based of Question score (if you ask for score(Section) you get the total score for that section)
- Text matching (you have the power of Perl at your disposal after all)
- Calling a utility function, in this case avg(). The expression engine makes available a bunch of handy utility functions, such as all of the subs from List::Util (min, max, sum, etc..)
- Resolving the recorded response value from another survey instance altogether (the first argument to value() and score() can be an assetId or an asset url.)
Behind the scenes, the ExpressionEngine is quite nice too, telling you what it’s doing along the way, which makes debugging complex expressions quite painless.
Along with all these changes, the test suite continues to grow. Check it out in the next WebGUI beta and let us know what you think.




Trackbacks /
Pingbacks