CalculationType: TsCalculationType;
The CalculationType property returns the custom method calculation mode.
If the pointwise calculation is used, that is, CalculationType = TsCalculationType.Pointwise, the custom method is executed for each series observation. If the series calculation is used, that is, CalculationType = TsCalculationType.Series, the method is executed for the entire series.
This example displays a custom calculation method. To execute the example, add links to the Metabase, Ms, Transform system assemblies.
Public Function CalculateSomething: Variant;
Var
pContext: ITsCalculationContext;
i: Integer;
pSeries: ITimeSeries;
Begin
pContext := TsCalculation.Current;
pContext.Tag := pContext.ParentObject.Name;
pSeries := pContext.CreateTimeSeries;
If pContext.CalculationType = TsCalculationType.Series Then
pContext.RaiseMessage("Series mode");
If pSeries.CalcPointCount < 25 Then
If pSeries.CalcPointCount < 15 Then
pContext.RaiseError("Number of observations is insufficient. Calculation cannot be executed");
Else
pContext.RaiseWarning("Number of observations is small. Unreliable data may be received");
End If;
End If;
For i := pSeries.StartIndex To pSeries.EndIndex Do
pSeries.Item(i) := 1 / i;
End For;
Return pSeries;
Else
If pContext.CalculationDirection = TsCalculationDirection.Forward Then
pContext.RaiseMessage(Pointwise mode (forward));
Else
pContext.RaiseMessage(Pointwise mode (backward));
End If;
If pSeries.CalcPointCount < 25 Then
If pSeries.CalcPointCount < 15 Then
pContext.RaiseError("Number of observations is insufficient. Calculation cannot be executed");
Else
pContext.RaiseWarning("Number of observations is small. Unreliable data may be received");
End If;
End If;
i := pSeries.CurrentIndex;
pSeries.Item(i) := 1 / i;
Return pSeries.Item(i);
End If;
End Function CalculateSomething;
The method calculates values on the basis of observation index. The method works both in series and pointwise modes. The calculation mode is displayed in the message. If the number of observations is less than 25, the warning is displayed. If the number of observations is less than 15, the error is displayed and the method is not calculated.
See also: