CalendarDateFormatEx(Level: DimCalendarLevel): String;
CalendarDateFormatEx[Level: Prognoz.Platform.Interop.Dimensions.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 to 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;
// Determine data source
ImportRequestDef := Obj As IImportRequestDefinition;
ImportRequestDef.SourceType := ImportRequestSourceType.irstProvider;
// Determine data consumer
ImportRequestDef.DestinationRubricator := TSDB;
// Determine import parameters
Params := ImportRequestDef.ProviderParams;
Params.Provider := TextProvider As IDatasetDataProvider;
Params.NewRevisionName := "Times series import";
Params.ImportObjectKey := Obj.Key;
Params.LoadType := CubeMetaLoaderLoadType.CreateAndUpdate;
// Determine attribute binding
Bindings := Params.Bindings;
// Determine 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";
// Determine binding of the Measurement Units (UNIT) attribute
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";
// Determine 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";
// Determine 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";
// Determine binding to import series observation values
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Value;
Binding.FieldType := CubeMetaLoaderFieldType.Name;
Binding.Field := "Value";
// Save changes in the import object
Obj.Save;
// Import data
Instance := (ImportRequestDef As IMetabaseObject).Open(Null) As IImportRequestInstance;
Instance.LoadData();
// Get error log of data import
ImportResult := Instance.ImportResult;
Count := importResult.Log.Count;
// Display log to console dialog box
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.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.Rds;
Public Shared Sub Main(Params: StartParams);
Var
TextProvider: IDtTextProvider;
Mb: IMetabase;
TSDBObj: IMetabaseObject;
TSDB: IRubricator;
Attr: IMetaAttributes;
CrInfo: IMetabaseObjectCreateInfo;
Obj: IMetabaseObject;
ImportRequestDef: IImportRequestDefinition;
ImpParams: 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.tftDelimited;
TextProvider.DelimitedColumnDelimiter := ";";
TextProvider.DelimitedTextQualifier := """";
TextProvider.Encoding := "WIN";
TextProvider.RangeHasHeader := True;
TextProvider.Open();
// Get time series database
Mb := Params.Metabase;
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 As integer;
CrInfo.Id := Mb.GenerateId("OBJ_IMPORTREQUEST_P", TSDBObj.Key);
CrInfo.Name := "Import object";
CrInfo.Parent := TSDBObj;
Obj := Mb.CreateObject(CrInfo).Edit();
// Determine data source
ImportRequestDef := Obj As IImportRequestDefinition;
ImportRequestDef.SourceType := ImportRequestSourceType.irstProvider;
// Determine data consumer
ImportRequestDef.DestinationRubricator := TSDB;
// Determine import parameters
ImpParams := ImportRequestDef.ProviderParams;
ImpParams.Provider := TextProvider As IDatasetDataProvider;
ImpParams.NewRevisionName := "Time series import";
ImpParams.ImportObjectKey := Obj.Key;
ImpParams.LoadType := CubeMetaLoaderLoadType.cmlltCreateAndUpdate;
// Set attribute binding
Bindings := ImpParams.Bindings;
// Determine calendar binding
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtCalendar;
Binding.ByColumns := False;
Binding.CalendarDateFormatEx[DimCalendarLevel.dclYear] := "$Year$";
Binding.CalendarDateFormatEx[DimCalendarLevel.dclQuarter] := "$Year$Q$Quarter$";
Binding.CalendarOptions.Levels := DimCalendarLevelSet.dclsYear Or DimCalendarLevelSet.dclsQuarter;
Binding.FieldType := CubeMetaLoaderFieldType.cmlftName;
Binding.Field := "Year";
// Determine binding of the Measurement Unit (UNIT) attribute
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtUnit;
Binding.FieldType := CubeMetaLoaderFieldType.cmlftConstValue;
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";
// Determine binding of the Cities attribute (CITY)
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtAttribute;
Binding.Attribute := "CITY";
Binding.FieldType := CubeMetaLoaderFieldType.cmlftName;
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";
// Determine binding of the Indicators attributes (INDICATOR)
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtAttribute;
Binding.Attribute := "INDICATOR";
Binding.FieldType := CubeMetaLoaderFieldType.cmlftName;
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";
// Determine binding to import values of series observations
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtValue;
Binding.FieldType := CubeMetaLoaderFieldType.cmlftName;
Binding.Field := "Value";
// Save changes to the import object
Obj.Save();
// Data import
Instance := (ImportRequestDef As IMetabaseObject).Open(Null) As IImportRequestInstance;
Instance.LoadData();
// Get error log of data import
ImportResult := Instance.ImportResult;
Count := importResult.Log.Count;
// Display log to console dialog box
For i := 0 To Count - 1 Do
Entry := ImportResult.Log.Item[i];
System.Diagnostics.Debug.WriteLine(Entry.ErrorMessage);
If Entry.IsError Then
System.Diagnostics.Debug.WriteLine(" (field = """ + Entry.Field + """, record = " +
Entry.RecordNumber.ToString() + ")");
End If;
End For;
End Sub;
See also: