Collapse(Input: ITimeSeries;
Method: MsCollapseType;
TargetFrequency: MsFrequency;
[MissingData: MissingDataMethod =16;]
[NumberOfPoints: Integer = 1;]
[SpecifiedValue: Double = 0;]
[AdditionalSeries: ITimeSeries = Null]): Variant;
Collapse(Input: Prognoz.Platform.Interop.Ms.ITimeSeries;
Method: Prognoz.Platform.Interop.Ms.MsCollapseType;
TargetFrequency: Prognoz.Platform.Interop.Ms.MsFrequency;
Context: Prognoz.Platform.Interop.Fore.ForeRuntimeContext;
MissingData: Prognoz.Platform.Interop.Stat.MissingDataMethod;
NumberOfPoints: integer;
SpecifiedValue: double;
AdditionalSeries: Prognoz.Platform.Interop.Ms.ITimeSeries): object;
Input. Input variable.
Method. Aggregation method.
TargetFrequency. Output frequency.
Context. Context. The parameter is used only in Fore.NET.
MissingData. Missing data treatment method.
NumberOfPoints. Additional parameter for missing data treatment method. It can take only positive values. It is used for the following missing data treatment methods:
• MissingDataMethod.NPointsAverage. N-Point Average. The parameter determines the number of neighbor points.
• PreviousGrowthRate, SucceedingGrowthRate. Previous Growth Rate, Succeeding Growth Rate. The parameter determines the number of periods.
SpecifiedValue. The value, with which missing data is substituted by the MissingDataMethod.SpecifiedValue Value method.
AdditionalSeries. The series that is used to substitute missing data by the MissingDataMethod.Pattern Pattern and MissingDataMethod.Overlay Overlay methods.
The Collapse method aggregates variable values.
This method aggregates data from the lower level to the higher level; it is used to calculate problems that require data aggregation. For example, data calculated by months must be summed for quarterly frequency.
On data aggregation, the following calendar frequency settings are taken into account: start period offset relative to its start/end.
Example of data aggregation from daily to weekly frequency
Executing the example requires that the repository contains a modeling container with the MS identifier. This container contains a model with the MODEL_D_Q identifier and quarterly frequency, that is calculated using a determinate equation and includes at least one factor.
Add links to the Metabase, Ms system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
ModelSpace, ModelObj: IMetabaseObject;
Transf: IMsFormulaTransform;
Formula: IMsFormula;
Model: IMsModel;
Determ: IMsDeterministicTransform;
TransVar: IMsFormulaTransformVariable;
Slice: IMsFormulaTransformSlice;
TermInfo: IMsFormulaTermInfo;
Expr: IExpression;
Begin
// Get current repository
Mb := MetabaseClass.Active;
// Get modeling container
ModelSpace := Mb.ItemById("MS").Bind;
// Get model
ModelObj := Mb.ItemByIdNamespace("MODEL_D_Q", ModelSpace.Key).Edit;
Model := ModelObj As IMsModel;
// Get model parameters
Transf := Model.Transform;
// Get model calculation method
Formula := Transf.FormulaItem(0);
Determ := Formula.Method As IMsDeterministicTransform;
// Get first factor of model
TransVar := Transf.Inputs.Item(0);
// Get slice, corresponding to factor
Slice := TransVar.Slices.Item(0);
// Create tern based on the first factor
TermInfo := Transf.CreateTermInfo;
TermInfo.Slice := Slice;
// Get expression for model calculation
Expr := Determ.Expression;
// Set expression for model calculation
Expr.AsString := "Collapse(" + TermInfo.TermInnerText + ", MsCollapseType.Total, " +
"MsFrequency.Annual, MissingDataMethod.NPointsAverage, 4)";
// Check expression correctness
If Expr.Valid
// If expression is correct, save changes
Then ModelObj.Save;
// If expression is incorrect, output message to console window
Else Debug.WriteLine("Model is not saved: error in formula");
End If;
End Sub UserProc;
After executing the example the model aggregates data of the first input variable with quarterly frequency for annual one with missing data treatment by means of the N-Point Average method where N = 4.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
ModelSpace, ModelObj: IMetabaseObject;
Transf: IMsFormulaTransform;
Formula: IMsFormula;
Model: IMsModel;
Determ: IMsDeterministicTransform;
TransVar: IMsFormulaTransformVariable;
Slice: IMsFormulaTransformSlice;
TermInfo: IMsFormulaTermInfo;
Expr: IExpression;
Begin
// Get current repository
Mb := Params.Metabase;
// Get modeling container
ModelSpace := Mb.ItemById["MS"].Bind();
// Get model
ModelObj := Mb.ItemByIdNamespace["MODEL_D_Q", ModelSpace.Key].Edit();
Model := ModelObj As IMsModel;
// Get model parameters
Transf := Model.Transform;
// Get model calculation method
Formula := Transf.FormulaItem[0];
Determ := Formula.Method As IMsDeterministicTransform;
// Get first factor of model
TransVar := Transf.Inputs.Item[0];
// Get slice, corresponding to factor
Slice := TransVar.Slices.Item[0];
// Create term based on the first factor
TermInfo := Transf.CreateTermInfo();
TermInfo.Slice := Slice;
// Get expression for model calculation
Expr := Determ.Expression;
// Set expression for model calculation
Expr.AsString := "Collapse(" + TermInfo.TermInnerText + ", MsCollapseType.Total, " +
"MsFrequency.Annual, MissingDataMethod.NPointsAverage, 4)";
// Check expression correctness
If Expr.Valid
// If expression is correct, save changes
Then ModelObj.Save();
// If expression is incorrect, output message to console window
Else System.Diagnostics.Debug.WriteLine("Model is not saved: error in formula");
End If;
End Sub;
Expression 1:
collapse({Brazil|BCA}, MsCollapseType.Total, MsFrequency.Annual, MissingDataMethod.NPointsAverage, 4)
Result: data is aggregated for the Brazil|BCA time series for annual frequency by summing method with missing data treatment by the N-Point Average method where N = 4.
Use: it can be used in formulas of calculated series of time series database and in formulas of attribute-based models of modeling container.
Expression 2:
Collapse(X1,MsCollapseType.Average,MsFrequency.Annual, MissingDataMethod.LinTrend)
Result: for the X1 factor data aggregation for annual frequency using average value calculation method with the Linear Trend missing data treatment method.
Use: it can be used in model variable-based formulas of modeling container.
See also:
IModelling | Time Series Database: Calculator, Aggregation | Modeling Container: The Models Collapse (Series Calculation),Collapse (Pointwise Calculation), Editing Regressor or Formula