StepParam: String;
StepParam: string;
The StepParam property determines parameters which sets cycle calculation step.
Calculation step is set using calculation by dates, it means the IMsCalculationChainIterator.UseDates property must be set to True.
To set directly calculation step, use the IMsCalculationChainIterator.Step_ property.
Executing the example requires that repository contains modeling container with the MS identifier containing metamodel with the METAMODEL_ITERATOR identifier and model with the MODEL_ITERATOR identifier.
Add links to the Dal, Dimensions, Metabase, Ms, Transform system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsKey: Integer;
MetaModel: IMsMetaModel;
Param: IMsModelParam;
CalcChain: IMsCalculationChainEntries;
Iterator: IMsCalculationChainIterator;
Model: IMsModel;
Formula: IMsFormula;
Expr: IExpression;
Begin
// Get current
mb := MetabaseClass.Active;
// Get modelling container key
MsKey := mb.GetObjectKeyById("MS");
// Get metamodel
MetaModel := mb.ItemByIdNamespace("METAMODEL_ITERATOR", MsKey).Edit As IMsMetaModel;
// Clear metamodel parameters collection
MetaModel.Params.Clear;
// Add parameter which will be responsible for cycle calculation
Param := MetaModel.Params.Add;
Param.DefaultValue := 0;
Param.Id := "THRESHOLD";
Param.Name := "Threshold";
// Add parameter which will be responsible for
// the cycle iterations start date
Param := MetaModel.Params.Add;
Param.DataType := DbDataType.Date;
Param.ParamType := TsParamType.Date;
Param.DefaultValue := DateTime.Parse("01.01.2000");
Param.Id := "ST_DATE";
Param.Name := "Iterations start date";
// Add parameter which will be responsible for
// cycle iterations end date
Param := MetaModel.Params.Add;
Param.DataType := DbDataType.Date;
Param.ParamType := TsParamType.Date;
Param.DefaultValue := DateTime.Parse("01.01.2017");
Param.Id := "END_DATE";
Param.Name := "Iterations end date";
// Add parameter which will be responsible for
// cycle iterations step
Param := MetaModel.Params.Add;
Param.ParamType := TsParamType.Frequency;
Param.DefaultValue := DimCalendarLevel.Week;
Param.Id := "STEP";
Param.Name := "Iterations step";
// Get and clear metamodel calculation chain
CalcChain := MetaModel.CalculationChain;
CalcChain.Clear;
// Create cycle in metamodel calculation chain
Iterator := CalcChain.AddIterator("Cycle");
// Set cycle execution conditions
Iterator.PostCondition := True;
Iterator.MaxIterations := 600;
Expr := Iterator.Expression;
Expr.AsString := "{THRESHOLD}<5";
// Get the model
Model := mb.ItemByIdNamespace("MODEL_ITERATOR", MsKey).Edit As IMsModel;
// Clear model calculation dynamics
Formula := Model.Transform.FormulaItem(0);
Formula.Level := DimCalendarLevel.Root;
// Save changes in the model
(Model As IMetabaseObject).Save;
// Add this model to the cycle
Iterator.Contents.AddModel(model);
// Determine that the cycle will execute iteration by dates
Iterator.UseDates := True;
// Set iteration dates using parameters
Iterator.StartParamID := "ST_DATE";
Iterator.EndParamID := "END_DATE";
// Set step of dates for iterations using parameter
Iterator.StepParam := "STEP";
(MetaModel As IMetabaseObject).Save;
End Sub UserProc;
After executing the example cycle iteration will be executed by specified dates with determined step. Dates and step will be set using parameters.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Transform;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsKey: uinteger;
MetaModel: IMsMetaModel;
Param: IMsModelParam;
CalcChain: IMsCalculationChainEntries;
Iterator: IMsCalculationChainIterator;
Model: IMsModel;
Formula: IMsFormula;
Expr: IExpression;
Begin
// Get current
mb := Params.Metabase;
// Get modelling container key
MsKey := mb.GetObjectKeyById("MS");
// Get metamodel
MetaModel := mb.ItemByIdNamespace["METAMODEL_ITERATOR", MsKey].Edit() As IMsMetaModel;
// Clear metamodel parameters collection
MetaModel.Params.Clear();
// Add parameter which will be responsible for cycle calculation
Param := MetaModel.Params.Add();
Param.DefaultValue := 0;
Param.Id := "THRESHOLD";
Param.Name := "Threshold";
// Add parameter which will be responsible for
// the cycle iterations start date
Param := MetaModel.Params.Add();
Param.DataType := DbDataType.ddtDate;
Param.ParamType := TsParamType.tsptDate;
Param.DefaultValue := DateTime.Parse("01.01.2000");
Param.Id := "ST_DATE";
Param.Name := "Iterations start date";
// Add parameter which will be responsible for
// cycle iterations end date
Param := MetaModel.Params.Add();
Param.DataType := DbDataType.ddtDate;
Param.ParamType := TsParamType.tsptDate;
Param.DefaultValue := DateTime.Parse("01.01.2017");
Param.Id := "END_DATE";
Param.Name := "Iterations end date";
// Add parameter which will be responsible for
// cycle iterations step
Param := MetaModel.Params.Add();
Param.ParamType := TsParamType.tsptFrequency;
Param.DefaultValue := DimCalendarLevel.dclWeek;
Param.Id := "STEP";
Param.Name := "Iterations step";
// Get and clear metamodel calculation chain
CalcChain := MetaModel.CalculationChain;
CalcChain.Clear();
// Create cycle in metamodel calculation chain
Iterator := CalcChain.AddIterator("Cycle");
// Set cycle execution conditions
Iterator.PostCondition := True;
Iterator.MaxIterations := 600;
Expr := Iterator.Expression;
Expr.AsString := "{THRESHOLD}<5";
// Get the model
Model := mb.ItemByIdNamespace["MODEL_ITERATOR", MsKey].Edit() As IMsModel;
// Clear model calculation dynamics
Formula := Model.Transform.FormulaItem[0];
Formula.Level := DimCalendarLevel.dclRoot;
// Save changes in the model
(Model As IMetabaseObject).Save();
// Add this model to the cycle
Iterator.Contents.AddModel(model);
// Determine that the cycle will execute iteration by dates
Iterator.UseDates := True;
// Set iteration dates using parameters
Iterator.StartParamID := "ST_DATE";
Iterator.EndParamID := "END_DATE";
// Set step of dates for iterations using parameter
Iterator.StepParam := "STEP";
(MetaModel As IMetabaseObject).Save();
End Sub;
See also: