Aggregation: IMsParametrizedDimensionAggregation;
Aggregation: Prognoz.Platform.Interop.Ms.IMsParametrizedDimensionAggregation;
The Aggregation property returns settings of aggregation for parametrized dimension.
By default parametrized dimension is not aggregated.
Executing the example requires that the repository contains a modeling container with the MS identifier that contains a metamodel with the METAMODEL_PARAMAGGREGATION identifier. This model must calculate an equation with the MODEL_PARAMAGGREGATION identifier containing one or several factors. The modeling container data source must contain an attribute with the CITY identifier that is a link to a dictionary containing a logical attribute with the ISCAPITAL identifier.
Add links to the Cubes, Dal, Dimensions, Matrix, Metabase, Ms, Rds, Transform system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsKey: Integer;
TSDB: IRubricator;
MS: IMsModelSpace;
Attributes: IMetaAttributes;
Dict: IMetabaseObjectDescriptor;
MetaModel: IMsMetaModel;
MParams: IMsModelParams;
CParam: IMsModelParam;
Model: IMsModel;
Transform: IMsFormulaTransform;
Inputs: IMsFormulaTransformVariable;
Slice: IMsFormulaTransformSlice;
dimInstC: IDimInstance;
dimSelC: IDimSelection;
paramDim: IMsParametrizedDimensions;
paramD: IMsParametrizedDimension;
Aggregation: IMsParametrizedDimensionAggregation;
CAdvFilter: IMsDimIteratorAdvancedFilter;
i: Integer;
CAdvFilterCond: IMsDimIteratorAdvancedFilterCondition;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modeling container key
MsKey := mb.GetObjectKeyById("MS");
// Get modeling container
MS := mb.Item(MsKey).Bind As IMsModelSpace;
// Get time series database
// which is a data source for modeling container
TSDB := MS.DefaultObject.Bind As IRubricator;
// Get series attributes
Attributes := TSDB.Facts.Attributes;
// Get dictionary which is the base for the CITY attribute
Dict := Attributes.FindById("CITY").ValuesObject;
// Get metamodel
MetaModel := mb.ItemByIdNamespace("METAMODEL_PARAMAGGREGATION", MsKey).Edit As IMsMetaModel;
// Get and clear metamodel parameters
MParams := MetaModel.Params;
MParams.Clear;
// Add a parameter based on dictionary of the CITY attribute
CParam := MParams.Add;
CParam.DataType := DbDataType.Integer;
CParam.Hidden := True;
CParam.Id := "CITY";
CParam.Name := "City";
CParam.LinkedObject := Dict;
CParam.ParamType := TsParamType.Selection;
dimInstC := Dict.Open(Null) As IDimInstance;
dimSelC := dimInstC.CreateSelection;
dimSelC.SelectElement(1, False);
CParam.DefaultValue := dimSelC;
// Save metamodel
(MetaModel As IMetabaseObject).Save;
// Get model
Model := mb.ItemByIdNamespace("MODEL_PARAMAGGREGATION", MsKey).Edit As IMsModel;
// Get model calculation parameters
Transform := Model.Transform;
// Get model factor
Inputs := Transform.Inputs.Item(0);
// Determine that the attribute value based on the CITY attribute dictionary
// is determined by metamodel parameter
Slice := Inputs.Slices.Item(0);
paramDim := Slice.ParametrizedDimensions;
paramD := paramDim.FindById(dimInstC.Ident);
paramD.ParamAttributes.Parameter := CParam;
// Get aggregation parameters
Aggregation := paramD.Aggregation;
// Determine that aggregation is executed by hierarchy
Aggregation.ByHierarchy := True;
// Set aggregation type
Aggregation.Type := BasicAggregatorOperation.Sum;
// Get advanced filter and clear all conditions
CAdvFilter := Aggregation.AdvancedFilter;
CAdvFilter.Clear;
// Add advanced filtering condition
CAdvFilterCond := CAdvFilter.Add;
// Set filtered attribute
CAdvFilterCond.Attribute := dimInstC.Attributes.FindById("ISCAPITAL").Attribute;
// Set comparison operator
CAdvFilterCond.Operator_ := MsAdvancedFilterConditionOperator.Equal;
// Set required attribute value
CAdvFilterCond.Value := True;
// Save model
(Model As IMetabaseObject).Save;
End Sub UserProc;
After executing the example a parametrized dimension is set for the first factor, in which aggregation is set up.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Rds;
Imports Prognoz.Platform.Interop.Transform;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsKey: uinteger;
TSDB: IRubricator;
MS: IMsModelSpace;
Attributes: IMetaAttributes;
Dict: IMetabaseObjectDescriptor;
MetaModel: IMsMetaModel;
MParams: IMsModelParams;
CParam: IMsModelParam;
Model: IMsModel;
Transform: IMsFormulaTransform;
Inputs: IMsFormulaTransformVariable;
Slice: IMsFormulaTransformSlice;
dimInstC: IDimInstance;
dimSelC: IDimSelection;
paramDim: IMsParametrizedDimensions;
paramD: IMsParametrizedDimension;
Aggregation: IMsParametrizedDimensionAggregation;
CAdvFilter: IMsDimIteratorAdvancedFilter;
i: Integer;
CAdvFilterCond: IMsDimIteratorAdvancedFilterCondition;
Begin
// Get current repository
mb := Params.Metabase;
// Get modeling container key
MsKey := mb.GetObjectKeyById("MS");
// Get modeling container
MS := mb.Item[MsKey].Bind() As IMsModelSpace;
// Get time series database
// which is a data source for modeling container
TSDB := MS.DefaultObject.Bind() As IRubricator;
// Get series attributes
Attributes := TSDB.Facts.Attributes;
// Get dictionary which is the base for the CITY attribute
Dict := Attributes.FindById("CITY").ValuesObject;
// Get metamodel
MetaModel := mb.ItemByIdNamespace["METAMODEL_PARAMAGGREGATION", MsKey].Edit() As IMsMetaModel;
// Get and clear metamodel parameters
MParams := MetaModel.Params;
MParams.Clear();
// Add a parameter based on dictionary of the CITY attribute
CParam := MParams.Add();
CParam.DataType := DbDataType.ddtInteger;
CParam.Hidden := True;
CParam.Id := "CITY";
CParam.Name := "City";
CParam.LinkedObject := Dict;
CParam.ParamType := TsParamType.tsptSelection;
dimInstC := Dict.Open(Null) As IDimInstance;
dimSelC := dimInstC.CreateSelection();
dimSelC.SelectElement(1, False);
CParam.DefaultValue := dimSelC;
// Save metamodel
(MetaModel As IMetabaseObject).Save();
// Get model
Model := mb.ItemByIdNamespace["MODEL_PARAMAGGREGATION", MsKey].Edit() As IMsModel;
// Get model calculation parameters
Transform := Model.Transform;
// Get model factor
Inputs := Transform.Inputs.Item[0];
// Determine that the attribute value based on the CITY attribute dictionary
// is determined by metamodel parameter
Slice := Inputs.Slices.Item[0];
paramDim := Slice.ParametrizedDimensions;
paramD := paramDim.FindById(dimInstC.Ident);
paramD.ParamAttributes.Parameter := CParam;
// Get aggregation parameters
Aggregation := paramD.Aggregation;
// Determine that aggregation is executed by hierarchy
Aggregation.ByHierarchy := True;
// Set aggregation type
Aggregation.Type := BasicAggregatorOperation.baoSum;
// Get advanced filter and clear all conditions
CAdvFilter := Aggregation.AdvancedFilter;
CAdvFilter.Clear();
// Add advanced filtering condition
CAdvFilterCond := CAdvFilter.Add();
// Set filtered attribute
CAdvFilterCond.Attribute := dimInstC.Attributes.FindById("ISCAPITAL").Attribute;
// Set comparison operator
CAdvFilterCond.Operator := MsAdvancedFilterConditionOperator.msafcoEqual;
// Set required attribute value
CAdvFilterCond.Value := True;
// Save model
(Model As IMetabaseObject).Save();
End Sub;
See also: