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.
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(Null) As 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 <> 0) Then
//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;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Express;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Orm;
Imports Prognoz.Platform.Interop.Pivot;
Imports Prognoz.Platform.Interop.Rds;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
Eax: IEaxAnalyzer;
Cube: ICubeInstance;
RubI: IRubricatorInstance;
Rub: IRubricator;
DictionaryInstance: IMetaDictionaryInstance;
resSelSet, SelectionSet: IDimSelectionSet;
factLookup: IRubricatorFactsLookup;
criteria: DimTextCriteria;
factory: IDimSelectionSetFactory;
selection: IDimSelection;
attributes: IMetaAttributes;
attr: IMetaAttribute;
id: string;
IsSelectionSetEmpty: Boolean;
res, Arr: System.Array;
i: Integer;
isFind: Boolean = False;
Loo: IMetaDictionaryLookup;
Cond: IOrmCondition;
key: uinteger;
Begin
//Get repository mb := Params.Metabase;
//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;
System.Diagnostics.Debug.WriteLine("Search in time series database'"+(RubAsIMetabaseObject).Name+"':"); //Get time series dictionary DictionaryInstance := RubI.GetDictionary(RubricatorDictionary.rubdicFacts);
//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.tecropSearchStringAttributes Or TextCriteriaOptions.tecropFreeText;
//Set searched word criteria.Text := "mln";
//Search among the elements selected in time series database dimensions criteria.SelectOptions := ConditionSelectOptions.coseopSelectedOnly;
//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(Null) As 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 (res <> Null) And (res.Length <> 0) Then
//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 As uinteger;
//Specify that time series must not be removed Loo.WhereIsDeleted := TriState.tsOffOption;
//Specify that time series must contain data Cond := Loo.Where.Add();
Cond.AttributeName := "VL";
Cond.Operator := OrmComparisonOperator.ocoIsNotNull;
//Limit search by the time series containing the text "mln" in the name Cond := Loo.Where.Add();
Cond.AttributeName := "FACTOR";
Cond.Operator := OrmComparisonOperator.ocoIn;
//Cond.Value := arr2;
Cond.Value := res;
//Get keys of found time series arr := Loo.LookupKeys("FACTOR");
//Get whether time series are found isFind := ((arr <> Null) And (arr.Length > 0));
//Display mnemonics of found time series in the console window For i := 0 To arr.Length - 1 Do
key := integer.Parse(arr[i].ToString()) As uinteger;
System.Diagnostics.Debug.WriteLine(char.ConvertFromUtf32(9) +
RubI.GetFactData(key, DictionaryGetDataOptions.dgdoNone).Mnemo);
End For;
End If;
End If;
//If time series are not found, display corresponding message in the console window If Not isFind Then
System.Diagnostics.Debug.WriteLine(char.ConvertFromUtf32(9) +
"Time series are not found or found time series do not contain data"); End If;
End If;
End Sub;
See also: