@@ -218,13 +218,17 @@ def _as_table(response: ExecutionResponse) -> ExecutionTable:
218218
219219@frozen  
220220class  TableDimension :
221+     """Dataclass used during total and dimension computation.""" 
222+ 
221223    item_ids : List [str ]
222224    idx : int 
223225    sorting : Any 
224226
225227
226228@frozen  
227229class  TotalDefinitionOrdering :
230+     """Dataclass used for ordering of total definitions.""" 
231+ 
228232    function_order : int 
229233    order : int 
230234    total : TotalDefinition 
@@ -296,6 +300,8 @@ def _convert_total_dimensions(
296300
297301@define  
298302class  TotalsComputeInfo :
303+     """Dataclass containing different values used for special case construction of pivot table totals.""" 
304+ 
299305    row_attr_ids : List [str ] =  field (on_setattr = frozen_attr )
300306    col_attr_ids : List [str ] =  field (on_setattr = frozen_attr )
301307    measure_group_rows : List [str ] =  field (on_setattr = frozen_attr )
@@ -310,6 +316,7 @@ class TotalsComputeInfo:
310316    column_subtotal_dimension_index : int  =  0 
311317
312318    def  reset_to_defaults (self ) ->  None :
319+         """Resets mutable fields to theirs default values.""" 
313320        self .has_row_and_column_grand_totals  =  False 
314321        self .has_row_and_column_sub_totals  =  False 
315322        self .has_row_subtotal_and_column_grand_total  =  False 
@@ -320,6 +327,7 @@ def reset_to_defaults(self) -> None:
320327        self .column_subtotal_dimension_index  =  0 
321328
322329    def  update_compute_info (self , col_total_attr_id : str , row_total_attr_id : str ) ->  None :
330+         """Update decision and index variables for totals construction.""" 
323331        # Check for grand totals rows/columns 
324332        # Grand total is always defined on the very first attribute of the attribute/columns bucket 
325333        if  row_total_attr_id  ==  self .row_attr_ids [0 ] and  col_total_attr_id  ==  self .col_attr_ids [0 ]:
@@ -340,6 +348,17 @@ def update_compute_info(self, col_total_attr_id: str, row_total_attr_id: str) ->
340348
341349
342350def  _get_additional_totals (insight : Insight , dimensions : list [TableDimension ]) ->  list [TotalDefinition ]:
351+     """Construct special cases of pivot table totals. 
352+ 
353+     These special cases are - 
354+       1. Grand totals - is the value obtained from row and column totals. 
355+       2. Marginal totals - is the value obtained within the subgroups from row and column subtotals. 
356+ 
357+     For `Grand Totals`, in Tiger AFM, you specify that you want total of totals with total that have only 
358+     "measureGroup" present. 
359+     For `Marginal Total`, in Tiger AFM, would need to iterate through both dimensions and obtain the missing 
360+     totalDimensions items based on the attribute and column identifiers order in buckets. 
361+     """ 
343362    totals : list [TotalDefinition ] =  []
344363    row_bucket  =  insight .get_bucket_of_type (BucketType .ROWS )
345364    col_bucket  =  insight .get_bucket_of_type (BucketType .COLS )
@@ -440,6 +459,14 @@ def _extend_marginal_totals(col_index: int, row_total: InsightTotal, tci: Totals
440459
441460
442461def  _get_computable_totals (insight : Insight , dimensions : list [TableDimension ]) ->  list [TotalDefinition ]:
462+     """ 
463+     Extracts total definitions from execution definition dimensions and converts them into total specifications for 
464+     Tiger AFM. Execution definition defines totals by a measure, aggregation function, and the attribute for whose 
465+     values we want the totals. In Tiger, measure and aggregation function remains the same, but the `totalDimensions` 
466+     with `totalDimensionItems` are best understood as coordinates for the resulting structure where the totals 
467+     should be placed. This implicitly decides which attributes should be used. This allows for multidimensional totals, 
468+     but such totals are impossible to define in the execution definition. 
469+     """ 
443470    processed_totals  =  []
444471    for  dim  in  dimensions :
445472        bucket_type  =  _GET_BUCKET_TYPE_OF_DIM_INDEX [dim .idx ]
0 commit comments