183 lines
6.5 KiB
C#
183 lines
6.5 KiB
C#
///
|
|
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
|
|
///
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Rig.TestMethods.CombinedWithDetection
|
|
{
|
|
public class CombinedWithDetTestParams : TestParamsBase, IParamsProvider, ITestParams
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(CombinedWithDetTestParams) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public double InitQfrom; /// Tested flow low range related to the detected flow
|
|
public double InitQto; /// Tested flow high range related to the detected flow
|
|
public double TargetQ; /// Target=terminal flow durning detection when increasing or decreasing the flow
|
|
public float RateOfChange; /// Each step is calculated as (TargetQfrom - Qfrom) * RateOfChange, text form is displayed in % (*100)
|
|
public float DetectionThreshold; /// Drop of frequency for the detection, text form is displayed in % (*100)
|
|
public bool UseAinsteadOfB; /// true = Uses 'average flow After' instead of the 'average flow Before'
|
|
public double DetectedFlowShift; /// Detected flow shift in [m3/h]
|
|
public float OffsetPulsesFreq; /// Offset frequency of pulses of the small WM for the detection in Hz
|
|
public bool SupressTrills; /// Main meter readings are ignored during test (suitable for small flows)
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
InitQfrom = 1.0;
|
|
InitQto = 1.1;
|
|
TargetQ = 3.0;
|
|
RateOfChange = 0.05f;
|
|
DetectionThreshold = 0.25f;
|
|
UseAinsteadOfB = false;
|
|
DetectedFlowShift = 0;
|
|
OffsetPulsesFreq = 1.0f;
|
|
SupressTrills = false;
|
|
}
|
|
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
string.Format(Strings.Initial_0, Strings.Q_from + " [m3/h]" ),
|
|
string.Format(Strings.Initial_0, Strings.Q_to + " [m3/h]" ),
|
|
string.Format(Strings.Target_0, "Q [m3/h]" ),
|
|
Strings.RateOfChangePct,
|
|
Strings.DetectionThresholdPct,
|
|
"Use A instead of B",
|
|
"Detected flow shift [m3/h]",
|
|
"Offset pulses freq.",
|
|
Strings.SupressWMTrills,
|
|
};
|
|
public override string ParamName(int i) { return paramNames[i]; }
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return InitQfrom.ToString();
|
|
case 1: return InitQto.ToString();
|
|
case 2: return TargetQ.ToString();
|
|
case 3: return (100.0f * RateOfChange).ToString();
|
|
case 4: return (100.0f * DetectionThreshold).ToString();
|
|
case 5: return UseAinsteadOfB ? Strings.yes : Strings.no;
|
|
case 6: return DetectedFlowShift.ToString();
|
|
case 7: return OffsetPulsesFreq.ToString();
|
|
case 8: return SupressTrills ? Strings.yes : Strings.no;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: InitQfrom = Utils.ParseUDouble(strValue); return CfgUpdateFlags.None;
|
|
case 1: InitQto = Utils.ParseUDouble(strValue); return CfgUpdateFlags.None;
|
|
case 2: TargetQ = Utils.ParseUDouble(strValue); return CfgUpdateFlags.None;
|
|
case 3: RateOfChange = Utils.ParseUFloat(strValue) / 100.0f; return CfgUpdateFlags.None;
|
|
case 4: DetectionThreshold = Utils.ParseUFloat(strValue) / 100.0f; return CfgUpdateFlags.None;
|
|
case 5: UseAinsteadOfB = strValue.Equals(Strings.yes); return CfgUpdateFlags.None;
|
|
case 6: DetectedFlowShift = Utils.ParseSDouble(strValue); return CfgUpdateFlags.None;
|
|
case 7: OffsetPulsesFreq = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None;
|
|
case 8: SupressTrills = strValue.Equals(Strings.yes); return CfgUpdateFlags.None;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
float fdummy;
|
|
double ddummy;
|
|
switch (i)
|
|
{
|
|
case 0: /// InitQfrom
|
|
case 1: /// InitQto
|
|
case 2: /// TargetQ
|
|
if (Utils.TryParseUDouble(strValue, out ddummy)) return true;
|
|
break;
|
|
case 3: /// RateOfChange
|
|
case 4: /// DetectionThreshold
|
|
case 7: /// OffsetPulsesFreq
|
|
if (Utils.TryParseUFloat(strValue, out fdummy)) return true;
|
|
break;
|
|
case 5: /// UseAinsteadOfB
|
|
case 8: /// SupressTrills
|
|
if (strValue.Equals(Strings.yes) || strValue.Equals(Strings.no)) return true;
|
|
break;
|
|
case 6: /// DetectedFlowShift
|
|
if (Utils.TryParseSDouble(strValue, out ddummy)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(CombinedWithDetTestParams prms)
|
|
{
|
|
prms.InitQfrom = this.InitQfrom;
|
|
prms.InitQto = this.InitQto;
|
|
prms.TargetQ = this.TargetQ;
|
|
prms.RateOfChange = this.RateOfChange;
|
|
prms.DetectionThreshold = this.DetectionThreshold;
|
|
prms.UseAinsteadOfB = this.UseAinsteadOfB;
|
|
prms.DetectedFlowShift = this.DetectedFlowShift;
|
|
prms.OffsetPulsesFreq = this.OffsetPulsesFreq;
|
|
prms.SupressTrills = this.SupressTrills;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
CombinedWithDetTestParams pars = new CombinedWithDetTestParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public override void UpdateFromDbEntity(ComponentTest dbEntity)
|
|
{
|
|
if (dbEntity == null) return;
|
|
try
|
|
{
|
|
CombinedWithDetTestParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as CombinedWithDetTestParams;
|
|
|
|
testParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
test = dbEntity.Test;
|
|
|
|
if (tmp != null) tmp.CopyContentTo(this);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parameterless constructor initializes the parameters
|
|
/// </summary>
|
|
public CombinedWithDetTestParams()
|
|
{
|
|
}
|
|
|
|
public CombinedWithDetTestParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public CombinedWithDetTestParams(ComponentTest testParamsEntity, string componentName, Test test)
|
|
{
|
|
this.testParamsEntity = testParamsEntity;
|
|
this.componentName = componentName;
|
|
this.test = test;
|
|
}
|
|
}
|
|
}
|