IMsCrossDimensionAggregationTransform.AppliesToExpression

Fore Syntax

AppliesToExpression: IExpression;

Fore.NET Syntax

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

Description

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

Comments

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

Fore Example

To execute the example the time series database with the FC identifier is supposed to be in the repository. The COUNTRY and the INDICATOR are the database attributes, referring to the dictionaries. The modeling container of the given base 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 the time series DB and it's modeling container
    RubrDescr := mb.ItemById("FC");
    Rubr := RubrDescr.Bind As IRubricator;
    msDescr := Rubr.ModelSpace;
    // Get the 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 the 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 the element for the 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 the expression for aggregation calculation
    Term := Aggr.Operands.Add(SliceInp);
    Aggr.Expression.AsString := "Fill(" + Term.TermToInnerText + ", MsFillMethod.RandomValue)";
    // Get the 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 the expression for weights calculation   
    Term := Aggr.WeightsOperands.Add(SliceInp);
    Aggr.WeightsExpression.AsString := Term.TermToInnerText + "+2";
    // Get the 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 the expression for the structure relevance calculation
    Term := Aggr.CompositionRelevanceOperands.Add(SliceInp);
    Aggr.CompositionRelevanceExpression.AsString := Term.TermToInnerText + "*2";
    // Get the elements for calculation expression of the elements, which are aggregated without considering 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 considering 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 the model
    (Model As IMetabaseObject).Save;
End Sub UserProc;

After executing the example the following model parameters are modified:

In the console window the expression, by which the aggregation is calculated is displayed, 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 the time series DB and it's modeling container
    RubrDescr := mb.ItemById["FC"];
    Rubr := RubrDescr.Bind() As IRubricator;
    msDescr := Rubr.ModelSpace;
    // Get the 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 the 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 the element for the 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 the expression for aggregation calculation
    Term := Aggr.Operands.Add(SliceInp);
    Aggr.Expression.AsString := "Fill(" + Term.TermToInnerText() + ", MsFillMethod.RandomValue)";
    // Get the 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 the expression for weights calculation   
    Term := Aggr.WeightsOperands.Add(SliceInp);
    Aggr.WeightsExpression.AsString := Term.TermToInnerText() + "+2";
    // Get the 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 the expression for the structure relevance calculation
    Term := Aggr.CompositionRelevanceOperands.Add(SliceInp);
    Aggr.CompositionRelevanceExpression.AsString := Term.TermToInnerText() + "*2";
    // Get the elements for calculation expression of the elements, which are aggregated without considering 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 considering 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 the model
    (Model As IMetabaseObject).Save();
End Sub;

See also:

IMsCrossDimensionAggregationTransform