Getting Date Range for Found Time Series

The example displays time series search in a time series database. All the time series containing the word mln are found. Then the information is obtained for these series: for which first and last year there is data.

Executing the example requires that the repository contains a time series database with the TSDB identifier containing custom time series attributes with the INDICATOR and CITY identifiers. These attributes are links to dictionaries.

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

Example

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

Sub FactorsLookup;
Var
    mb: IMetabase;
    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: Array Of Integer;
    i: Integer;
    Loo: IMetaDictionaryLookup;
    Cond: IOrmCondition;
    resV: Array Of Variant;
    min, max: DateTime;
    v: Variant;
    Members: IMetaDataMembers;
Begin
    // Get repository
    mb := MetabaseClass.Active;
    // Get instance of the TSDB time series database
    RubI := mb.ItemById("TSDB").Open(NullAs IRubricatorInstance;
    Rub := RubI.Rubricator;
    Debug.WriteLine("Search in time series database '" + (Rub As IMetabaseObject).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 string attribute values
    criteria.CriteriaOptions := TextCriteriaOptions.SearchStringAttributes Or TextCriteriaOptions.FreeText;
    // Set searched word
    criteria.Text := "mln";
    // Search among 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
//Transform array of found keys into array of the Variant type             resV := New Variant[res.Length];
            For i := 0 To res.Length - 1 Do
                resV[i] := res[i];
            End For;
//Create an object for time series search by specified attribute values             Loo := RubI.Values.CreateLookup;
//Specify that search is executed by the last actual revision             Loo.WhereRevisionKey := -1;
//Specify that time series must not be removed             Loo.WhereIsDeleted := TriState.OffOption;
//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 := resV;
//Get found time series             Loo.Open(DictionaryCursorOptions.None);
//Get data of found series             Members := Loo.Current.Record.Members;
//Get time series observation date             min := Members.FindById("DT").Value;
            max := min;
//Select minimum and maximum time series dates             While Not Loo.Eof Do
                Members := Loo.Current.Record.Members;
                v := Members.FindById("DT").Value;
                If v <= min Then
                    min := v
                Else
                    max := v > max ? v : max;
                End If;
                Loo.Next;
            End While;
//Close object for time series search             Loo.Close;
//Display results in the console window Debug.WriteLine("-minimum date:"+min.ToString); Debug.WriteLine("-maximum date:"+max.ToString);         End If;
    End If;
End Sub FactorsLookup;

See also:

Examples