IMsCalculationStats.Compare

Syntax

Compare(Right: IMsCalculationStats): IMsCalculationStatsDiffList;

Parameters

Right. Compared calculation statistics.

Description

The Compare method compares statistics to each other.

Comments

To compare calculation statistics, save statistics result to XML file using the IMsCalculationStats.SaveToXml method.

Equal statistics are compared to each other. The comparison results in the collection containing information only by the statistics, which values differ.

Example

Executing the example requires that the repository contains a modeling container with the CONT_MODEL identifier including a modeling problem with the PROBLEM identifier. The file system should contain a file with statistics from the previous problem calculation: D:\Work\Stats.xml.

Add links to the Metabase, Ms, Xml system assemblies.

Sub UserProc;
Var
    Mb: IMetabase;
    Problem: IMsProblem;
    Settings: IMsProblemCalculationSettings;
    Calc: IMsProblemCalculation;
    OldStats, NewStats: IMsCalculationStats;
    Doc: IXMLDOMDocument3;
    Elem: IXmlDomElement;
Begin
    Mb := MetabaseClass.Active;
    
// Get modeling problem
    Problem := Mb.ItemByIdNamespace("PROBLEM", Mb.GetObjectKeyById("CONT_MODEL")).EditTemporary As IMsProblem;
    Settings := Problem.CreateCalculationSettings;
    
// Set calculation statistics drill down
    Settings.StatsLevel := MsCalculationStatsLevel.Basic;
    Calc := Problem.Calculate(Settings);
    
// Calculate modeling problem and calculation statistics
    Calc.Run;
    
// Problem execution statistic
    NewStats := Calc.Stats;
    
// Load previous statistic from file and compare
    Doc := New FreeThreadedDOMDocument60.Create;
    Doc.load(
"D:\Work\Stats.xml");
    Elem := doc.selectSingleNode(
"Stats"As IXmlDomElement;
    OldStats := 
New MsCalculationStats.Create;
    OldStats.LoadFromXml(Elem);
    
// Compare statistics
    ShowCompareResult(NewStats.Compare(OldStats));
End Sub UserProc;

Sub ShowCompareResult(DiffList: IMsCalculationStatsDiffList);
Var
    Diff: IMsCalculationStatsDiff;
    Left, Right: IMsCalculationStatNode;
    i: Integer;
Begin
    Debug.WriteLine(
"Number of found differences: " + DiffList.Count.ToString);
    Debug.Indent;
    
For i := 0 To DiffList.Count - 1 Do
        Diff := DiffList.Item(i);
        Left := Diff.Left;
        Right := Diff.Right;
        Debug.Write(Left.Name + 
":   ");
        Debug.Write(
"Calculated value: "); ShowValue(Left.Value);
        Debug.Write(
". Value obtained from file: "); ShowValue(Right.Value);
        Debug.WriteLine(
"");
    
End For;
    Debug.Unindent;
End Sub ShowCompareResult;

Sub ShowValue(Value: Variant);
Var
    Values: Array 
Of Variant;
    j: Integer;
    Combined: String;
Begin
    
If Value Is Array Then
        Values := Value 
As Array;
        
For j := 0 To Values.Length - 1 Do
            
If Not Combined.IsEmpty Then
                Combined := Combined + 
", ";
            
End If;
            Combined := Combined + Values[j];
        
End For;
        Debug.Write(
"[" + Combined + "]");
        Combined := 
"";
    
Elseif Value Is IMsDatePeriod Then
        Debug.Write((Value 
As IMsDatePeriod).Start.ToString + " - " + (Value As IMsDatePeriod).End_.ToString);
    
Else
        Debug.Write(Value);
    
End If;
End Sub ShowValue;

Executing the example results in the calculation of the specified modeling problem and the obtained calculation statistic. After this, the obtained statistic is compared with the statistic saved to the file. If there are differences, they are displayed in the development environment console.

See also:

IMsCalculationStats