Transform: IMsFormulaTransform;
Transform: Prognoz.Platform.Interop.Ms.IMsFormulaTransform;
The Transform property returns parameters of complex condition of calculation.
By default, parameters contain one formula with annual frequency. To get the formula, use the IMsFormulaTransform.FormulaItem property. After creating the formula, it will be automatically decomposed and set into the IMsBranchConditionExpression.Expression property.
Executing the example requires that the repository contains a modeling container with the MODEL_SPACE identifier, which contains models with the USER_MODEL, DEFAULT_MODEL identifiers and a metamodel with the USER_META_MODEL identifier. The metamodel must contain an integer parameter named indicator_param.
Add links to the Dimensions, Metabase, Ms system assemblies.
Sub UserTransformation;
Var
pMetabase: IMetabase;
pMSKey: Integer;
pMeta: IMsMetaModel;
pBranch: IMsCalculationChainBranch;
pModel_a, pModel_b: IMsModel;
pCase: IMsBranchCase;
pCond: IMsBranchConditionExpression;
pTransf: IMsFormulaTransform;
pMethod: IMsDeterministicTransform;
Begin
pMetabase := MetabaseClass.Active;
//Get modeling container key
pMSKey := pMetabase.GetObjectKeyById("MODEL_SPACE");
// Get metamodel
pMeta := pMetabase.ItemByIdNamespace("USER_META_MODEL", pMSKey).Edit As IMsMetaModel;
// Clear calculation chain of metamodel
pMeta.CalculationChain.Clear;
// Create a condition of metamodel calculation
pBranch := pMeta.CalculationChain.AddBranch("Calculation condition");
// Set calendar frequency of condition
pBranch.Level := DimCalendarLevel.Year;
// Get the DEFAULT_MODEL model
pModel_a := pMetabase.ItemByIdNamespace("DEFAULT_MODEL", pMSKey).Bind As IMsModel;
// Add model to condition
pBranch.DefaultContents.AddModel(pModel_a);
// Get the USER_MODEL model
pModel_b := pMetabase.ItemByIdNamespace("USER_MODEL", pMSKey).Bind As IMsModel;
// Create a new branch of condition
pCase := pBranch.CaseList.Add;
// Add the USER_MODEL model to new branch
pCase.Contents.AddModel(pModel_b);
// Create a condition of branch calculation
pCond := pCase.Conditions.Add(MsBranchConditionType.Expression) As IMsBranchConditionExpression;
pTransf := pCond.Transform;
pMethod := pTransf.FormulaItem(0).Method As IMsDeterministicTransform;
pMethod.Expression.AsString := "{indicator_param[t]} = 3";
// Save metamodel
(pMeta As IMetabaseObject).Save;
End Sub UserTransformation;
After executing the example the calculation condition will be added to the metamodel: the value of the metamodel parameter must be equal to three. On calculating the transformation task the following condition is checked: if it is satisfied, the USER_MODEL model is calculated; if it is not satisfied, the DEFAULT_MODEL is calculated.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
pMetabase: IMetabase;
pMSKey: uinteger;
pMeta: IMsMetaModel;
pBranch: IMsCalculationChainBranch;
pModel_a, pModel_b: IMsModel;
pCase: IMsBranchCase;
pCond: IMsBranchConditionExpression;
pTransf: IMsFormulaTransform;
pMethod: IMsDeterministicTransform;
Begin
pMetabase := Params.Metabase;
//Get modeling container key
pMSKey := pMetabase.GetObjectKeyById("MODEL_SPACE");
// Get metamodel
pMeta := pMetabase.ItemByIdNamespace["USER_META_MODEL", pMSKey].Edit() As IMsMetaModel;
// Clear calculation chain of metamodel
pMeta.CalculationChain.Clear();
// Create a condition of metamodel calculation
pBranch := pMeta.CalculationChain.AddBranch("Calculation condition");
// Set calendar frequency of condition
pBranch.Level := DimCalendarLevel.dclYear;
// Get the DEFAULT_MODEL model
pModel_a := pMetabase.ItemByIdNamespace["DEFAULT_MODEL", pMSKey].Bind() As IMsModel;
// Add model to condition
pBranch.DefaultContents.AddModel(pModel_a);
// Get the USER_MODEL model
pModel_b := pMetabase.ItemByIdNamespace["USER_MODEL", pMSKey].Bind() As IMsModel;
// Create a new branch of condition
pCase := pBranch.CaseList.Add();
// Add the USER_MODEL model to new branch
pCase.Contents.AddModel(pModel_b);
// Create a condition of branch calculation
pCond := pCase.Conditions.Add(MsBranchConditionType.mbctExpression) As IMsBranchConditionExpression;
pTransf := pCond.Transform;
pMethod := pTransf.FormulaItem[0].Method As IMsDeterministicTransform;
pMethod.Expression.AsString := "{indicator_param[t]} = 3";
// Save metamodel
(pMeta As IMetabaseObject).Save();
End Sub;
See also: