Version 21 (modified by Dominic König, 12 years ago) ( diff )



S3Report is a REST method handler for data analysis.


S3Report can generate contingency tables (a.k.a. pivot tables) from S3Resources.


S3Report uses pyvttbl to generate contingency tables. A modified version of pyvttbl is integrated into the S3 framework.

Pyvttbl requires the following Python modules:

  • numpy
  • matplotlib

URL Methods

S3Report responds to the /report URL method, for all resources (generic method).

The following parameters are accepted:

rowsthe name of the field to be used for the table rowsyes
colsthe name of the field to be used for the table columnsno (if no cols are specified, all instance values appear in 1 column)
factthe name of the field to be used for the instance valuesno (falls back to "name" if present, otherwise to "id")
aggregatethe aggregation functionno (default: list)
tablewhether to hide the pivot table (table=0) or show it (table=1)no
chartrender as chart by default, format: chart=<type>:<dimension>no

rows, cols and fact support the same options as list_fields:

  • fields in the table
  • virtual fields in the table
  • fields/virtual fields in tables linked by foreign keys ($-notation)

The chart option accepts:

  • type: piechart|barchart|breakdown
  • dimension: rows|cols

S3Report supports a number of aggregation functions. The following functions have been tested so far:

lista comma-separated list of all instance values
countthe number of instance values
sumthe sum of all instance values
avgthe average (mean) of all instance values


$-notation for references:

reduced parameter list:

Report Options

Table configurations can contain a report_options item, which is a Storage object. This object is used to configure reports and report options form.

The rows, cols, facts and aggregate items are lists of available values for the user to select from.

The defaults property is a Storage object that contains the default values for the report. It can contain a value for rows, cols, fact, aggregate and totals (as described in URL Methods).

The search property is a list of S3Search widgets that will allow the report to be filtered. If no search property is specified, no filter form will be available.

Here is an example of a report_options item:

                        label = T("Project"),
                        field = "project_id",

All items in report_options and defaults are optional.

If fact and methods are configured like:

   report_options = Storage(
       fact = [field1, field2, field3],
       methods = [method1, method2],

then S3Report will automatically provide a selection of all (mathematically) meaningful field-method-combinations. Some of these combinations may not be relevant for the use-case, though. To specify field-method-combinations instead, you can configure it like:

   report_options = Storage(
       fact = [
               (field1, method1),
               (field2, method1),
               (field2, method2),
               (field3, method1),

Optionally, you can define a custom label for each combination (which will be used in the select list):

   report_options = Storage(
       fact = [
               (field1, method1, T("My Report A")),
               (field2, method1, T("My Report B")),
               (field2, method2, T("My Report C")),
               (field3, method1, T("My Report D")),

Further Development

The following enhancements are currently under development:

  • Support for JSON, CSV and XLS exports
Note: See TracWiki for help on using the wiki.