Ниже приведен пример использования операции GetMs для расчёта уравнения. В запросе передаются: экземпляр открытого контейнера моделирования, шаблон расчёта уравнения и параметры выполнения операции. В ответе приходит экземпляр модели, содержащей уравнение с результатами расчёта.
Для выполнения примера уравнение должно рассчитываться методом «Детерминированное уравнение».
В примере C# для вывода результатов используются вспомогательные процедуры: PrintArray, PrintSeries, описанные в разделе «Расчёт уравнения».
{
"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, (От родителя)-(От родителя)",
"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"
]
},
"factors" :
{
"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();
// Задаём параметры выполнения операции
getMsOp.tMs = ms;
getMsOp.tArg = new GetMsArg()
{ // Задаем шаблон извлечения данных
pattern = new MsMdPattern()
{
obInst = false,
all = false,
item = new MsItemPattern()
{ // Указываем ключ рассчитываемой модели
key = modelKey,
problem = new MsProblemPattern()
{
metamodel = new MsMetaModelPattern()
{
calculationChain = ListOperation.Get,
calcChainPattern = new MsCalculationChainPattern()
{
// Указываем ключ рассчитываемого уравнения
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
}
}
}
}
}
}
}
}
}, // Задаем параметры расчёта уравнения
execParams = new MsMdExecParams()
{
k = 0,
execMethod = true,
execEvaluateSeries = true,
execPairCorrelationMatrix = true,
scenarioKeys = new long[] { },
modelKeys = new long[] { (long)eqKey }
}
};
// Создаем прокси-объект для выполнения операции
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;
// Выводим ошибки и предупреждения
MsModel eq = chainEntry.model;
if (eq.warnings != null)
{
Console.WriteLine("-- Предупреждения --");
Console.WriteLine("".PadRight(3) + printArray(eq.warnings));
}
if (eq.error == null) //Проверяем, возникли ли ошибки при расчёте уравнения
{ // Уравнение рассчитано без ошибок, получаем результаты расчёта
TsFormula formula = eq.transform.formulas.its.GetValue(0) as TsFormula;
TsDeterministicMethod determ = formula.method.deterministic;
Console.WriteLine("-- Входные факторы --");
Console.WriteLine("".PadRight(3) + printArray(determ.factsMatrix));
Console.WriteLine("-- Матрица корреляции --");
MsPairCorrelationMatrix pm = determ.pairCorrelationMatrix;
if (pm.error != null) {Console.WriteLine("".PadRight(3) + "ошибка: " + pm.error);}
Console.WriteLine("".PadRight(3) + printArray(pm.data));
// Получаем рассчитанные значения и выводим в окно консоли
MsEvaluateSeriesResult seriesRes = formula.method.evaluateSeries;
printSeries(seriesRes);
}
else // При расчёте уравнения возникли ошибки
{
Console.WriteLine("-- Ошибки --");
Console.WriteLine(eq.error);
}
// Возвращаем модель, содержащую уравнение
return chainEntry;
}
См. также: