IMsCalculationStats.Compare

Syntax

Compare(Right: IMsCalculationStats): IMsCalculationStatsDiffList;

Compare(Right: Prognoz.Platform.Interop.Ms.IMsCalculationStats): Prognoz.Platform.Interop.Ms.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 that contains 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 (in Fore.NET - the MsXml2 assembly) 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;

Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.MsXml2;

Public Shared Sub Main(Params: StartParams);
Var
    Mb: IMetabase;
    Problem: IMsProblem;
    Settings: IMsProblemCalculationSettings;
    Calc: IMsProblemCalculation;
    OldStats, NewStats: MsCalculationStats;
    Doc: IXMLDOMDocument3 = 
New FreeThreadedDOMDocument60();
    Elem: IXmlDomElement;
Begin
    Mb := Params.Metabase;
    
// 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.mcslBasic;
    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.load("D:\Work\Stats.xml");
    Elem := doc.selectSingleNode(
"Stats"As IXmlDomElement;
    OldStats := 
New MsCalculationStatsClass();
    OldStats.LoadFromXml(Elem);
    
// Compare statistics
    ShowCompareResult(NewStats.Compare(OldStats));
End Sub;

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

Shared Sub ShowValue(Value: Object);
Var
    Values: Array;
    j: Integer;
    Combined: String;
Begin
    
If Value Is Array Then
        Values := Value 
As Array;
        
For j := 0 To Values.Length - 1 Do
            
If Not string.IsNullOrEmpty(Combined) Then
                Combined := Combined + 
", ";
            
End If;
            Combined := Combined + Values[j];
        
End For;
        System.Diagnostics.Debug.Write(
"[" + Combined + "]");
        Combined := 
"";
    
Elseif Value Is IMsDatePeriod Then
        System.Diagnostics.Debug.Write((Value 
As IMsDatePeriod).Start.ToString() + " - " + (Value As IMsDatePeriod).@End.ToString());
    
Else
        System.Diagnostics.Debug.Write(Value);
    
End If;
End Sub;

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