Skip to content

Commit

Permalink
Renamed Rollup to Totals, changed constructor to accept *args instead…
Browse files Browse the repository at this point in the history
… of a list, removed imports for references and operations from slicer.__init__ so these must be imported from their respective packages, updated docs
  • Loading branch information
twheys committed Aug 16, 2016
1 parent c8c7b1e commit 512c253
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
30 changes: 28 additions & 2 deletions docs/2_slicer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ For each |FeatureReference|, there are the following variations:

.. code-block:: python
from fireant.slicer import WoW, DeltaMoM, DeltaQoQ
from fireant.slicer.references import WoW, DeltaMoM, DeltaQoQ
slicer.notebook.column_index_table(
metrics=['clicks', 'conversions'],
Expand All @@ -328,4 +328,30 @@ For each |FeatureReference|, there are the following variations:
.. note::

For any reference, the comparison is made for the same days of the week.
For any reference, the comparison is made for the same days of the week.


Post-Processing Operations
--------------------------

Operations include extra computations that modify the final results.

Totals
""""""

Totals adds ``ROLLUP`` to the SQL query to load the data and aggregated across dimensions. It requires one or more dimension keys as parameters for the dimensions that should be totaled. The below example will add an extra line with the total clicks and conversions for each date in addition to the three lines for each device type, desktop, mobile and tablet.

.. code-block:: python
from fireant.slicer.operations import Totals
slicer.notebook.line_chart(
metrics=['clicks', 'conversions'],
dimensions=['date', 'device'],
operations=[Totals('device')],
)
L1 and L2 Loss
""""""""""""""

Coming soon
2 changes: 0 additions & 2 deletions fireant/slicer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# coding: utf-8
from .filters import EqualityFilter, ContainsFilter, RangeFilter, WildcardFilter
from .managers import SlicerException
from .operations import Rollup
from .references import WoW, MoM, QoQ, YoY, Delta, DeltaPercentage
from .schemas import (Slicer, Metric, Dimension, CategoricalDimension, ContinuousDimension, NumericInterval,
UniqueDimension, DatetimeDimension, DatetimeInterval, DimensionValue, EqualityOperator, Join)
6 changes: 3 additions & 3 deletions fireant/slicer/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def schemas(self, slicer):
raise NotImplementedError


class Rollup(Operation):
def __init__(self, dimension_keys):
super(Rollup, self).__init__('rollup')
class Totals(Operation):
def __init__(self, *dimension_keys):
super(Totals, self).__init__('rollup')
self.dimension_keys = dimension_keys

def schemas(self, slicer):
Expand Down
4 changes: 3 additions & 1 deletion fireant/tests/slicer/test_slicer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from fireant import settings
from fireant.slicer import *
from fireant.slicer.operations import Totals
from fireant.slicer.references import *
from fireant.tests.database.mock_database import TestDatabase
from pypika import functions as fn, Tables, Case

Expand Down Expand Up @@ -702,7 +704,7 @@ def test_rollup_operation(self):
query_schema = self.test_slicer.manager.query_schema(
metrics=['foo'],
dimensions=['date', 'locale', 'account'],
operations=[Rollup(['locale', 'account'])],
operations=[Totals('locale', 'account')],
)

self.assertTrue({'table', 'metrics', 'dimensions', 'rollup'}.issubset(query_schema.keys()))
Expand Down

0 comments on commit 512c253

Please sign in to comment.