Archive for the ‘WebGUI’ category

Ode to wgd and the command line

July 14th, 2009

Doug just posted an ode to the Linux command line over at the Plain Black staff blog.

I’ve been getting a lot of joy out of the command line today too thanks to Graham’s ridiculously useful WGDev. One wgd command that I only started using in earnest today is the ls command. In its most basic form, it lets you print out a list of assets on your site:


$ wgd ls /home

getting_started
your_next_step
the_latest_news
tell_a_friend
documentation
site_map

I added a bunch of extensions to ls today, the first one being a -r option that tells ls to recursively list assets. Given that this prints to STDOUT, you can pipe this into any other command line tool to manipulate the output. For example, to list all assets that have the word “you” in their menu title:


$ wgd ls /root -f "%menuTitle%" -r | grep -i you
Profile Account Layout
Inbox Account Layout
Friends Layout Template
Account Layout
Shop Account Layout
Contributions Layout
Default Account Layout
Layout
Your Next Step

(the -f “%menuTitle%” option above tells the command to output only the menuTitle property of each asset).

Under the hood ls is calling asset->getLineage(), so I exposed a few of the getLineage API options to ls.

For example, this is one way of getting a sorted list of Survey templates on your site:


$ wgd ls root -r --includeOnlyClass WebGUI::Asset::Template -f "%url% %namespace%" | perl -ane 'print "$F[0] ($F[1])\n" if $F[1] =~ m/survey/i' | sort
root/import/expireincompletesurveyresponses/expireincompletesurveyresponses (ExpireIncompleteSurveyResponses)
root/import/survey/default-answer-edit (Survey/Edit)
root/import/survey/default-feedback (Survey/Feedback)
root/import/survey/default-gradebook-report (Survey/Gradebook)
root/import/survey/default-overview-report (Survey/Overview)
root/import/survey/default-question-edit (Survey/Edit)
root/import/survey/default-questions (Survey/Take)
root/import/survey/default-section-edit (Survey/Edit)
root/import/survey/default-survey-edit (Survey/Edit)
root/import/survey/default-survey-summary (Survey/Summary)
root/import/survey/default-survey (Survey)
root/import/survey/default-survey-take (Survey/Take)
root/import/survey/default-test-results (Survey/TestResults)

While I was writing this post, Andy asked me to provide him with a list of all Carousel wobjects on a site we’re working on. That’s as easy as:


$ wgd ls -r root --includeOnlyClass WebGUI::Asset::Wobject::Carousel

The most useful option I added to ls is the –filter smartmatch filter option. This option filters the results using an asset property of your choosing. Format looks like “%url% ~~ smartmatch”, where “url” is the field to filter against, and “smartmatch” is either a Perl regular expression such as “/(?i:partial_match)/” or a string such as “my_exact_match”.

For example, the following command lists all templates that include absolute urls. We generate the output to an html file so that someone can easily open all the links and manually review/remove the absolute urls:


$ wgd ls -r /root --filter "%template% ~~ /http:///" --includeOnlyClass WebGUI::Asset::Template --format "<a href=http://dev.localhost.localdomain/%url%?func=edit>%url%</a><br>" > links.html

links.html then contains:

<a href=http://dev.localhost.localdomain/style_01?func=edit>style_01</a><br>
<a href=http://dev.localhost.localdomain/style_02?func=edit>style_02</a><br>
<a href=http://dev.localhost.localdomain/style_03?func=edit>style_03</a><br>

...

One type of command that I can see myself using a lot in the future is the following, which displays all assets that are viewable to a specific group (in this case the “Turn Admin On” group, which has an id of “12″):


$ wgd ls -r root --format "%groupIdView% %url%" --filter "%groupIdView% ~~ 12"
12 root/import/newsletter
12 root/import/projectmanager/resource
12 root/import/wiki

Alternatively, you can use a variation of the above to list all assets that are NOT viewable to a certain group (or groups). This is great for finding assets that have accidentally been set to say, Admins, when you want them viewable by Registered Users. For example, the following command lists assets that are not viewable to the default “Visitors”, “Everyone”, or “Registered Users” groups:


$ wgd ls -r root --format "%groupIdView% %url%" | perl -ane 'print "$F[0] $F[1]\n" if !grep {$F[0] eq $_} qw(1 2 7)'
12 root/import/newsletter
12 root/import/projectmanager/resource
12 root/import/wiki

All of these commands take in the order of 1 second to run, which is a lot less time consuming than manually reviewing your site asset-by-asset. And if you incorporate them into your test suite, you can re-verify their output against your site policy/expectations whenever you like.

Padre::Plugin::WebGUI

July 3rd, 2009

For a little while now I’ve been working on a WebGUI plugin for Padre (the Perl Application Development and Refactoring Environment). Progress has been pretty slow, partly due to lack of time but also because often the things I want to do are at the edge of what Padre currently supports (or just that there’s no existing examples of how to do something easily).

I’ve released the code onto CPAN, and the current dev version is available via github, but since it’s all a bit hacky and alpha at the moment I thought it worthwhile doing a little tour of what currently works (on my dev box at least).

Installation

Installation is the same as any other Padre plugin, either install via cpan


cpan install Padre::Plugin::WebGUI

or from git:


git clone git://github.com/pdonelan/Padre-Plugin-WebGUI.git

perl Makefile.PL

make && make test && make install

Since this is a WebGUI plugin, you need to first install WebGUI, and also WGDev.

Once you’ve done that, you will see the WebGUI plugin listed in the Padre Plugin Manager:

Padre Plugin Manager

Click the enable button, and you’ll see a WebGUI item appear in the Plugin menu.

Controlling WRE Services

The first thing you can do with the plugin is control your WRE services (mysql, modperl, modproxy and spectre).

Click on: WebGUI > WRE Services > Modperl > Restart and you’ll see a restart status message appear in the Padre output panel.

restart-modperl

Currently this is just a simple wrapper around the wreservice.pl script that ships with WebGUI. A nice enhancement would be to turn the menu item into a services dashboard with lights telling you which services are currently running, and buttons to start/stop/restart.

Online Resources

Another item in the menu called Online Resources gives you access to a bunch of handy WebGUI links that open in your browser – including one that takes you straight to a web-based IRC client connected to #webgui.

WebGUI Log

If you click the “Logview” checkbox on the WebGUI menu, a WebGUI Log panel will open. This panel will start monitoring all of your WRE log files (webgui.log, modperl.log, modproxy.log, etc..) and display changes in real-time. WebGUI uses Log4perl as its logging engine, but it uses the sitename as the Log4perl category, which means that you can’t easily e.g. turn on DEBUG output and filter out everything except the module you’re working on (unless you use my Log4perl::Filter::CallerMatch module). Once we add in the ability to easily customise what files are being logged and apply filters to what gets displayed, this will make the above scenario a breeze.

The logview panel uses a long-running Padre task and File::Tail::select to continuous monitor a bunch of files in realtime. The main thread writes commands to a temp file to send commands to the monitoring thread (the most important command being “exit” which tells the thread to break out of its monitoring loop!). Later I plan on adding support for other commands such as “add/remove this file from the list of files you’re watching”, “add/remove filter”, etc.. Since this seems like a generic sort of feature I’m hoping to bundle  Padre::Plugin::WebGUI::Logview and Padre::Plugin::WebGUI::Task::Logview as a stand-alone module for other Padre plugin developers to use (and improve).

logview

Asset Tree

And finally, the coolect feature the WebGUI plugin has is the Asset Tree.

If you turn on the Asset Tree from the plugin menu, a new panel appears with a “Connect” button on it. Currently this is hardwired to the default WebGUI dev site at dev.localhost.localdomain but later I plan on adding a Site Manager to allow you to define sites here.

Double-clicking on the Connect button connects to the site, and pulls down the asset tree:

asset-tree

This is the same Asset Tree you see when you log in to your WebGUI site and turn admin mode on. As you can see from the screenshot, right-clicking on a node brings up a context menu, from which you can do asset-specific actions. The plugin already gives you access to all of the WGDev commands from the main plugin menu (with a dialog box asking you what arguments you want to pass to the command), but it becomes a lot more useful once you hook these WGDev commands to the Asset Tree context menu. Then instead of having to remember what url or assetId your asset has, you can just click through the tree to find the node you want, right-click and off you go.

For example, WGDev has a package command that lets you package up node and all of its children into a tarball that can be imported into other sites, used in upgrade scripts, etc.. By integrating this command into the context menu, you can have Padre prompt you you for the folder that you want to save the WebGUI package in (via your native Save File dialog box).

Similarly, WGDev has an edit command that lets you edit an asset (for example a template file) via your favourite editor and then have the changes pushed back into the database after you save and close the file. By integrating this command into Padre, you could leave the file open, and push the changes up every time you hit save(allowing for more convenient continuous editing).

Survey vs SurveyMonkey

May 4th, 2009

For my first post in the Enlightened Perl “Iron Man” get-more-people-to blog-outside-of-the-Perl-echo-chamber initiative, I thought it’d be fun to do a follow-up to my recent WebGUI Survey Goodies post, comparing our humble Perl powered Survey tool to the industry giant: SurveyMonkey.

SurveyMonkey

According to their official website, SurveyMonkey is “the leading survey tool on the web (ranked by Alexa), with over 80% of the Fortune 100 currently using SurveyMonkey”. Impressive stuff! They must have an awesome tool. Let’s see how Survey stacks up. I’m comparing Survey to the free version of SurveyMonkey, so if someone has a paid account and wants to let us know what extra features we’re missing out on that’d be great.

Let’s start with the SurveyMonkey features page.

Design

Select From Over 20 Types of Questions – We support everything from multiple choice to rating scales to open-ended text. You can customize the layout of every question type for the ultimate in design flexibility.

20 question types sounds impressive. I don’t think we have that many. Looking closer though, their list actually only numbers 15 in total, and some of them are redundant items like  “Multiple Choice (only one answer)”, “Multiple Choice (Multiple Answers)”. Ok, first win to SurveyMonkey! – we don’t have a drop-down list question type. But that’s only because no-one has asked for one yet – Kaleb could probably commit one faster than it took me to write this blog post. Digging deeper, most of the other question types could be recreated by playing with Survey’s per-question/answer settings such as horizontal/vertical display, etc.. Preconfigured bundles of questions are an interesting concept..  Survey has the concept of a multi-choice question bundle, which is a question plus all of its answers – these can be copied, and also saved so that you can deploy them at will anywhere in your survey, but it might be interesting to apply that concept to the Section level (SurveyMonkey doesn’t let you create your own bundles by the way).

Missing from SurveyMonkey’s arsenal are “Date Range”, draggable sliders (and dual-sliders), and a calendar-style date picker. So let’s call it even for now.

Use Our Survey Templates, Create custom themes

Yup, we’re fully templated, using the same template system (HTML::Template) that powers the rest of WebGUI. There appears to be some skinning you can do in SurveyMonkey, but the “Survey Template Library” is only listed for the pro version on their Pricing Page. I think we’re edging ahead at this point.

Add a Logo to Your Survey

Um..?? Well let’s see.. You can run Survey on your own domain, within a WebGUI site, however you please. And yes, that includes putting your logo wherever you like. (Looks like the logo feature is disabled in the free version of SurveyMonkey. bummer.).

Validate Your Survey Responses

SurveyMonkey has some nice per-question validation options that go beyond what Survey is currently capable of. They definitely beat us on this front. However that will change when we make the planned switch to inputEx for rendering html form elements – inputEx has a huge array of sexy looking form elements that can be easily wired up with validation logic.

Randomize or Sort Your Question Choices

Can do.

Save Your Survey as a PDF

Nice! That’d be a great feature to have. No doubt a solution is only one CPAN module away, but right now SurveyMonkey has it and we don’t.

Collection Features

I won’t list all the features here but they mostly pertain to controlling who can access your questionnaires. Survey runs inside of WebGUI, so you have the full power of WebGUI Authentication/Authorization at your disposal. You have fine-grained control over who can edit surveys, take surveys and view reports. Want to use LDAP users? Easy. WebGUI Auth is fully pluggable too, so there’s nothing stopping you from integrating your site with whatever other infrastructure you already have. Survey also lets you set time windows on how long users have to complete a survey, which can be useful if data validity is important to you. I’m confident we win hands down here, although of course you need to be competent enough to set it up.

Analysis Features

I think SurveyMonkey has more web-based features here, since our current focus is to do only basic online reporting and let users export their data to something more powerful like SPSS for proper statistical analysis. There’s definitely a lot we can improve on here, although we’re completely driven by the features that end-users want, so only time will tell what we decide to implement on this front.

OK, my turn

Off the top of my head, here are some features that Survey has but appear to be missing from the free version of SurveyMonkey:

  • Jump/Branching expression. The front page mentions “control the flow with custom skip logic”. Presumably that’s similar to our Jump Expressions (see my previous post). I’d love to do a detailed comparison of the relative power of their expression engine vs ours, but sadly it’s only available in the paid version. Ours gives you a very large subset of the Perl language to play with, so we’re probably winning here.
  • I hardly consider this a “feature”, but it looks like the free version of SurveyMonkey only lets you create 10 questions per survey, and you can only have 100 responses. And the free version doesn’t let you export your data to a spreadsheet program. Ouch!
  • Scoring, and branching based on scores
  • No sign of quiz mode with tabular and graphical feedback for the user to let them know how they scored (see my previous post)
  • Visualisation (see my previous post)
  • Drag and drop section/question/answer re-ordering. I can’t imagine see myself being very productive if I was trying to work on the 500+ question survey I’m building inside of the menu-driven SurveyMonkey interface.
  • The ability to modify the survey engine to do whatever custom magic you like
  • Complete control over your data ffs!This is the biggie as far as I’m concerned. Surveys built with SurveyMonkey store their data on the SurveyMonkey servers. Australia’s privacy laws are very strict about sending private data overseas, and I assume the same is true for other countries. You could land yourself in a world of trouble if you created supposedly “private” surveys where people were asked to enter personally identifying information (particularly if the data was medical related) and that data was stored overseas. You can pay to add SSL to your SurveyMonkey account, but there is no mention of database encryption, which is also something to ponder. At the end of the day, if you’re doing anything remotely private you should be self-hosting the data.
  • Have access to the code, which, among other things, means that you can build a comprehensive test suite for your complex 500+ question survey. For any complex Survey involving non-trivial branching logic, it’s invaluable to be able to build an automated test suite that independently verifies your branching and scoring logic (and makes sure that any future changes don’t break things). In Survey you can write this in Perl at the code level, interacting with Survey and the database via the WebGUI API, or using any programming language to create an automated “virtual user” that interacts with the Survey via the web interface (simulating page clicks etc..).

So…

Overall that was a bit disappointing. I mean, there’s are definitely areas we can improve on, and I’m sure that the SurveyMonkey documentation and support is great, but for something that purports to be the best of breed, … well let’s just that that as far as the free version goes you’re pretty limited in what you can do. No doubt the paid version is better, and of course most people out there just want something simple that they can jump right in and start using with minimal fuss. But it seems to me that pretty soon you start running into limitations, especially with the free version.

Ok, enough of that, let’s get back to what’s new in Survey. Here are a couple of new features that have been added in the past week:

Firstly, Kaleb committed some code a few days ago that allows you to flag Sections as “logical”. What this means is that the section is hidden from the user, but appears in the admin screen and can have branching expressions defined for it. This is really handy if you have sophisticated branching logic and you run into a situation where you need an intermediate jump target. For example, it’s a common scenario to have a bunch of “pre-section” rules that you want to evaluate before letting the user start the section. Rather than duplicating these rules on every other node that jumps to the section, you can have those nodes jump to a pre-section node that evaluates the rules in one place.

Another awesome feature that was recently committed to the Survey repo (and that won’t cost you a banana) is tagging. The Survey expression engine now allows you to tag data as you go, which allows you to do all sorts of interesting things. For instance, say you’re doing one of those magazine pop-quizzes where you (very scientifically) classify people into personality types. After asking a bunch of dog-related questions, you can now say something like this in your branch expression:

tag(“personality type”, “dog lover”) if score(“dog questions section”) > 5

That creates a new data field called “personality type” that is stored against the user’s response (in this case the stored data is the string “dog lover”). Later, you can actually use that tag inside another branch expression to only show a bunch of questions to the dog lovers:

jump { tag(“personality type”) eq “dog lover” } “more dog questions section”

Or you could use that tag inside the text of another question as templated text:

Clearly you’re a [[personality type]]!

..which would appear to the user as:

Clearly you’re a dog lover!

And finally, the tagged data is stored as part of the user’s response data, meaning that you can pull it out of the database later (using another WebGUI asset like SQLReport or your own custom code) and do whatever you like with it.

WebGUI Survey goodies

April 9th, 2009

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..

load-mask

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.

multichoice-bundles

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.

warnings

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).

summaries

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.

visualisation

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.