Useful HTML reports

While doing research, you sometimes run into the situation where you are getting loads and loads of results, and you need to create nice reports to simplify the analysis. Often this is tabular data, sometimes you might be able to create some images, but the key point is you need a simple way to bundle this all together. As the topic title suggest, HTML fits the bill very nicely. It's reasonably easy to generate (after all, it's text only), you can embed additional data (images), and you can also use JavaScript to improve the usability of the report.

For HTML generation, I started to use basic C++ iostreams, but this quickly becomes unmaintainable, and you will run into debug problems. If your markup is wrong, it's very complicated to see in the C++ code where the error source is. A much nicer solution is Google ctemplate, a C++ HTML template engine in the spirit of Smarty. Basically, you can author the template using any HTML editor, add some markup for repeating sections, then you fill out some values on the C++ side, and your done. For debugging, you simply strip the template tags, and validate the code with any HTML validator. Two things are especially nice about ctemplate. First of all, repeating sections is trivial. If you add a dictionary for a section twice, it will be repeated twice in the output, no need to set up loop constructs on your own. Seconds, it's fast -- generating a 50 MiB HTML file takes ~ 2 seconds with it. For viewing such large files, I can recommend to use a WebKit based browsers, as at least Firefox 3.0 has some problems when closing such a file.

To improve the report usability, you can use make them interactive using a JavaScript. I can recommend the very nice JQuery framework -- in fact, it worked so fine, that I didn't bother to try another one ;). JQuery allows to add hide/add hyperlinks very easily, which is useful if your report contains detail data that you don't want to display all the time. All you need is to give your items an id, and then toggle the visibility of the item using $("#yourId").toggle(). If you have tabular data, JQuery has a real killer plugin: TableSorter. This allows you to sort tables interactively, without any additional setup code. All you have to do is to use proper headers for your table, and you're ready to sort.

I have to admit that I still use plain-text only reporting quite a bit, but it's usually much faster for analysis to have a nice report with some comfort (hyperlinks to additional data, embedded images). With the ctemplate stuff, the cost of adding HTML output over plain-text is rather minimal, so the next time you run into a situation where you'll need some output, you should really consider to give HTML a try.


Comments powered by Disqus