CalendarDateFormatEx(Level: DimCalendarLevel): String;
Level. The calendar level, for which format is set.
The CalendarDateFormatEx property determines a date format for several levels of calendar dimension.
To specify date format for several level, consequently specify them using this property. For example, the code for specifying annual and quarterly frequency format:
Sub UserProc;
Var
Binding: ICubeMetaLoaderBinding;
Begin
//...
Binding.CalendarDateFormatEx(DimCalendarLevel.Year) := "$Year$";
Binding.CalendarDateFormatEx(DimCalendarLevel.Quarter) := "$Year$Q$Quarter$";
//...
End Sub UserProc;
Executing the example requires a time series database with the TSDB_IMPORT identifier containing mandatory attributes with the CITY and INDICATOR identifiers. These attributes must be links to the dictionary.
The file system must contain the D:\res_export.txt file containing data of several calendar frequencies.
Contents of the res_export.txt file
Add links to the Cubes, Db, Dimensions, Dt, Metabase, Rds system assemblies.
Sub UserProc;
Var
TextProvider: IDtTextProvider;
Mb: IMetabase;
TSDBObj: IMetabaseObject;
TSDB: IRubricator;
Attr: IMetaAttributes;
CrInfo: IMetabaseObjectCreateInfo;
Obj: IMetabaseObject;
ImportRequestDef: IImportRequestDefinition;
Params: IImportRequestProviderParams;
Bindings: ICubeMetaLoaderBindings;
Binding: ICubeMetaLoaderBinding;
DimM: IDimensionModel;
Instance: IImportRequestInstance;
ImportResult: IImportRequestResult;
Count, i: Integer;
Entry: ICubeMetaLoaderLogEntry;
Begin
// Create a data source for import from text file
TextProvider := New DtTextProvider.Create;
TextProvider.File := "D:\res_export.txt";
TextProvider.FormatType := DtTextFormatType.Delimited;
TextProvider.DelimitedColumnDelimiter := ";";
TextProvider.DelimitedTextQualifier := """";
TextProvider.Encoding := "WIN";
TextProvider.RangeHasHeader := True;
TextProvider.Open;
// Get time series database
Mb := MetabaseClass.Active;
TSDBObj := Mb.ItemById("TSDB_IMPORT").Bind;
TSDB := TSDBObj As IRubricator;
Attr := TSDB.Facts.Attributes;
// Create an import object
CrInfo := Mb.CreateCreateInfo;
CrInfo.ClassId := MetabaseObjectClass.KE_CLASS_IMPORTREQUEST;
CrInfo.Id := Mb.GenerateId("OBJ_IMPORTREQUEST_P", TSDBObj.Key);
CrInfo.Name := "Import object";
CrInfo.Parent := TSDBObj;
Obj := Mb.CreateObject(CrInfo).Edit;
// Specify data provider
ImportRequestDef := Obj As IImportRequestDefinition;
ImportRequestDef.SourceType := ImportRequestSourceType.Provider;
// Specify data consumer
ImportRequestDef.DestinationRubricator := TSDB;
// Set import options
Params := ImportRequestDef.ProviderParams;
Params.Provider := TextProvider As IDatasetDataProvider;
Params.NewRevisionName := "Time series import";
Params.ImportObjectKey := Obj.Key;
Params.LoadType := CubeMetaLoaderLoadType.CreateAndUpdate;
// Set attribute binding
Bindings := Params.Bindings;
// Set calendar binding
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Calendar;
Binding.ByColumns := False;
Binding.CalendarDateFormatEx(DimCalendarLevel.Year) := "$Year$";
Binding.CalendarDateFormatEx(DimCalendarLevel.Quarter) := "$Year$Q$Quarter$";
Binding.CalendarOptions.Levels := DimCalendarLevelSet.Year Or DimCalendarLevelSet.Quarter;
Binding.FieldType := CubeMetaLoaderFieldType.Name;
Binding.Field := "Year";
// Set binding of the Measurement Units (UNIT) attibute
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Unit;
Binding.FieldType := CubeMetaLoaderFieldType.ConstValue;
Binding.FieldValue := 1;
Binding.Attribute := "UNIT";
DimM := Attr.FindById("UNIT").ValuesObject.Bind As IDimensionModel;
Binding.Dimension := DimM;
Binding.Index := DimM.Indexes.Item(0).Id;
Binding.KeyAttribute := "KEY";
// Set binding of the Cities (CITY) attribute
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Attribute;
Binding.Attribute := "CITY";
Binding.FieldType := CubeMetaLoaderFieldType.Name;
Binding.Field := "CITY_KEY";
DimM := Attr.FindById("CITY").ValuesObject.Bind As IDimensionModel;
Binding.Dimension := DimM;
Binding.Index := DimM.Indexes.Item(0).Id;
Binding.KeyAttribute := "KEY";
Binding.NameAttribute := "NAME";
// Set binding of the Indicators (INDICATOR) attribute
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Attribute;
Binding.Attribute := "INDICATOR";
Binding.FieldType := CubeMetaLoaderFieldType.Name;
Binding.Field := "INDICATOR_KEY";
DimM := Attr.FindById("INDICATOR").ValuesObject.Bind As IDimensionModel;
Binding.Dimension := DimM;
Binding.Index := DimM.Indexes.Item(0).Id;
Binding.KeyAttribute := "KEY";
Binding.NameAttribute := "NAME";
// Set binding for import of values of series observations
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Value;
Binding.FieldType := CubeMetaLoaderFieldType.Name;
Binding.Field := "Value";
// Save changes in import object
Obj.Save;
// Execute data import
Instance := (ImportRequestDef As IMetabaseObject).Open(Null) As IImportRequestInstance;
Instance.LoadData;
// Get data import error log
ImportResult := Instance.ImportResult;
Count := importResult.Log.Count;
// Display log in the console window
For i := 0 To Count - 1 Do
Entry := ImportResult.Log.Item(i);
Debug.WriteLine(Entry.ErrorMessage);
If Entry.IsError Then
Debug.WriteLine(" (field = """ + Entry.Field + """, record = " +
Entry.RecordNumber.ToString + ")");
End If;
End For;
End Sub UserProc;
As a result of executing the example the data from the "D:\res_export.txt" file will be imported to the time series database.
See also: