IdentificationStartDateParam: IMsModelParamAttributes;
IdentificationStartDateParam: Prognoz.Platform.Interop.Ms.IMsModelParamAttributes;
The IdentificationStartDateParam property determines binding settings for the parameter that sets sample period start date.
Executing the example requires that the repository contains a modeling container with the MODEL_SPACE identifier. A problem with the PROBLEM identifier, a metamodel and a model are created in the container. Parameters with the I_START, I_END, F_START, F_END identifiers are created in the metamodel. All parameters send selection and are linked with calendar dictionary.
Add links to the Dimensions, Metabase, Ms system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
Model: IMsModel;
MParams: IMsModelParams;
CalcPeriod: IMsModelPeriod;
OutputPeriod: IMsDatePeriod;
Begin
// Get model
Mb := MetabaseClass.Active;
Problem := Mb.ItemByIdNamespace("PROBLEM", Mb.GetObjectKeyById("MODEL_SPACE")).Edit As IMsProblem;
MetaModel := Problem.MetaModel;
Model := (MetaModel.CalculationChain.Item(0) As IMsCalculationChainModel).EditModel;
MParams := MetaModel.Params;
// Calculation periods
CalcPeriod := Model.Transform.Period;
CalcPeriod.IdentificationStartDateParam.Parameter := MParams.FindById("I_START");
CalcPeriod.IdentificationEndDateParam.Parameter := MParams.FindById("I_END");
CalcPeriod.ForecastStartDateParam.Parameter := MParams.FindById("F_START");
CalcPeriod.ForecastEndDateParam.Parameter := MParams.FindById("F_END");
SetAttribute(CalcPeriod.IdentificationStartDateParam);
SetAttribute(CalcPeriod.IdentificationEndDateParam);
SetAttribute(CalcPeriod.ForecastStartDateParam);
SetAttribute(CalcPeriod.ForecastEndDateParam);
// Unloading period
OutputPeriod := Model.Transform.OutputPeriod As IMsDatePeriod;
// Clear data unloading period
OutputPeriod.ClearPeriod();
// Set unloading period start and end
OutputPeriod.Enabled := True;
OutputPeriod.StartParam.Parameter := MParams.FindById("F_START");
OutputPeriod.EndParam.Parameter := MParams.FindById("F_END");
SetAttribute(OutputPeriod.StartParam);
SetAttribute(OutputPeriod.EndParam);
// Save changes
Model.MetabaseObject.Save;
End Sub UserProc;
Sub SetAttribute(DateParam: IMsModelParamAttributes);
Var
Dim: IDimInstance;
Begin
Dim := DateParam.Parameter.LinkedObject.Open(Null) As IDimInstance;
DateParam.ClearAttributes;
DateParam.Attributes.Add(Dim.Attributes.FindById("START_DATE").Attribute);
End Sub SetAttribute;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Ms;
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
Model: IMsModel;
MParams: IMsModelParams;
CalcPeriod: IMsModelPeriod;
OutputPeriod: IMsDatePeriod;
Begin
// Get model
Mb := Params.Metabase;
Problem := Mb.ItemByIdNamespace["PROBLEM", Mb.GetObjectKeyById("MODEL_SPACE")].Edit() As IMsProblem;
MetaModel := Problem.MetaModel;
Model := (MetaModel.CalculationChain.Item[0] As IMsCalculationChainModel).EditModel;
MParams := MetaModel.Params;
// Calculation periods
CalcPeriod := Model.Transform.Period;
CalcPeriod.IdentificationStartDateParam.Parameter := MParams.FindById("I_START");
CalcPeriod.IdentificationEndDateParam.Parameter := MParams.FindById("I_END");
CalcPeriod.ForecastStartDateParam.Parameter := MParams.FindById("F_START");
CalcPeriod.ForecastEndDateParam.Parameter := MParams.FindById("F_END");
SetAttribute(CalcPeriod.IdentificationStartDateParam);
SetAttribute(CalcPeriod.IdentificationEndDateParam);
SetAttribute(CalcPeriod.ForecastStartDateParam);
SetAttribute(CalcPeriod.ForecastEndDateParam);
// Unloading period
OutputPeriod := Model.Transform.OutputPeriod As IMsDatePeriod;
// Clear data unloading period
OutputPeriod.ClearPeriod();
// Set unloading period start and end
OutputPeriod.Enabled := True;
OutputPeriod.StartParam.Parameter := MParams.FindById("F_START");
OutputPeriod.EndParam.Parameter := MParams.FindById("F_END");
SetAttribute(OutputPeriod.StartParam);
SetAttribute(OutputPeriod.EndParam);
// Save changes
Model.MetabaseObject.Save();
End Sub;
Shared Sub SetAttribute(DateParam: IMsModelParamAttributes);
Var
Dim: IDimInstance;
Begin
Dim := DateParam.Parameter.LinkedObject.Open(Null) As IDimInstance;
DateParam.ClearAttributes();
DateParam.Attributes.Add(Dim.Attributes.FindById("START_DATE").Attribute);
End Sub;
After executing the example sample, forecasting and data unloading periods are changed for the model. Period values are taken from metamodel parameters and created by values of the START_DATE attribute of the elements selected in calendar dictionaries.
See also: