Execute(
Calculation: IMsMethodCalculation;
Coord: IMsFormulaTransformCoord;
Explained: IMsFormulaTerm;
Explanatories: IMsFormulaTermList);
Calculation. Settings required for model calculation.
Coord. Dimension by which calculation is executed.
Explained. Output series.
Explanatories. Collection of terms used as modelling factors.
The Execute method calculates the model using the user algorithm. This method must be predetermined in the user class.
Public Class My_Method: Object, IMsUserTransformImplementation
Param1, Param2: Double;
Sub Execute(Calculation: IMsMethodCalculation; Coo: IMsFormulaTransformCoord; Explained: IMsFormulaTerm; Explanatories: IMsFormulaTermList);
Var
Matr: IMatrix;
Mcoo: IMatrixCoord;
Cub: ICubeInstance;
i: Integer;
Term: IMsFormulaTerm;
ModelAr, FactorAr: Array Of Double;
Period: IMsModelPeriod;
Begin
//Getting the variables matrix, where the calculated data is saved
Matr := Calculation.Variable(Explained.Slice.Variable.VariableStub);
Mcoo := Matr.CreateCoord;
Matr.ValueFlag := Matr.ValueFlag + 1;
ModelAr := Explained.Serie(Calculation);
Period := Calculation.Period;
//Calculation
If Explanatories.Count <> 0 Then
Term := Explanatories.Item(0);
FactorAr := Term.Serie(Calculation);
For i := 0 To Period.ForecastEndDate.Year - Period.IdentificationStartDate.Year Do
MCoo.Item(0) := i;
MCoo.Item(1) := 1;
If Double.IsNan(ModelAr[i]) Then
Matr.Item(Mcoo) := (FactorAr[i] + (FactorAr[i - 1] + FactorAr[i - 2])) * Param1 / Param2;
Else
Matr.Item(Mcoo) := (ModelAr[i] + FactorAr[i]) * Param1 / Param2;
End If;
Calculation.CurrentPoint := DateTime.AddYears(Calculation.CurrentPoint, 1);
End For;
Else
For i := 0 To Period.ForecastEndDate.Year - Period.IdentificationStartDate.Year Do
MCoo.Item(0) := i;
MCoo.Item(1) := 1;
Matr.Item(Mcoo) := Math.RandBetween(0, 100) * Param1 / Param2;
End For;
End If;
//Saving data to the variable
Cub := ((Explained.Slice.Variable.VariableStub As IMsVariable).Cube As IMetabaseObject).Open(Null) As ICubeInstance;
Cub.Destinations.DefaultDestination.CreateStorage.SaveMatrix(Matr, Matr.ValueFlag);
End Sub Execute;
Sub Set_params(ParamValue: IMsUserMethodParams);
Begin
Param1 := ParamValue.Item(0).Value As Double;
Param2 := ParamValue.Item(1).Value As Double;
End Sub Set_params;
End Class My_Method;
This example is a macro that contains a user method of model calculation. On calculating the model that is set up to use the custom method, the data based on some dependency between the output series and the model factor is calculated. After the calculation is performed the data is saved to the output variable.
See also: