IMsCrossDimensionAggregationTransform.AppliesToExpression

Fore Syntax

AppliesToExpression: IExpression;

Fore.NET Syntax

AppliesToExpression: Prognoz.Platform.Interop.ForeSystem.IExpression;

Description

The AppliesToExpression property determines the expression that is used to set the components, which are aggregated without missing data treatment.

Comments

The collection of the elements, which can be used in the expression, is returned by the IMsCrossDimensionAggregationTransform.AppliesToOperands property.

Fore Example

Executing the example requires that the repository contains a time series database with the FC identifier. COUNTRY and INDICATOR are the database attributes referring to the dictionaries. The modeling container of the given database must contain:

Add links to the Metabase, Ms, Cubes, Dimensions system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    RubrDescr: IMetabaseObjectDescriptor;
    Rubr: IRubricator;
    msDescr: IMetabaseObjectDescriptor;
    Model: IMsModel;
    Transform: IMsFormulaTransform;
    Formula: IMsFormula;
    Aggr: IMsCrossDimensionAggregationTransform;
    strsGen: IMsFormulaStringGenerator;
    Term: IMsFormulaTerm;
    selFactory: IDimSelectionSetFactory;
    SelSet: IDimSelectionSet;
    Attributes: IMetaAttributes;
    DictC, DictI: IMetabaseObjectDescriptor;
    SliceInp: IMsFormulaTransformSlice;
    Options: IMsCrossDimensionAggregationOptions;
    FiltesList: IMsAggregationFilterList;
    Filter: IMsAggregationFilter;
Begin
    mb := MetabaseClass.Active;
    // Get time series database and its modeling container
    RubrDescr := mb.ItemById("FC");
    Rubr := RubrDescr.Bind As IRubricator;
    msDescr := Rubr.ModelSpace;
    // Get model
    Model := mb.ItemByIdNamespace("CROSS_DIM_AGGR", msDescr.Key).Edit As IMsModel;
    Transform := Model.Transform;
    Formula := Transform.FormulaItem(0);
    // Set up aggregation calculation parameters
    Aggr := Formula.Method As IMsCrossDimensionAggregationTransform;
    Aggr.AgregationMethod := MsAgregationMethodType.WeightedAverage;
    selFactory := New DimSelectionSetFactory.Create;
    SelSet := selFactory.CreateDimSelectionSet;
    // Get factors attributes and dictionaries, to which they refer
    Attributes := Rubr.Facts.Attributes;
    DictC := Attributes.FindById("COUNTRY").ValuesObject;
    DictI := Attributes.FindById("INDICATOR").ValuesObject;
    SelSet.Add(DictC.Open(NullAs IDimInstance);
    SelSet.Add(DictI.Open(NullAs IDimInstance);
    // Get element for aggregation calculation expression 
    SelSet.Item(0).DeselectAll;
    SelSet.Item(1).DeselectAll;
    SelSet.Item(1).SelectElement(1False);
    SliceInp := Transform.Inputs.Add(RubrDescr.Bind As IVariableStub).Slices.Add(SelSet);
    // Set expression for aggregation calculation
    Term := Aggr.Operands.Add(SliceInp);
    Aggr.Expression.AsString := "Fill(" + Term.TermToInnerText + ", MsFillMethod.RandomValue)";
    // Get element for weights calculation expression
    SelSet.Item(1).DeselectAll;
    SelSet.Item(1).SelectElement(2False);
    SliceInp := Transform.Inputs.Add(RubrDescr.Bind As IVariableStub).Slices.Add(SelSet);
    // Set expression for weights calculation   
    Term := Aggr.WeightsOperands.Add(SliceInp);
    Aggr.WeightsExpression.AsString := Term.TermToInnerText + "+2";
    // Get elements for structure relevance calculation expression
    SelSet.Item(1).DeselectAll;
    SelSet.Item(1).SelectElement(3False);
    SliceInp := Transform.Inputs.Add(RubrDescr.Bind As IVariableStub).Slices.Add(SelSet);
    // Set expression for structure relevance calculation
    Term := Aggr.CompositionRelevanceOperands.Add(SliceInp);
    Aggr.CompositionRelevanceExpression.AsString := Term.TermToInnerText + "*2";
    // Get elements for calculation expression of the elements, which are aggregated without taking into account missing data
    SelSet.Item(1).DeselectAll;
    SelSet.Item(1).SelectElement(1False);
    SliceInp := Transform.Inputs.Add(RubrDescr.Bind As IVariableStub).Slices.Add(SelSet);
    // Set expression  for calculating the elements, which are aggregated without taking into account missing data
    Aggr.AppliesToOperands.Add(SliceInp);
    Aggr.AppliesToExpression.AsString := Term.TermToInnerText;
    // Set aggregation filter
    FiltesList := Aggr.Filter;
    Filter := FiltesList.Add(DictC.Bind As IDimensionModel);
    Filter.AggregationParamID := "Country_Param";
    Filter.UseParamAsGroup := True;
    // Set additional aggregation calculation parameters
    Options := Aggr.Options;
    Options.Threshold := 20;
    Options.Percentile := 50;
    Options.KeepSegment := True;
    // Generate model name
    strsGen := Formula.CreateStringGenerator;
    strsGen.ShowFullVariableNames := True;
    Debug.WriteLine("Aggregation expression: " + strsGen.Execute);
    // Save model
    (Model As IMetabaseObject).Save;
End Sub UserProc;

After executing the example the following model parameters are changed:

The console window displays the expression, by which aggregation is calculated, for example:

Aggregation expression: Afghanistan|BCA[t] = Sum((fill(BCI[t], MsFillMethod.RandomValue)) * (BDS[t] + 2)) / Sum(BDS[t] + 2)

Fore.NET Example

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.Dimensions;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Rds;

[STAThread]
Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    RubrDescr: IMetabaseObjectDescriptor;
    Rubr: IRubricator;
    msDescr: IMetabaseObjectDescriptor;
    Model: IMsModel;
    Transform: IMsFormulaTransform;
    Formula: IMsFormula;
    Aggr: IMsCrossDimensionAggregationTransform;
    strsGen: IMsFormulaStringGenerator;
    Term: IMsFormulaTerm;
    selFactory: IDimSelectionSetFactory;
    SelSet: IDimSelectionSet;
    Attributes: IMetaAttributes;
    DictC, DictI: IMetabaseObjectDescriptor;
    SliceInp: IMsFormulaTransformSlice;
    Options: IMsCrossDimensionAggregationOptions;
    FiltesList: IMsAggregationFilterList;
    Filter: IMsAggregationFilter;
Begin
    mb := Params.Metabase;
    // Get time series database and its modeling container
    RubrDescr := mb.ItemById["FC"];
    Rubr := RubrDescr.Bind() As IRubricator;
    msDescr := Rubr.ModelSpace;
    // Get model
    Model := mb.ItemByIdNamespace["CROSS_DIM_AGGR", msDescr.Key].Edit() As IMsModel;
    Transform := Model.Transform;
    Formula := Transform.FormulaItem[0];
    // Set up aggregation calculation parameters
    Aggr := Formula.Method As IMsCrossDimensionAggregationTransform;
    Aggr.AgregationMethod := MsAgregationMethodType.mammtWeightedAverage;
    selFactory := New DimSelectionSetFactory.Create();
    SelSet := selFactory.CreateDimSelectionSet();
    // Get factors attributes and dictionaries, to which they refer
    Attributes := Rubr.Facts.Attributes;
    DictC := Attributes.FindById("COUNTRY").ValuesObject;
    DictI := Attributes.FindById("INDICATOR").ValuesObject;
    SelSet.Add(DictC.Open(NullAs IDimInstance);
    SelSet.Add(DictI.Open(NullAs IDimInstance);
    // Get element for aggregation calculation expression 
    SelSet.Item[0].DeselectAll();
    SelSet.Item[1].DeselectAll();
    SelSet.Item[1].SelectElement(1False);
    SliceInp := Transform.Inputs.Add(RubrDescr.Bind() As IVariableStub).Slices.Add(SelSet);
    // Set expression for aggregation calculation
    Term := Aggr.Operands.Add(SliceInp);
    Aggr.Expression.AsString := "Fill(" + Term.TermToInnerText() + ", MsFillMethod.RandomValue)";
    // Get element for weights calculation expression
    SelSet.Item[1].DeselectAll();
    SelSet.Item[1].SelectElement(2False);
    SliceInp := Transform.Inputs.Add(RubrDescr.Bind() As IVariableStub).Slices.Add(SelSet);
    // Set expression for weights calculation   
    Term := Aggr.WeightsOperands.Add(SliceInp);
    Aggr.WeightsExpression.AsString := Term.TermToInnerText() + "+2";
    // Get elements for structure relevance calculation expression
    SelSet.Item[1].DeselectAll();
    SelSet.Item[1].SelectElement(3False);
    SliceInp := Transform.Inputs.Add(RubrDescr.Bind() As IVariableStub).Slices.Add(SelSet);
    // Set expression for structure relevance calculation
    Term := Aggr.CompositionRelevanceOperands.Add(SliceInp);
    Aggr.CompositionRelevanceExpression.AsString := Term.TermToInnerText() + "*2";
    // Get elements for calculation expression of the elements, which are aggregated without taking into account missing data
    SelSet.Item[1].DeselectAll();
    SelSet.Item[1].SelectElement(1False);
    SliceInp := Transform.Inputs.Add(RubrDescr.Bind() As IVariableStub).Slices.Add(SelSet);
    // Set expression  for calculating the elements, which are aggregated without taking into account missing data
    Aggr.AppliesToOperands.Add(SliceInp);
    Aggr.AppliesToExpression.AsString := Term.TermToInnerText() + "-4";
    // Set aggregation filter
    FiltesList := Aggr.Filter;
    Filter := FiltesList.Add(DictC.Bind() As IDimensionModel);
    Filter.AggregationParamID := "Country_Param";
    Filter.UseParamAsGroup := True;
    // Set additional aggregation calculation parameters
    Options := Aggr.Options;
    Options.Threshold := 20;
    Options.Percentile := 50;
    Options.KeepSegment := True;
    // Generate model name
    strsGen := Formula.CreateStringGenerator();
    strsGen.ShowFullVariableNames := True;
    System.Diagnostics.Debug.WriteLine("Aggregation expression: " + strsGen.Execute());
    // Save model
    (Model As IMetabaseObject).Save();
End Sub;

See also:

IMsCrossDimensionAggregationTransform