Input: IMsFormulaTermInfo;
Input: Prognoz.Platform.Interop.Ms.IMsFormulaTermInfo;
The Input property determines the term corresponding to input variable.
For source frequency use the IMsCollapseTransform.InputLevel property.
Executing the example requires that the repository contains a modeling container with the MS identifier. This modeling container must contain a model with the MODEL_COLLAPSE_VECT identifier calculated by the Collapse (Series Calculation) method. It is also required to have a time series database with the TSDB identifier containing annual and monthly frequencies.
Add links to the Cubes, Dimensions, Metabase, Ms, Stat system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsKey: Integer;
Model: IMsModel;
Stub: IVariableStub;
Tree: IMsFormulaTransformSlicesTree;
RubrDescr: IMetabaseObjectDescriptor;
Transform: IMsFormulaTransform;
TransformVarables: IMsFormulaTransformVariables;
TransformVar: IMsFormulaTransformVariable;
Coord: IMsFormulaTransformCoord;
Slice: IMsFormulaTransformSlice;
Collapse: IMsCollapseTransform;
TermInfo: IMsFormulaTermInfo;
Calcul: IMsMethodCalculation;
arr: Array Of double;
i: Integer;
Period: IMsModelPeriod;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modeling container key
MsKey := mb.GetObjectKeyById("MS");
// Get model
Model := mb.ItemByIdNamespace("MODEL_COLLAPSE_VECT", MsKey).Edit As IMsModel;
// Get object for setting up model parameters
Transform := Model.Transform;
// Get collection of output variables
TransformVarables := Transform.Outputs;
// Get the first output variable
TransformVar := TransformVarables.Item(0);
// Create output variable calculation parameters
Coord := Transform.CreateCoord(TransformVar);
// Get calculation parameters of the Collapse method
Collapse := Transform.FormulaItem(0).Method As IMsCollapseTransform;
// Get time series database (TSDB)
RubrDescr := Mb.ItemById("TSDB");
// Cast obtained TSDB to abstract data source
Stub := RubrDescr.Bind As IVariableStub;
// Add a factor to model, which data source is TSDB
TransformVar := Transform.Inputs.Add(Stub);
Tree := TransformVar.SlicesTree(TransformVar);
Slice := Tree.CreateSlice(2);
// Get factor as a term
TermInfo := Transform.CreateTermInfo;
TermInfo.Slice := Slice;
// Specify obtained term as input variable
Collapse.Input := TermInfo;
// Specify original frequency
Collapse.InputLevel := DimCalendarLevel.Month;
// Set collapse type
Collapse.MethodType := MsCollapseType.Average;
// Specify missing data treatment method
Collapse.MissingData.Method := MissingDataMethod.LinTrend;
// Set the number of missing values in output series,
// which can be considered sufficient for aggregation
Collapse.Tolerance := 5;
// Create an object with model calculation parameters
Calcul := Transform.CreateCalculation;
// Set calculation periods
Period := Model.Transform.Period;
Calcul.Period.IdentificationStartDate := Period.IdentificationStartDate;
Calcul.Period.IdentificationEndDate := Period.IdentificationEndDate;
Calcul.Period.ForecastStartDate := Period.ForecastStartDate;
Calcul.Period.ForecastEndDate := Period.ForecastEndDate;
Calcul.CurrentPoint := Period.IdentificationStartDate;
// Get output model data
arr := Collapse.CalculateSeries(Calcul, Coord).Modelling;
// Output name and data of output variable in the console window
Debug.WriteLine(Collapse.Result.TermInfo.TermText);
For i := 0 To arr.Length - 1 Do
Debug.WriteLine(arr[i]);
End For;
// Save changes in model
(Model As IMetabaseObject).Save;
End Sub UserProc;
After executing the example calculation settings for the MODEL_COLLAPSE_VECT model are changed: output variable, collapse calculation method and so on are changed. Calculation results are displayed in the console window.
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.Dimensions;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsKey: uinteger;
Model: IMsModel;
Stub: IVariableStub;
Tree: IMsFormulaTransformSlicesTree;
RubrDescr: IMetabaseObjectDescriptor;
Transform: IMsFormulaTransform;
TransformVarables: IMsFormulaTransformVariables;
TransformVar: IMsFormulaTransformVariable;
Coord: IMsFormulaTransformCoord;
Slice: IMsFormulaTransformSlice;
Collapse: IMsCollapseTransform;
TermInfo: IMsFormulaTermInfo;
Calcul: IMsMethodCalculation;
arr: System.Array;
i: Integer;
Period: IMsModelPeriod;
Begin
// Get current repository
mb := Params.Metabase;
// Get modeling container key
MsKey := mb.GetObjectKeyById("MS");
// Get model
Model := mb.ItemByIdNamespace["MODEL_COLLAPSE_VECT", MsKey].Edit() As IMsModel;
// Get object to set up model parameters
Transform := Model.Transform;
// Get output variables collection
TransformVarables := Transform.Outputs;
// Get the first output variable
TransformVar := TransformVarables.Item[0];
// Create calculation parameters of output variable
Coord := Transform.CreateCoord(TransformVar);
// Get calculation parameters of the Collapse method
Collapse := Transform.FormulaItem[0].Method As IMsCollapseTransform;
// Get time series database (TSDB)
RubrDescr := Mb.ItemById["TSDB"];
// Cast obtained TSDB to abstract data source
Stub := RubrDescr.Bind() As IVariableStub;
// Add factor with the TSDB data source to model
TransformVar := Transform.Inputs.Add(Stub);
Tree := TransformVar.SlicesTree[TransformVar];
Slice := Tree.CreateSlice(2);
// Get factor as a term
TermInfo := Transform.CreateTermInfo();
TermInfo.Slice := Slice;
// Specify obtained term as an input variable
Collapse.Input := TermInfo;
// Specify original frequency
Collapse.InputLevel := DimCalendarLevel.dclMonth;
// Set collapse type
Collapse.MethodType := MsCollapseType.mctAverage;
// Specify missing data treatment method
Collapse.MissingData.Method := MissingDataMethod.mdmLinTrend;
// Set the number of missing values in output series,
// which can be considered sufficient for aggregation
Collapse.Tolerance := 5;
// Create an object with model calculation parameters
Calcul := Transform.CreateCalculation();
// Set calculation periods
Period := Model.Transform.Period;
Calcul.Period.IdentificationStartDate := Period.IdentificationStartDate;
Calcul.Period.IdentificationEndDate := Period.IdentificationEndDate;
Calcul.Period.ForecastStartDate := Period.ForecastStartDate;
Calcul.Period.ForecastEndDate := Period.ForecastEndDate;
Calcul.CurrentPoint := Period.IdentificationStartDate;
// Get output variable data
arr := Collapse.CalculateSeries[Calcul, Coord].Modelling;
// Output name and data of output variable in the console window
System.Diagnostics.Debug.WriteLine(Collapse.Result.TermInfo.TermText);
For i := 0 To arr.Length - 1 Do
System.Diagnostics.Debug.WriteLine(arr[i]);
End For;
// Save changes in model
(Model As IMetabaseObject).Save();
End Sub;
See also: