TestLoad: ICubeMetaLoaderTestLoadResult;
The TestLoad method implements test loading of time series from data source and returns object that contains results.
During text loading data is checked, loaded data is not saved.
Executing the example requires a time series database with the OBJ_FC identifier and a time series export file C:\Fixed.xlsx. Also, MDM repository with the MDM_REPO identifier must be present in the repository. There should be dictionaries with the DICT_CTR, DICT_IND and UNITS identifiers in this repository. The COUNTRY attribute of the time series database refers to the DICT_CTR dictionary, the INDICATOR attribute is a link to the DICT_IND dictionary, and measurement units refer to the UNITS dictionary.
Add links to the Metabase, Cube, Dt, Db, Dimension system assemblies.
The C:\Fixed.xlsx file, for which the example is created
<font color="#008080">Sub</font><font color="#000000"> UserProc;<br /> </font><font color="#008080">Var</font><font color="#000000"><br /> Mb: IMetabase;<br /> NsiDescr: IMetabaseObjectDescriptor;<br /> CubeMetaLoader: ICubeMetaLoader;<br /> CrInfo: IMetabaseObjectCreateInfo;<br /> Obj: IMetabaseObject;<br /> ObjDesc: IMetabaseObjectDescriptor;<br /> CubeMetaLoaderBindings: ICubeMetaLoaderBindings;<br /> CalendarBinding: ICubeMetaLoaderBinding;<br /> CountryBinding: ICubeMetaLoaderBinding;<br /> IndicatorBinding: ICubeMetaLoaderBinding;<br /> UnitBinding: ICubeMetaLoaderBinding;<br /> ScaleBinding: ICubeMetaLoaderBinding;<br /> LevelBinding: ICubeMetaLoaderBinding;<br /> ValueBinding: ICubeMetaLoaderBinding;<br /> Parser: ICubeMetaLoaderBindingParser;<br /> Excel: IDtExcelProvider;<br /> Provider: IDatasetDataProvider;<br /> Log: ICubeMetaLoaderLog;<br /> Entry: ICubeMetaLoaderLogEntry;<br /> Count, i, key: Integer;<br /> TestResult: ICubeMetaLoaderTestLoadResult;<br /> TestResultEntry: ICubeMetaLoaderTestLoadResultEntry;<br /> </font><font color="#008080">Begin</font><font color="#000000"><br /> Mb := MetabaseClass.Active;<br /> NsiDescr := Mb.ItemById(</font><font color="#800000">"RDS_REPO"</font><font color="#000000">);<br /> </font><font color="#008000">// Create a loader<br /> </font><font color="#000000"> CrInfo := Mb.CreateCreateInfo;<br /> CrInfo.ClassId := MetabaseObjectClass.KE_CLASS_CUBEMETALOADER;<br /> CrInfo.Id := </font><font color="#800000">"CUBEMETALOADER"</font><font color="#000000">;<br /> CrInfo.Permanent := </font><font color="#008080">False</font><font color="#000000">;<br /> ObjDesc := Mb.CreateObject(CrInfo);<br /> Obj := ObjDesc.Edit;<br /> CubeMetaLoader := Obj </font><font color="#008080">As</font><font color="#000000"> ICubeMetaLoader;<br /> CubeMetaLoader.LoadType := CubeMetaLoaderLoadType.CreateAndUpdate;<br /> CubeMetaLoader.Rubricator := Mb.ItemById(</font><font color="#800000">"OBJ_FC"</font><font color="#000000">).Bind </font><font color="#008080">As</font><font color="#000000"> IRubricator;<br /> CubeMetaLoader.ScaleValues := </font><font color="#008080">True</font><font color="#000000">;<br /> CubeMetaLoaderBindings := CubeMetaLoader.Bindings;<br /> </font><font color="#008000">// Edit calendar parameters<br /> </font><font color="#000000"> CalendarBinding := CubeMetaLoaderBindings.Add;<br /> CalendarBinding.BindingType := CubeMetaLoaderBindingType.Calendar;<br /> CalendarBinding.CalendarOptions.Levels := DimCalendarLevelSet.Year;<br /> CalendarBinding.ByColumns := </font><font color="#008080">False</font><font color="#000000">;<br /> CalendarBinding.CalendarDateFormat := </font><font color="#800000">"$Year$"</font><font color="#000000">;<br /> CalendarBinding.FieldType := CubeMetaLoaderFieldType.Name;<br /> CalendarBinding.Field := </font><font color="#800000">"Year"</font><font color="#000000">;<br /> Parser := CalendarBinding.Parser;<br /> Parser.ParserType := CubeMetaLoaderParserType.FixedPosition;<br /> Parser.StringPositionStart := </font><font color="#008000">2</font><font color="#000000">;<br /> Parser.StringPositionEnd := -</font><font color="#008000">1</font><font color="#000000">;<br /> </font><font color="#008000">// Edit the INDICATOR attribute parameters<br /> </font><font color="#000000"> IndicatorBinding := CubeMetaLoaderBindings.Add;<br /> IndicatorBinding.BindingType := CubeMetaLoaderBindingType.Attribute;<br /> IndicatorBinding.Attribute := </font><font color="#800000">"INDICATOR"</font><font color="#000000">;<br /> IndicatorBinding.Field := </font><font color="#800000">"Indicator Code"</font><font color="#000000">;<br /> IndicatorBinding.FieldType := CubeMetaLoaderFieldType.Name;<br /> IndicatorBinding.Dimension := Mb.ItemByIdNamespace(</font><font color="#800000">"DICT_IND"</font><font color="#000000">, NsiDescr.Key).Bind<br /> </font><font color="#008080">As</font><font color="#000000"> IDimensionModel;<br /> </font><font color="#008000">// «IX_CODE» - unique key of the DICT_IND dictionary<br /> </font><font color="#000000"> IndicatorBinding.Index := </font><font color="#800000">"IX_CODE"</font><font color="#000000">;<br /> IndicatorBinding.KeyAttribute := </font><font color="#800000">"KEY"</font><font color="#000000">;<br /> Parser := IndicatorBinding.Parser;<br /> Parser.ParserType := CubeMetaLoaderParserType.FixedPosition;<br /> Parser.StringPositionStart := </font><font color="#008000">2</font><font color="#000000">;<br /> Parser.StringPositionEnd := </font><font color="#008000">7</font><font color="#000000">;<br /> </font><font color="#008000">// Edit parameters of the COUNTRY attribute<br /> </font><font color="#000000"> CountryBinding := CubeMetaLoaderBindings.Add;<br /> CountryBinding.BindingType := CubeMetaLoaderBindingType.Attribute;<br /> CountryBinding.Attribute := </font><font color="#800000">"COUNTRY"</font><font color="#000000">;<br /> CountryBinding.Field := </font><font color="#800000">"Country Code"</font><font color="#000000">;<br /> CountryBinding.FieldType := CubeMetaLoaderFieldType.Name;<br /> CountryBinding.Dimension := Mb.ItemByIdNamespace(</font><font color="#800000">"DICT_CTR"</font><font color="#000000">, NsiDescr.Key).Bind </font><font color="#008080">As</font><font color="#000000"><br /> IDimensionModel;<br /> </font><font color="#008000">// IX_WEO - dictionary unique key DICT_CTR<br /> </font><font color="#000000"> CountryBinding.Index := </font><font color="#800000">"IX_WEO"</font><font color="#000000">;<br /> CountryBinding.KeyAttribute := </font><font color="#800000">"KEY"</font><font color="#000000">;<br /> CountryBinding.NameAttribute := </font><font color="#800000">"NAME"</font><font color="#000000">;<br /> Parser := CountryBinding.Parser;<br /> Parser.ParserType := CubeMetaLoaderParserType.FixedPosition;<br /> Parser.StringPositionStart := </font><font color="#008000">3</font><font color="#000000">;<br /> Parser.StringPositionEnd := </font><font color="#008000">5</font><font color="#000000">;<br /> </font><font color="#008000">// Edit attributes of calendar and measurement units<br /> </font><font color="#000000"> LevelBinding := CubeMetaLoaderBindings.Add;<br /> LevelBinding.BindingType := CubeMetaLoaderBindingType.Attribute;<br /> LevelBinding.Attribute := </font><font color="#800000">"DL"</font><font color="#000000">;<br /> LevelBinding.FieldType := CubeMetaLoaderFieldType.ConstValue;<br /> LevelBinding.FieldValue := DimCalendarLevel.Year </font><font color="#008080">As</font><font color="#000000"> Integer;<br /> UnitBinding := CubeMetaLoaderBindings.Add;<br /> UnitBinding.BindingType := CubeMetaLoaderBindingType.Unit;<br /> UnitBinding.Field := </font><font color="#800000">"Units"</font><font color="#000000">;<br /> UnitBinding.FieldType := CubeMetaLoaderFieldType.Name;<br /> Parser := UnitBinding.Parser;<br /> Parser.ParserType := CubeMetaLoaderParserType.FixedPosition;<br /> Parser.StringPositionStart := </font><font color="#008000">0</font><font color="#000000">;<br /> Parser.StringPositionEnd := -</font><font color="#008000">1</font><font color="#000000">;<br /> ScaleBinding := CubeMetaLoaderBindings.Add;<br /> ScaleBinding.BindingType := CubeMetaLoaderBindingType.Unit;<br /> ScaleBinding.Field := </font><font color="#800000">"Scale"</font><font color="#000000">;<br /> ScaleBinding.FieldType := CubeMetaLoaderFieldType.Name;<br /> ScaleBinding.Dimension := Mb.ItemByIdNamespace(</font><font color="#800000">"UNITS"</font><font color="#000000">, NsiDescr.Key).Bind </font><font color="#008080">As</font><font color="#000000"> IDimensionModel;<br /> </font><font color="#008000">// «IX_WEO_UNIT_SCALE» - unique key of the UNITS dictionary<br /> </font><font color="#000000"> ScaleBinding.Index := </font><font color="#800000">"IX_WEO_UNIT_SCALE"</font><font color="#000000">;<br /> ScaleBinding.KeyAttribute := </font><font color="#800000">"KEY"</font><font color="#000000">;<br /> Parser := ScaleBinding.Parser;<br /> Parser.ParserType := CubeMetaLoaderParserType.FixedPosition;<br /> Parser.StringPositionStart := </font><font color="#008000">0</font><font color="#000000">;<br /> Parser.StringPositionEnd := -</font><font color="#008000">1</font><font color="#000000">;<br /> </font><font color="#008000">// Edit attributes containing values<br /> </font><font color="#000000"> ValueBinding := CubeMetaLoaderBindings.Add;<br /> ValueBinding.BindingType := CubeMetaLoaderBindingType.Value;<br /> ValueBinding.Field := </font><font color="#800000">"Value"</font><font color="#000000">;<br /> ValueBinding.FieldType := CubeMetaLoaderFieldType.Name;<br /> Parser := ValueBinding.Parser;<br /> Parser.ParserType := CubeMetaLoaderParserType.FixedPosition;<br /> Parser.StringPositionStart := </font><font color="#008000">0</font><font color="#000000">;<br /> Parser.StringPositionEnd := -</font><font color="#008000">1</font><font color="#000000">;<br /> </font><font color="#008000">// Edit loader parameters<br /> </font><font color="#000000"> Excel := </font><font color="#008080">New</font><font color="#000000"> DtExcelProvider.Create;<br /> Excel.ImexMode := DtExcelImexMode.Import;<br /> Excel.File := </font><font color="#800000">"C:\Fixed.xlsx"</font><font color="#000000">;<br /> Excel.Query := </font><font color="#800000">"SELECT * FROM [Sheet1$]"</font><font color="#000000">;<br /> Excel.HasHeader := </font><font color="#008080">True</font><font color="#000000">;<br /> Excel.CheckFieldName := </font><font color="#008080">True</font><font color="#000000">;<br /> Excel.Open;<br /> Provider := Excel </font><font color="#008080">As</font><font color="#000000"> IDatasetDataProvider;<br /> </font><font color="#008000">// Load<br /> </font><font color="#000000"> CubeMetaLoader.Data := Provider;<br /> TestResult := CubeMetaLoader.TestLoad;<br /> Count := TestResult.Count;<br /> Debug.WriteLine(</font><font color="#800000">"Test"</font><font color="#000000">);<br /> Debug.WriteLine(</font><font color="#800000">"Total errors in log: "</font><font color="#000000"> + Count.ToString);<br /> </font><font color="#008080">If</font><font color="#000000"> Count > </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">Then</font><font color="#000000"><br /> </font><font color="#008080">For</font><font color="#000000"> i := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> Count - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br /> TestResultEntry := TestResult.Item(i);<br /> Debug.WriteLine(TestResultEntry.Attribute + </font><font color="#800000">" : "</font><font color="#000000"><br /> + TestResultEntry.Value + </font><font color="#800000">" = "</font><font color="#000000"><br /> + TestResultEntry.Count.ToString);<br /> </font><font color="#008080">If</font><font color="#000000"> i >= </font><font color="#008000">10</font><font color="#000000"> - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Then</font><font color="#000000"><br /> </font><font color="#008080">Break</font><font color="#000000">;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br /> </font><font color="#008080">Else</font><font color="#000000"><br /> CubeMetaLoader.Data := Provider;<br /> CubeMetaLoader.LoadData;<br /> Log := CubeMetaLoader.Log;<br /> </font><font color="#008080">For</font><font color="#000000"> </font><font color="#008080">Each</font><font color="#000000"> key </font><font color="#008080">In</font><font color="#000000"> CubeMetaLoader.InvalidFactors </font><font color="#008080">Do</font><font color="#000000"><br /> Debug.WriteLine(</font><font color="#800000">"Error on loading factor with key: "</font><font color="#000000"> + key.ToString);<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br /> Count := Log.Count;<br /> Debug.WriteLine(</font><font color="#800000">"Data loading"</font><font color="#000000">);<br /> Debug.WriteLine(</font><font color="#800000">"Total records in log: "</font><font color="#000000"> + Count.ToString);<br /> </font><font color="#008080">For</font><font color="#000000"> i := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> Count - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br /> Entry := Log.Item(i);<br /> Debug.WriteLine(i.ToString + </font><font color="#800000">" : "</font><font color="#000000"><br /> + Entry.DateBegin.ToString + </font><font color="#800000">","</font><font color="#000000"><br /> + Entry.RecordNumber.ToString + </font><font color="#800000">","</font><font color="#000000"><br /> + Entry.Field + </font><font color="#800000">","</font><font color="#000000"><br /> + Entry.ErrorMessage);<br /> </font><font color="#008080">If</font><font color="#000000"> i >= </font><font color="#008000">10</font><font color="#000000"> - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Then</font><font color="#000000"><br /> </font><font color="#008080">Break</font><font color="#000000">;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">Sub</font><font color="#000000"> UserProc;</font>
After executing the example test data loading from the file C:\Fixed.xlsx is executed, the first ten records from report on loading are displayed in the console window. If the test loading is successful, the factors are exported from file to the time series database.
See also: