Time Series Search

The example displays time series search in the time series database that is a data source for express report. All the time series with data and containing the word mln are found.

Executing the example requires that the repository contains an express report with the REPORT_LOOKUP identifier. Data source for the report is a time series database containing time series custom attributes with the INDICATOR and CITY identifiers. These attributes are links to dictionaries.

After executing the example the console window displays names of the found series.

Example

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

Sub FactorsLookup;
Var
    mb: IMetabase;
    Eax: IEaxAnalyzer;
    Cube: ICubeInstance;
    RubI: IRubricatorInstance;
    Rub: IRubricator;
    DictionaryInstance: IMetaDictionaryInstance;
    resSelSet,SelectionSet: IDimSelectionSet;
    factLookup: IRubricatorFactsLookup;
    criteria: IDimTextCriteria;
    factory: IDimSelectionSetFactory;
    selection: IDimSelection;
    attributes: IMetaAttributes;
    attr: IMetaAttribute;
    id: string;
    IsSelectionSetEmpty: Boolean;
    res, Arr: array Of Integer;
    i: Integer;
    isFind: Boolean = False;
    Loo: IMetaDictionaryLookup;
    Cond: IOrmCondition;
Begin
//Get repository     mb := MetabaseClass.Active;
//Get the REPORT_LOOKUP express report     Eax := mb.ItemById("REPORT_LOOKUP").Bind As IEaxAnalyzer;
//Get express report data source as a cube     Cube := (Eax.Pivot.DataSource As ICubeInstanceDestination).Cube;
//If time series database is an express report data source, //execute search     If Cube Is IRubricatorInstance Then
//Get instance of time series database         RubI := Cube As IRubricatorInstance;
        Rub := RubI.Rubricator;
Debug.WriteLine("Search in time series database'"+(RubAsIMetabaseObject).Name+"':"); //Get time series dictionary         DictionaryInstance := RubI.GetDictionary(RubricatorDictionary.Facts);
//Create an object for time series search         factLookup := RubI.CreateFactsLookup;
//Set search criteria         criteria := New DimTextCriteria.Create;
//Search for occurrence of searched word in values of string attributes         criteria.CriteriaOptions := TextCriteriaOptions.SearchStringAttributes Or TextCriteriaOptions.FreeText;
//Set searched word         criteria.Text := "mln";
//Search among the elements selected in time series database dimensions         criteria.SelectOptions := ConditionSelectOptions.SelectedOnly;
//Create a selection in time series database dimensions         factory := New DimSelectionSetFactory.Create;
        SelectionSet := factory.CreateDimSelectionSet;
//Get all time series attributes         attributes := Rub.Facts.Attributes;
//Parse all time series attributes         For Each Attr In attributes Do
            id := Attr.Id;
//If it is the INDICATOR or CITY attribute, //select all elements in the dimension based on this attribute             If (Id = "INDICATOR"Or (Id = "CITY"Then
                selection := SelectionSet.Add(Attr.ValuesObject.Open(NullAs IDimInstance);
                selection.SelectAll;
            End If;
        End For;
//Filter attributes by specified parameters         resSelSet := factLookup.SetTextCriteria(criteria, SelectionSet);
//Check if time series with corresponding text are found         selection := Null;
        For Each selection In resSelSet Do
            If selection.SelectedCount > 0 Then
                IsSelectionSetEmpty := False;
                Else IsSelectionSetEmpty := True;
            End If;
        End For;
//If time series are found, check if they contain data         If Not IsSelectionSetEmpty Then
//Get keys of found time series             res := factLookup.LookupFactors;
            If (Not IsNULL(res)) And (res.Length <> 0Then
//Create an object for time series search by specified attribute values                 Loo := RubI.Values.CreateLookup;
//Specify that search by the last actual revision                 Loo.WhereRevisionKey := -1;
//Specify that time series must not be removed                 Loo.WhereIsDeleted := TriState.OffOption;
//Specify that time series must contain data                 Cond := Loo.Where.Add;
                Cond.AttributeName := "VL";
                Cond.Operator_ := OrmComparisonOperator.IsNotNull;
//Limit search by the time series containing the text "mln" in the name                 Cond := Loo.Where.Add;
                Cond.AttributeName := "FACTOR";
                Cond.Operator_ := OrmComparisonOperator.In_;
                //Cond.Value := arr2;
                Cond.Value := res;
//Get keys of found time series                 arr := Loo.LookupKeys("FACTOR");
//Get whether time series are found                 isFind := (Not isNULL(arr) And (arr.Length > 0));
//Display mnemonics of found time series in the console window                 For i := 0 To arr.Length - 1 Do
                    Debug.WriteLine(#9 + RubI.GetFactData(arr[i]).Mnemo);
                End For;
            End If;
        End If;
//If time series are not found, display corresponding message in the console window         If Not isFind Then
Debug.WriteLine(#9+"Time series are not found or found time series do not contain data");         End If;
    End If;
End Sub FactorsLookup;

See also:

Examples