Step-by-Step Model Calculation

Below is the example of using the GetMs operation for step-by-step model calculation. The request contains an instance of opened modeling container, pattern and parameters of model calculation. The response contains information about calculation.

SOAP request:

- <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
- <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <GetMs xmlns="http://www.fsight.ru/PP.SOM.Som">
- <tMs xmlns="">
  <id>S54!M!S!C1</id>
  </tMs>
- <tArg xmlns="">
- <pattern>
  <obInst>true</obInst>
- <item>
  <key>2803</key>
- <problem>
- <calculation>
- <calculationState>
- <model>
  <generatedName>true</generatedName>
  </model>
  </calculationState>
  </calculation>
  </problem>
  </item>
  </pattern>
- <execParams>
  <level>Year</level>
  <problemCalculationKey>0</problemCalculationKey>
- <slices>
  <its />
  </slices>
  <execStepInto>false</execStepInto>
  <execStepOver>true</execStepOver>
  </execParams>
  </tArg>
  </GetMs>
  </s:Body>
  </s:Envelope>

SOAP response:

- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
- <soapenv:Body>
- <GetMsResult xmlns="http://www.fsight.ru/PP.SOM.Som" xmlns:q1="http://www.fsight.ru/PP.SOM.Som" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <id xmlns="">
  <id>S54!M!S!C1</id>
  </id>
- <meta xmlns="">
- <obInst>
- <obDesc isShortcut="0">
  <i>MODELSPACE</i>
  <n>Modeling container</n>
  <k>1581</k>
  <c>5121</c>
  <p>1580</p>
  <h>0</h>
  </obDesc>
  </obInst>
  <dirty>0</dirty>
- <item>
  <k>2803</k>
  <id>TEMP_MODEL</id>
  <n>TEMP_MODEL</n>
  <vis>1</vis>
  <type>Problem</type>
- <problemMd>
- <calculation>
  <pointCount>0</pointCount>
  <pointPassed>0</pointPassed>
  <saveData>1</saveData>
  <copyFact>0</copyFact>
  <treatNullsAsZeros>0</treatNullsAsZeros>
  <isRunning>0</isRunning>
- <calculationState>
  <model />
  <scenarioKey>4294967295</scenarioKey>
  <currentPoint>1899-12-30</currentPoint>
  <message>Task calculation is finished. Calculation time took 00:00:01</message>
  </calculationState>
  <isSuspend>0</isSuspend>
  </calculation>
  </problemMd>
  </item>
  </meta>
  </GetMsResult>
  </soapenv:Body>
  </soapenv:Envelope>

JSON request:

    {
     "GetMs" : 
      {
       "tMs" : 
        {
         "id" : "S30!M!S!C1"
        },
       "tArg" : 
        {
         "pattern" : 
          {
           "obInst" : "true",
           "item" : 
            {
             "key" : "2803",
             "problem" : 
              {
               "calculation" : 
                {
                 "calculationState" : 
                  {
                   "model" : 
                    {
                     "generatedName" : "true"
                    }
                  }
                }
              }
            }
          },
         "execParams" : 
          {
           "level" : "Year",
           "problemCalculationKey" : "0",
           "slices" : 
            {
             "its" : ""
            },
           "execStepInto" : "false",
           "execStepOver" : "true"
          }
        }
      }
    }
  }
}

JSON response:

    {
     "GetMsResult" : 
      {
       "id" : 
        {
         "id" : "S30!M!S!C1"
        },
       "meta" : 
        {
         "obInst" : 
          {
           "obDesc" : 
            {
             "@isShortcut" : "0",
             "i" : "MODELSPACE",
"n" : "Modeling container",
"k" : "1581",
"c" : "5121",
"p" : "1580",
"h" : "0"
}
},
"dirty" : "0",
"item" : 
{
           "k" : "2803",
           "id" : "TEMP_MODEL",
           "n" : "TEMP_MODEL",
           "vis" : "1",
           "type" : "Problem",
           "problemMd" : 
            {
             "calculation" : 
              {
               "pointCount" : "0",
               "pointPassed" : "0",
               "saveData" : "1",
               "copyFact" : "0",
               "treatNullsAsZeros" : "0",
               "isRunning" : "0",
               "calculationState" : 
                {
                 "model" : "",
                 "scenarioKey" : "4294967295",
                 "currentPoint" : "1899-12-30",
                 "message" : "Task calculation completed. Calculation time is 00:00:01"
},
"isSuspend" : "0"
}
}
}
}
public static bool GetMsStepIntoCalc(MsId ms, ulong modelKey, ulong? prCalcKey, MsFormulaTransformSlice outSlice)
 {
     var getMsOp = new GetMs();
     //Set operation execution parameters
     getMsOp.tMs = ms;
     getMsOp.tArg = new GetMsArg()
     {  //Set general data getting pattern
         pattern = new MsMdPattern()
         {
             item = new MsItemPattern()
             {   //Set calculated model key
                 key = modelKey,
                 //Set data calculation pattern
                 problem = new MsProblemPattern()
                 {
                     calculation = new MsProblemCalculationPattern()
                     {
                         calculationState = new MsCalculationStatePattern()
                         {
                             model = new MsModelPattern() { generatedName = true }
                         }
                     }
                 }
             }
         },//Set calculation parameters
         execParams = new MsMdExecParams()
         {
             execStepInto = false,
             execStepOver = true,
             problemCalculationKey = prCalcKey,
             slices = new MsFormulaTransformSlices()
             {
                 its = new MsFormulaTransformSlice[] { outSlice }
             },
             level = DimCalendarLvl.Year
         }
     };
     //Create a proxy object for operation execution
     var somClient = new SomPortTypeClient();
     //Execute calculation steps
     GetMsResult getMsResult = somClient.GetMs(getMsOp);
     MsProblemCalculation calc = getMsResult.meta.item.problemMd.calculation;
     //Output calculation data into console window
     if ((calc.pointPassed == 0) && (calc.pointCount !=0))
     {
         Console.WriteLine("Task calculation information:");
         Console.WriteLine("".PadRight(3) + "- number of calculation steps: " + calc.pointCount);
         Console.WriteLine("".PadRight(3) + "- data is loaded into output variables after calculation end: " + calc.saveData);
         Console.WriteLine("".PadRight(3) + "- data for sample period is copied from the Fact scenario: " + calc.copyFact);
         Console.WriteLine("".PadRight(3) + "- empty values in data are filled with zeros: " + calc.treatNullsAsZeros);
         Console.WriteLine("".PadRight(3) + "- model in calculation process: " + calc.isRunning);
     };
     Console.WriteLine("Task calculation. Step '" + calc.pointPassed + "' from '" + calc.pointCount + "'");
     MsCalculationState calcState = calc.calculationState;
     Console.WriteLine("".PadRight(3) + "- operation: " + calcState.message);
     Console.WriteLine("".PadRight(3) + "- equation: " + calcState.model.generatedName);
     Console.WriteLine("".PadRight(3) + "- calculation scenario key: "+calcState.scenarioKey);
     Console.WriteLine("".PadRight(3) + "- calculation point: " + calcState.currentPoint);
     Console.WriteLine("".PadRight(3) + "- values: " + printArray(calcState.values));
     bool continueCalc = calc.isSuspend.Value;
     return continueCalc;
 }

See also:

GetMs: Operation