Ниже приведен пример использования операции GetMs для расчёта уравнения. В запросе передаются: экземпляр открытого контейнера моделирования, шаблон расчёта уравнения и параметры выполнения операции. В ответе приходит экземпляр модели, содержащей уравнение с результатами расчёта.
Для выполнения примера уравнение должно рассчитываться методом «Детерминированное уравнение».
{
"Envelope" :
{
"Body" :
{
"GetMs" :
{
"tMs" :
{
"id" : "S49!M!S!C1"
},
"tArg" :
{
"pattern" :
{
"obInst" : "false",
"all" : "false",
"item" :
{
"key" : "3364",
"model" :
{
"transform" :
{
"formulas" :
{
"method" : ""
}
}
}
}
},
"execParams" :
{
"k" : "0",
"scenarioKeys" : "", "execMethod" : "true", "execEvaluateSeries" : "true", "execPairCorrelationMatrix" : "true", "execFactsMatrix" : "true" } } } } } }
{
"Envelope" :
{
"Body" :
{
"GetMsResult" :
{
"id" :
{
"id" : "S49!M!S!C1"
},
"meta" :
{
"item" :
{
"k" : "3364",
"id" : "OBJ3364",
"n" : "MyOutputVavable[t] = 10 - MyInputVavable[t] * 3.14",
"vis" : "1",
"type" : "Model",
"modelMd" :
{
"transform" :
{
"formulas" :
{
"its" :
{
"it" :
[
{
"k" : "0",
"kind" : "Deterministic",
"method" :
{
"deterministic" :
{
"modifyType" : "Replace",
"expression" : "10 - @_3365:0[] * 3.14",
"result" :
{
"slice" :
{
"k" : "0",
"id" : "262",
"n" : "MyOutputVavable",
"vis" : "1",
"variableKey" : "3366",
"stubKey" : "2805",
"selections" :
{
"its" :
{
"Item" :
{
"id" :
{
"id" : "2818"
},
"variant" : "262"
}
}
},
"aggregator" : "None",
"parametrizedDimensions" :
{
"its" :
{
"Item" :
{
"dimension" : "0",
"parameter" : "0"
}
}
},
"unitInfo" :
{
"unit" : "4294967295",
"measure" : "4294967295",
"baseUnit" : "4294967295",
"unitsDimensionKey" : "0"
},
"level" : "None"
},
"lag" : "",
"key" : "0",
"termToText" : "{MyOutputVavable[t]}",
"termToInnerText" : "@_3366:0[]",
"termInfo" :
{
"k" : "4294967295",
"lag" : "0",
"inversion" :
{
"type" : "None",
"lag" : "PrecidingValue",
"previousLag" : "-1",
"seasonality" : "None",
"dependence" : "Linear",
"K" : "3"
}
},
"unitInfo" :
{
"unit" : "4294967295",
"measure" : "4294967295",
"baseUnit" : "4294967295",
"unitsDimensionKey" : "0"
}
},
"operands" :
{
"its" :
{
"Item" :
{
"k" : "0",
"slice" :
{
"k" : "0",
"id" : "261",
"n" : "MyInputVavable",
"vis" : "1",
"variableKey" : "3365",
"stubKey" : "2805",
"selections" :
{
"its" :
{
"Item" :
{
"id" :
{
"id" : "2818"
},
"variant" : "261"
}
}
},
"aggregator" : "None",
"parametrizedDimensions" :
{
"its" :
{
"Item" :
{
"dimension" : "0",
"parameter" : "0"
}
}
},
"unitInfo" :
{
"unit" : "4294967295",
"measure" : "4294967295",
"baseUnit" : "4294967295",
"unitsDimensionKey" : "0"
},
"level" : "None"
},
"lag" : "",
"key" : "1",
"termToText" : "{MyInputVavable[t]}",
"termToInnerText" : "@_3365:0[]",
"termInfo" :
{
"k" : "4294967295",
"lag" : "0",
"inversion" :
{
"type" : "None",
"lag" : "PrecidingValue",
"previousLag" : "-1",
"seasonality" : "None",
"dependence" : "Linear",
"K" : "3"
}
},
"unitInfo" :
{
"unit" : "4294967295",
"measure" : "4294967295",
"baseUnit" : "4294967295",
"unitsDimensionKey" : "0"
}
}
}
},
"aggregateOperands" :
{
"its" : ""
},
"factsMatrix" :
{
"d" :
[
"1.000000",
"-1.700000",
"7.200000",
"-1.000000",
"5.000000",
"0.200000",
"6.600000",
"-0.500000", "3.200000", "2.000000", "3.000000", "6.200000", "7.100000", "5.800000", "2.800000", "3.700000", "5.600000",
"3.200000", "3.600000", "8.000000", "7.000000", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN",
"NaN",
"NaN",
"NaN",
"NaN"
]
},
"pairCorrelationMatrix" :
{
"data" :
{
"d" : "1.000000"
}
}
},
"name" : "Y = 10 - X1 * 3.14",
"evaluateSeries" :
{
"its" :
{
"Item" :
{
"scenarioKey" : "4294967295",
"fact" :
{
"d" :
[
"4.000000",
"1.200000",
"3.000000",
"2.000000",
"3.800000", "1.200000", "2.800000", "2.000000", "1.100000", "5.400000", "1.000000", "-1.700000", "7.200000", "-1.000000",
"5.000000", "0.200000", "6.600000", "-0.500000", "3.200000", "2.000000", "3.000000", "NaN", "NaN" ]
},
"modelling" :
{
"d" :
[
"6.860000",
"15.338000",
"-12.608000",
"13.140000",
"-5.700000",
"9.372000", "-10.724000", "11.570000", "-0.048000", "3.720000", "0.580000", "-9.468000", "-12.294000", "-8.212000", "1.208000",
"-1.618000", "-7.584000", "-0.048000", "-1.304000", "-15.120000", "-11.980000", "NaN", "NaN" ] },
"forecast" :
{
"d" :
[
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN",
"NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN"
]
},
"residuals" :
{
"d" :
[ "-2.860000", "-14.138000", "15.608000", "-11.140000", "9.500000", "-8.172000", "13.524000", "-9.570000", "1.148000",
"1.680000", "0.420000", "7.768000", "19.494000", "7.212000", "3.792000", "1.818000", "14.184000", "-0.452000", "4.504000",
"17.120000",
"14.980000",
"NaN",
"NaN"
]
}
}
},
"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" } }, "calendarLevel" : "Year", "outputSliceKey" : "0" } ]
} } }, "warnings" : "" } } } } } } }
Функция GetMsDeterm рассчитывает указанное уравнение. Входные параметры: экземпляр контейнера моделирования; ключ рассчитываемого уравнения. В результате выполнения функция возвращает модель, содержащую рассчитанное уравнение. Результаты расчёта выводятся в окно консоли. Для вывода результатов используются вспомогательные процедуры: PrintArray, PrintSeries, описанные в разделе «Расчёт уравнения».
Для выполнения примера уравнение должно рассчитываться методом «Детерминированное уравнение».
public static MsItem GetMsDeterm(MsId ms, ulong eqKey)
{
var getMsOp = new GetMs();
// Задаём параметры выполнения операции
getMsOp.tMs = ms;
getMsOp.tArg = new GetMsArg()
{ // Задаём шаблон извлечения данных
pattern = new MsMdPattern()
{
obInst = false,
all = false,
item = new MsItemPattern()
{ // Указываем ключ рассчитываемого уравнения
key = eqKey,
model = new MsModelPattern()
{
transform = new MsFormulaTransformPattern()
{
formulas = new TsFormulaPattern()
{
method = new TsMethodPattern() { }
}
}
}
}
}, // Задаём параметры расчёта уравнения
execParams = new MsMdExecParams()
{
k = 0,
execMethod = true,
execEvaluateSeries = true,
scenarioKeys = new long[] { },
execFactsMatrix = true,
execPairCorrelationMatrix = true
}
};
// Создаем прокси-объект для выполнения операции
var somClient = new SomPortTypeClient();
GetMsResult getMsResult = somClient.GetMs(getMsOp);
MsItem model = getMsResult.meta.item;
// Выводим ошибки и предупреждения
MsModel eq = model.modelMd;
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 model;
}
См. также:
SOAP