121 lines
3.8 KiB
C#
121 lines
3.8 KiB
C#
using System;
|
|
using System.Xml;
|
|
|
|
namespace XYLEM.Device
|
|
{
|
|
/// <summary>
|
|
/// A single calibration point
|
|
/// </summary>
|
|
[Serializable]
|
|
public class CalibrationPoint : IComparable<CalibrationPoint>, IEquatable<CalibrationPoint>
|
|
{
|
|
/// <summary>
|
|
/// Reference flow in liter / second
|
|
/// https://xyleminc.atlassian.net/wiki/spaces/MJKMF/pages/6661802342
|
|
/// </summary>
|
|
public Single ReferenceFlowRate_lps { get; set; }
|
|
|
|
/// <summary>
|
|
/// DUT Reported flow in liter / second
|
|
/// https://xyleminc.atlassian.net/wiki/spaces/MJKMF/pages/6661802342
|
|
/// </summary>
|
|
public Single ReportedFlowRate_lps { get; set; }
|
|
|
|
public CalibrationPoint()
|
|
{
|
|
ReferenceFlowRate_lps = ReportedFlowRate_lps = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ctor
|
|
/// </summary>
|
|
/// <param name="referenceFlowRate_lps">reference flow rate [l/s] given by the flow-test-bench</param>
|
|
/// <param name="reportedFlowRate_lps">reported flow rate [l/s] by the DUT</param>
|
|
public CalibrationPoint(Single referenceFlowRate_lps, Single reportedFlowRate_lps)
|
|
{
|
|
ReferenceFlowRate_lps = referenceFlowRate_lps;
|
|
ReportedFlowRate_lps = reportedFlowRate_lps;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
const int w1 = 11;
|
|
return $"Ref={ReferenceFlowRate_lps*3.6,w1:F6} m3/h DUT={ReportedFlowRate_lps*3.6,w1:F6} m3/h " +
|
|
$"(Ref={ReferenceFlowRate_lps,w1:F6} l/s DUT={ReportedFlowRate_lps,w1:F6} l/s)";
|
|
}
|
|
|
|
public int CompareTo(CalibrationPoint other)
|
|
{
|
|
// If null, it can't be the same
|
|
if (System.Object.ReferenceEquals(other, null))
|
|
{
|
|
return -1;
|
|
}
|
|
// Any of them is not okay
|
|
if ((this.ReferenceFlowRate_lps!= other.ReferenceFlowRate_lps) || (this.ReportedFlowRate_lps!= other.ReportedFlowRate_lps))
|
|
{
|
|
return -1; // Not the same
|
|
}
|
|
return 0; // is the same
|
|
}
|
|
|
|
public bool Equals(CalibrationPoint other)
|
|
{
|
|
return this.CompareTo(other) == 0;
|
|
}
|
|
|
|
#region Operator == > < ! ..
|
|
public static bool operator ==(CalibrationPoint a, CalibrationPoint b)
|
|
{
|
|
// If both are null, or both are same instance, return true.
|
|
if (System.Object.ReferenceEquals(a, b))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// If one is null, but not both, return false.
|
|
// from https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type?redirectedfrom=MSDN
|
|
if (a is null)
|
|
{
|
|
// null == null = true.
|
|
if (b is null)
|
|
{
|
|
return true;
|
|
}
|
|
// Only the left side is null.
|
|
return false;
|
|
}
|
|
|
|
// Return true if the fields match:
|
|
return (a.Equals(b));
|
|
}
|
|
|
|
public static bool operator !=(CalibrationPoint a, CalibrationPoint b)
|
|
{
|
|
return !(a == b);
|
|
}
|
|
|
|
public static bool operator <(CalibrationPoint a, CalibrationPoint b)
|
|
{
|
|
return a.CompareTo(b) < 0;
|
|
}
|
|
|
|
public static bool operator >(CalibrationPoint a, CalibrationPoint b)
|
|
{
|
|
return a.CompareTo(b) > 0;
|
|
}
|
|
|
|
public static bool operator >=(CalibrationPoint a, CalibrationPoint b)
|
|
{
|
|
return a.CompareTo(b) >= 0;
|
|
}
|
|
|
|
public static bool operator <=(CalibrationPoint a, CalibrationPoint b)
|
|
{
|
|
return a.CompareTo(b) <= 0;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
} |