atoti.scope package

Module contents

Scope functions.

atoti.scope.cumulative(level, partitioning=None, window=range(-2147483648, 0), exclude_self=False)

Create a scope to be used in the computation of cumulative aggregations.

Cumulative aggregations include cumulative sums (also called running sum or prefix sum), average, min, max, etc.

Example with m2 = tt.agg.sum(m1, scope=tt.scope.cumulative(date))

date

m1

m2

2000/01/01

15

15

2000/01/02

10

25

2000/02/03

20

45

2000/02/05

30

75

2000/04/05

5

90

2000/04/05

10

95

If the level is part of a multi-level hierarchy, it is possible to reset the aggregation when the value of a level changes. For instance, a running sum over a date can be reset at the beginning of each month. m2 = tt.agg.sum(m1, scope=tt.scope.cumulative("day", partitioning="month"))

year/month/day

m1

m2

Comment

2000/01/01

15

15

2000/01/02

10

25

2000/02/03

20

20

Reset at the beginning of February

2000/02/05

30

50

2000/04/05

5

5

Reset at the beginning of April

2000/04/05

10

15

Parameters
  • level (Level) – the level along which the aggregation is performed

  • partitioning (Optional[Level]) – the levels in the hierarchy at which to start the aggregation over

  • window (Optional[range]) – a custom range of aggregation. The range defines the set of members before and after a given member (using the level comparator) to be considered in the computation of the running aggregation. A custom range allows to compute the 5-day sliding average of a measure, for instance. By default the range is (-inf, 0), meaning that the value for a given member is computed using all of the members before it and none after it. The first value of the range should always be ≤0 and the second should always be ≥0.

  • exclude_self (bool) – whether to include a member’s contribution in its own cumulative value

atoti.scope.origin(*levels)

Create an aggregation scope with an arbitrary number of levels.

The collection of levels defines a boundary above and under which the aggregation is performed differently. When those levels are not expressed in a query, the measure will drill down until finding the value for all members of these levels, and then aggregate those values using the user-defined aggregation function. This allows to compute measures that show the yearly average when looking at the grand total, but the sum of each month’s value when looking at each year individually.

Parameters

levels (Union[str, Level]) – the levels defining the dynamic aggregation domain

atoti.scope.siblings(hierarchy, exclude_self=False)

Create a “siblings” aggregation scope.

In a siblings scope, the value for the member of a given level in the hierarchy is computed by taking the contribution of all of the members on the same level (its siblings), possibly except that member itself.

A siblings aggregation is an appropriate tool for operations such as marginal aggregations (marginal VaR, marginal average) for non-linear aggregation functions.

Parameters
  • hierarchy (Union[str, Hierarchy]) – the hierarchy containing the levels along which the aggregation is performed

  • exclude_self (bool) – whether to include the current member’s contribution in its cumulative value