Package s3 :: Module s3report :: Class S3PivotTable
[frames] | no frames]

Class S3PivotTable

source code

object --+
         |
        S3PivotTable

Class representing a pivot table of a resource

Instance Methods
 
__init__(self, resource, rows, cols, facts, strict=True, precision=None)
Constructor - extracts all unique records, generates a pivot table from them with the given dimensions and computes the aggregated values for each cell.
source code
 
__len__(self)
Total number of records in the report
source code
 
geojson(self, fact=None, level="L0")
Render the pivot table data as a dict ready to be exported as GeoJSON for display on a Map.
source code
 
json(self, maxrows=None, maxcols=None)
Render the pivot table data as JSON-serializable dict
source code
 
xls(self, title)
Convert this pivot table into an XLS file
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables
  records
All records in the pivot table as a Storage like:...
  empty
Empty-flag (True if no records could be found)
  numrows
The number of rows in the pivot table
  numcols
The number of columns in the pivot table
  cell
Array of pivot table cells in [rows[columns]]-order, each...
  row
List of row headers, each header is a Storage like:...
  col
List of column headers, each header is a Storage like:...
  totals
The grand total values for each layer, as a Storage like:...
Properties

Inherited from object: __class__

Method Details

__init__(self, resource, rows, cols, facts, strict=True, precision=None)
(Constructor)

source code 

Constructor - extracts all unique records, generates a pivot table from them with the given dimensions and computes the aggregated values for each cell.

Parameters:
  • resource - the S3Resource
  • rows - field selector for the rows dimension
  • cols - field selector for the columns dimension
  • facts - list of S3PivotTableFacts to compute
  • strict - filter out dimension values which don't match the resource filter
  • precision - maximum precision of aggregate computations, a dict {selector:number_of_decimals}
Overrides: object.__init__

__len__(self)
(Length operator)

source code 

Total number of records in the report

geojson(self, fact=None, level="L0")

source code 

Render the pivot table data as a dict ready to be exported as GeoJSON for display on a Map.

Called by S3Report.geojson()

Parameters:
  • layer - the layer. e.g. ("id", "count")
    • we only support methods "count" & "sum"
    • @ToDo: Support density: 'per sqkm' and 'per population'
  • level - the aggregation level (defaults to Country)

json(self, maxrows=None, maxcols=None)

source code 

Render the pivot table data as JSON-serializable dict

@param layer: the layer
@param maxrows: maximum number of rows (None for all)
@param maxcols: maximum number of columns (None for all)
@param least: render the least n rows/columns rather than
              the top n (with maxrows/maxcols)

{
    labels: {
        layer:
        rows:
        cols:
        total:
    },
    method: <aggregation method>,
    cells: [rows[cols]],
    rows: [rows[index, value, label, total]],
    cols: [cols[index, value, label, total]],

    total: <grand total>,
    filter: [rows selector, cols selector]
}

xls(self, title)

source code 

Convert this pivot table into an XLS file

Parameters:
  • title - the title of the report
Returns:
the XLS file as stream

Instance Variable Details

records

All records in the pivot table as a Storage like:
{
 <record_id>: <Row>
}

empty

Empty-flag (True if no records could be found)

numrows

The number of rows in the pivot table

numcols

The number of columns in the pivot table

cell

Array of pivot table cells in [rows[columns]]-order, each
cell is a Storage like:
    {
     records: <list_of_record_ids>,
     (<fact>, <method>): <aggregated_value>, ...per layer
    }

row

List of row headers, each header is a Storage like:
{
 value: <dimension value>,
 records: <list_of_record_ids>,
 (<fact>, <method>): <total value>, ...per layer
}

col

List of column headers, each header is a Storage like:
{
 value: <dimension value>,
 records: <list_of_record_ids>,
 (<fact>, <method>): <total value>, ...per layer
}

totals

The grand total values for each layer, as a Storage like:
{
 (<fact>, <method): <total value>, ...per layer
}