IMsMetaModelVisualController.GetVariableByAttrValues

Syntax

GetVariableByAttrValues(RubricatorKey: Integer;
                        AttrKeys: Array;
                        AttrValues: Array;
                        GraphMeta: String
                        Var VariableExists: Boolean;
                        [ParentKey: Integer = -1]): IMsCalculationChainVariable;

Parameters

RubricatorKey. Time series database key.

AttrKeys. Array of keys of attributes by values of which the variable will be extracted.

AttrValues. Array of attribute values.

GraphMeta. Graphical context.

VariableExists. The attribute of the fact that the variable corresponding to the specified series exists in the internal time series database. It is returned after executing the method.

ParentKey. Parent element key.

Description

The GetVariableByAttrValues method returns the variable corresponding to the series with the specified value of attributes.

Comments

The AttrKeys array must contain real values, and the AttrValues array must contain Variant type values. The order of attribute keys in the AttrKeys array must correspond to that in the AttrValues array, that is, the first element of the AttrKeys array sets the attribute key and the first element of the AttrValues array is the value of this attribute and so on.

The GraphMeta parameter can take the Null value.

Available values of the VariableExists parameter:

If the ParentKey parameter is set to -1, the variable is in the time series database root.

Example

Executing the example requires:

  1. A time series database with the TSDB identifier, containing an attribute with the COUNTRY and INDICATOR identifiers. These attributes should be links to the dictionary. Dictionary to which the COUNTRY attribute is referred should contain element with the 755 key and dictionary to which the INDICATOR attribute is referred should contain element with the 765 key.

  2. A modeling container with the MS identifier, containing a metamodel with the META identifier.

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

Sub GetVariableByAttrValues;
Var
    mb: IMetabase;
    RubObj, MsObj: IMetabaseObjectDescriptor;
    Meta: IMsMetaModel;
    MetaVisual: IMsMetaModelVisualController;
    VarInp: IMsCalculationChainVariable;
    VarEx: Boolean;
    InVarKey, InModelKey: Integer;
    InpKeys: Array[1Of Integer;
    AttsKey: Array[2Of Integer;
    AttsVal: Array[2Of Variant;
    SimpleModel: IMsModel;
    j: Integer;
Begin
    mb := MetabaseClass.Active;
    // Get modeling container
    MsObj := mb.ItemById("MS");
    // Get metamodel
    Meta := mb.ItemByIdNamespace("META", MsObj.Key).Edit As IMsMetaModel;
    MetaVisual := Meta.VisualController;
    // Set attribute values of input variable
    RubObj := mb.ItemById("TSDB");
    AttsKey[0] := (RubObj.Bind As IRubricator).Facts.Attributes.FindById("CITY").Key;
    AttsVal[0] := 755;
    AttsKey[1] := (RubObj.Bind As IRubricator).Facts.Attributes.FindById("INDICATOR").Key;
    AttsVal[1] := 765;
    // Add folder
    j := Meta.CalculationChain.AddFolder("Folder for expression").Key;
    // Create input variable in folder and get variable key
    VarInp := MetaVisual.GetVariableByAttrValues(RubObj.Key, AttsKey, AttsVal, "", VarEx, j);
    VarInp.Slice.Level := DimCalendarLevel.Year;
    InpKeys[0] := VarInp.Key;
    // Create internal model in folder
    SimpleModel := MetaVisual.CreateSimpleModel(-1, InpKeys, VarInp.Key, MsFormulaKind.LinearRegression, "", InVarKey, InModelKey, j);
    // Display model name in the console window
    Debug.WriteLine(SimpleModel.CreateStringGenerator.Execute);
    // Save metamodel
    (Meta As IMetabaseObject).Save;
End Sub GetVariableByAttrValues;

After executing the example folder will be created in the META metamodel. Variable basing on specified values of time series database attributes will be added in this folder. Model using added variable will be also created in this folder.

See also:

IMsMetaModelVisualController