Below is the example of using the GetMs operation to calculate an equation. The request contains and instance of opened modeling container, equation calculation pattern, and parameters of operation execution. The response contains an instance of the model that contains an equation with calculation results.
To execute the example, the equation must be calculated with the Determinate Equation method.
The C# example uses the PrintArray, PrintSeries auxiliary operations to display results described in the Equation Calculation section.
{ "GetMs" : { "tMs" : { "id" : "AOGBEFLOHDNBFOAEDPIBNDGEBKEDGIEEJKBKNMPOIOPJKGIB!M!S!CDMLANFLOHDNBFOAEJJKHCEGAMOAEGLOEPKMEPMOJMOAHLALB" }, "tArg" : { "pattern" : { "obInst" : "false", "all" : "false", "item" : { "key" : "89669", "problem" : { "metamodel" : { "calculationChain" : "Get", "calcChainPattern" : { "modelPattern" : { "transform" : { "outputs" : "Get", "formulaCount" : "true", "formulas" : { "method" : { "series" : "true" } }, "displayId" : "true", "equationsFormula" : { "method" : "" }, "series" : "Get", "kind" : "true", "displaySettings" : "true", "additionalAttributes" : "true", "calculationType" : "true", "calculationDirection" : "true", "transformVariable" : { "slices" : "Get", "transformSlice" : { "selection" : "Get" } } }, "stochastic" : "true", "calculationPeriod" : "true", "useModelPeriod" : "true", "useExistingData" : "true", "treatNullsAsZeros" : "true", "autoName" : "true", "generatedName" : "true", "period" : "true", "isExclusive" : "true", "useAutoPeriod" : "true" }, "entryKeys" : { "l" : "4" } } } } } }, "execParams" : { "k" : "0", "modelKeys" : { "l" : "4" }, "scenarioKeys" : "", "execMethod" : "true", "execEvaluateSeries" : "true", "execPairCorrelationMatrix" : "true" } } } }
{ "GetMsResult" : { "id" : { "id" : "AOGBEFLOHDNBFOAEDPIBNDGEBKEDGIEEJKBKNMPOIOPJKGIB!M!S!CDMLANFLOHDNBFOAEJJKHCEGAMOAEGLOEPKMEPMOJMOAHLALB" }, "meta" : { "item" : { "k" : "89669", "id" : "MODEL_NEW", "n" : "MODEL_NEW", "vis" : "1", "type" : "Problem", "problemMd" : { "metamodel" : { "k" : "89670", "calculationChain" : { "its" : { "Item" : { "k" : "4", "id" : "OBJ4", "n" : "MyOutputVavable|A[t] = 10 - MyInputVavable[t] * 3.14, (From parent)-(From parent)", "vis" : "1", "type" : "Model", "excluded" : "0", "graphMeta" : "", "model" : { "transform" : { "outputs" : { "its" : { "Item" : { "k" : "1", "id" : "VARIABLES_89670", "n" : "Variables", "vis" : "1", "slices" : { "its" : { "Item" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" } } }, "variableStubKey" : "89671", "parameterID" : "", "kind" : "Stub", "attributeId" : "", "attributeType" : "Series" } } }, "formulaCount" : "1", "formulas" : { "its" : { "it" : [ { "k" : "0", "kind" : "Deterministic", "method" : { "deterministic" : { "modifyType" : "Replace", "expression" : "10 - @_2:0[] * 3.14", "result" : { "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "lag" : "", "key" : "0", "termToText" : "{MyOutputVavable|A[t]}", "termToInnerText" : "@_1:0[]", "termInfo" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "included" : "0" }, "operands" : { "its" : { "Item" : { "k" : "0", "slice" : { "k" : "0", "id" : "1", "n" : "MyInputVavable", "vis" : "1", "variableKey" : "2", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "1" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "lag" : "", "key" : "1", "termToText" : "{MyInputVavable[t]}", "termToInnerText" : "@_2:0[]", "termInfo" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "1", "n" : "MyInputVavable", "vis" : "1", "variableKey" : "2", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "1" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "included" : "1" } } }, "pairCorrelationMatrix" : { "data" : { "d" : "1" } } }, "name" : "10 - X1 * 3.14", "series" : { "addFactor" : { "k" : "4294967295" } }, "evaluateSeries" : { "its" : { "Item" : { "scenarioKey" : "4294967295", "fact" : { "d" : [ "3", "7", "2", "6", "4", "1", "5", "3.42857143", "3.28571429", "3.14285714", "3", "2.85714286", "2.71428571", "2.57142857", "2.42857143", "2.28571429", "2.14285714", "2", "1.85714286", "1.71428571", "1.57142857", "1.42857143", "1.28571429", "1.14285714", "1", "0.85714286", "0.71428571", "0.57142857", "NaN" ] }, "modelling" : { "d" : [ "6.859999999999999", "-2.56", "3.72", "-11.98", "-13.55", "-18.574", "-23.598", "-28.62200000000001", "-33.646", "-38.67", "-43.69400000000001", "-48.718", "-53.742", "-58.76600000000001", "-63.79000000000001", "-68.81400000000001", "-73.83800000000001", "-78.86200000000001", "-83.886", "-88.91000000000001", "-93.93400000000001", "-98.95800000000001", "-103.982", "-109.006", "-114.03", "-119.054", "NaN", "NaN", "NaN" ] }, "residuals" : { "d" : [ "-3.859999999999999", "9.56", "-1.72", "17.98", "17.55", "19.574", "28.598", "32.05057143000001", "36.93171429", "41.81285714", "46.69400000000001", "51.57514286000001", "56.45628571", "61.33742857000001", "66.21857143000001", "71.09971429000001", "75.98085714000001", "80.86200000000001", "85.74314285999999", "90.62428571000001", "95.50542857000001", "100.38657143", "105.26771429", "110.14885714", "115.03", "119.91114286", "NaN", "NaN", "NaN" ] }, "input" : { "d" : [ "3", "7", "2", "6", "4", "1", "5", "3.42857143", "3.28571429", "3.14285714", "3", "2.85714286", "2.71428571", "2.57142857", "2.42857143", "2.28571429", "2.14285714", "2", "1.85714286", "1.71428571", "1.57142857", "1.42857143", "1.28571429", "1.14285714", "1", "0.85714286", "0.71428571", "0.57142857", "NaN", "NaN", "NaN" ] }, "indicators" : { "its" : { "it" : [ { "termToText" : "{MyInputVavable[t]}", "serie" : { "d" : [ "1", "4", "2", "7", "7.5", "9.1", "10.7", "12.3", "13.9", "15.5", "17.1", "18.7", "20.3", "21.9", "23.5", "25.1", "26.7", "28.3", "29.9", "31.5", "33.1", "34.7", "36.3", "37.9", "39.5", "41.1", "NaN", "NaN", "NaN", "NaN", "NaN" ] }, "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "entryKey" : "1" } ] } } } }, "dates" : { "it" : [ "1990A1", "1991A1", "1992A1", "1993A1", "1994A1", "1995A1", "1996A1", "1997A1", "1998A1", "1999A1", "2000A1", "2001A1", "2002A1", "2003A1", "2004A1", "2005A1", "2006A1", "2007A1", "2008A1", "2009A1", "2010A1", "2011A1", "2012A1", "2013A1", "2014A1", "2015A1", "2016A1", "2017A1", "2018A1", "2019A1", "2020A1" ] } }, "inversionInfo" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "doUseR" : "0", "supportsR" : "0" }, "calendarLevel" : "Year", "outputSliceKey" : "0" } ] } }, "displayId" : "0", "series" : { "its" : "" }, "kind" : "Simple", "displaySettings" : { "displayTermsAs" : "Derive" }, "additionalAttributes" : "", "calculationType" : "Serie", "calculationDirection" : "Forward" }, "stochastic" : "0", "calculationPeriod" : "Forecast", "useModelPeriod" : "1", "useExistingData" : "0", "treatNullsAsZeros" : "0", "autoName" : "1", "period" : { "identificationStartDate" : "1990-01-01", "identificationEndDate" : "2018-04-24", "forecastStartDate" : "2018-04-25", "forecastEndDate" : "2020-01-01", "identificationStartDateParamID" : "", "identificationEndDateParamID" : "", "forecastStartDateParamID" : "", "forecastEndDateParamID" : "", "autoPeriod" : "28672", "identificationStartOffset" : "0", "identificationEndOffset" : "0", "forecastEndOffset" : "0", "isIdentStartCorrect" : "1", "isIdentEndCorrect" : "1", "isForecastEndCorrect" : "1" }, "isExclusive" : "1", "useAutoPeriod" : "1", "generatedName" : "MyOutputVavable|A[t] = 10 - MyInputVavable[t] * 3.14", "warnings" : "", "readOnly" : "0" } } } }, "visualController" : { "userRPath" : "", "isRExist" : "0" }, "suppressEmptyFilter" : { "suppressEmpty" : "0", "suppressEmptyArea" : "SerieBounds" }, "readOnly" : "0", "variableTestUseR" : "0", "calculateIdentOnFact" : "0" }, "useScenarios" : "0", "readOnly" : "0" } } } } }
public static MsCalculationChainEntry GetMsDeterm(MsId ms, ulong modelKey, ulong eqKey) { var getMsOp = new GetMs(); // Set operation execution parameters getMsOp.tMs = ms; getMsOp.tArg = new GetMsArg() { // Set data extraction pattern pattern = new MsMdPattern() { obInst = false, all = false, item = new MsItemPattern() { // Specify calculated model key key = modelKey, problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { calculationChain = ListOperation.Get, calcChainPattern = new MsCalculationChainPattern() { // Specify calculated equation key entryKeys = new long[] { (long)eqKey }, modelPattern = new MsModelPattern() { autoName = true, calculationPeriod = true, generatedName = true, isExclusive = true, period = true, stochastic = true, treatNullsAsZeros = true, useAutoPeriod = true, useExistingData = true, useModelPeriod = true, transform = new MsFormulaTransformPattern() { additionalAttributes = true, calculationDirection = true, calculationType = true, displayId = true, displaySettings = true, formulaCount = true, outputs = ListOperation.Get, series = ListOperation.Get, kind = true, formulas = new TsFormulaPattern() { method = new TsMethodPattern() { series = true } }, equationsFormula = new TsFormulaPattern() { method = new TsMethodPattern() { } }, transformVariable = new MsFormulaTransformVariablePattern() { slices = ListOperation.Get, transformSlice = new MsFormulaTransformSlicePattern() { selection = ListOperation.Get } } } } } } } } }, // Set equation calculation parameters execParams = new MsMdExecParams() { k = 0, execMethod = true, execEvaluateSeries = true, execPairCorrelationMatrix = true, scenarioKeys = new long[] { }, modelKeys = new long[] { (long)eqKey } } }; // Create a proxy object for operation execution var somClient = new SomPortTypeClient(); GetMsResult getMsResult = somClient.GetMs(getMsOp); MsMetaModel meta = getMsResult.meta.item.problemMd.metamodel; MsCalculationChainEntry chainEntry = meta.calculationChain.its.GetValue(0) as MsCalculationChainEntry; // Display errors and warnings MsModel eq = chainEntry.model; if (eq.warnings != null) { Console.WriteLine("-- Warnings --"); Console.WriteLine("".PadRight(3) + printArray(eq.warnings)); } if (eq.error == null) //Check if errors occurred on equation calculation { // Equation is calculated without errors, get calculation results TsFormula formula = eq.transform.formulas.its.GetValue(0) as TsFormula; TsDeterministicMethod determ = formula.method.deterministic; Console.WriteLine("-- Input factors --"); Console.WriteLine("".PadRight(3) + printArray(determ.factsMatrix)); Console.WriteLine("-- Correlation matrix --"); MsPairCorrelationMatrix pm = determ.pairCorrelationMatrix; if (pm.error != null) {Console.WriteLine("".PadRight(3) + "error: " + pm.error);} Console.WriteLine("".PadRight(3) + printArray(pm.data)); // Get calculated values and display into console window MsEvaluateSeriesResult seriesRes = formula.method.evaluateSeries; printSeries(seriesRes); } else // Errors occurred on equation calculation { Console.WriteLine("-- Errors --"); Console.WriteLine(eq.error); } // Return the model that contains equation return chainEntry; }
See also: