2023-07-31 16:38:10 +08:00
|
|
|
|
using System;
|
|
|
|
|
using Aitex.Core.RT.DataCenter;
|
|
|
|
|
using Aitex.Core.RT.Log;
|
|
|
|
|
using Aitex.Core.Util;
|
|
|
|
|
using Sicentury.Core;
|
2023-08-02 16:12:13 +08:00
|
|
|
|
using FunFilter = System.Func<double, double>;
|
2023-07-31 16:38:10 +08:00
|
|
|
|
|
|
|
|
|
namespace MECF.Framework.RT.Core.Managers.PDS
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 气体流量累加器。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ProcessDataStatCounter : BindableBase
|
|
|
|
|
{
|
|
|
|
|
#region Variables
|
|
|
|
|
|
|
|
|
|
private DateTime _lastPollingTime = DateTime.MinValue;
|
|
|
|
|
private readonly R_TRIG _trigDataPollingError = new();
|
2023-08-02 16:12:13 +08:00
|
|
|
|
private FunFilter _dataFilter;
|
2023-08-08 16:24:34 +08:00
|
|
|
|
private readonly R_TRIG _rTrigPollDataFailed = new();
|
2023-07-31 16:38:10 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
2023-08-02 16:12:13 +08:00
|
|
|
|
public ProcessDataStatCounter(string name, string module, FunFilter filter = null)
|
2023-07-31 16:38:10 +08:00
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Module = module;
|
2023-08-02 16:12:13 +08:00
|
|
|
|
_dataFilter = filter;
|
2023-07-31 16:38:10 +08:00
|
|
|
|
|
|
|
|
|
DataPath = new[]
|
|
|
|
|
{
|
|
|
|
|
$"{module}.GasRealTimeFlow.{name}_Run.FeedBack",
|
|
|
|
|
$"{module}.GasRealTimeFlow.{name}_Vent.FeedBack",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 16:12:13 +08:00
|
|
|
|
public ProcessDataStatCounter(string name, string module, FunFilter filter = null, params string[] dataPath)
|
|
|
|
|
: this(name, module, filter)
|
2023-07-31 16:38:10 +08:00
|
|
|
|
{
|
|
|
|
|
DataPath = dataPath;
|
|
|
|
|
Total = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 16:12:13 +08:00
|
|
|
|
public ProcessDataStatCounter(string name, string module, double initValue, FunFilter filter = null) : this(name, module, filter)
|
2023-07-31 16:38:10 +08:00
|
|
|
|
{
|
|
|
|
|
Total = initValue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 16:12:13 +08:00
|
|
|
|
public ProcessDataStatCounter(string name, string module, double initValue, FunFilter filter = null, params string[] dataPath)
|
|
|
|
|
: this(name, module, filter, dataPath)
|
2023-07-31 16:38:10 +08:00
|
|
|
|
{
|
|
|
|
|
Total = initValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 返回当前统计数据的名称。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Name { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 返回当前统计数据所属的模块。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Module { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 返回当前数据统计时所使用的数据拉取路径。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string[] DataPath { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 返回当前统计数据的累加值。
|
|
|
|
|
/// </summary>
|
2023-08-01 18:24:41 +08:00
|
|
|
|
public double Total { get; internal set; }
|
2023-07-31 16:38:10 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 累加气体流量。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Accumulate()
|
|
|
|
|
{
|
|
|
|
|
var ts = DateTime.Now - _lastPollingTime;
|
|
|
|
|
if(_lastPollingTime == DateTime.MinValue)
|
|
|
|
|
ts = TimeSpan.FromSeconds(1);
|
|
|
|
|
|
2023-08-02 16:12:13 +08:00
|
|
|
|
var sum = 0.0d;
|
2023-07-31 16:38:10 +08:00
|
|
|
|
foreach (var pdata in DataPath)
|
|
|
|
|
{
|
2023-08-08 16:24:34 +08:00
|
|
|
|
var polled = DATA.Poll(pdata);
|
|
|
|
|
_rTrigPollDataFailed.CLK = polled == null;
|
|
|
|
|
if(_trigDataPollingError.Q)
|
|
|
|
|
LOG.Error($"Failed to count {pdata}, unable to poll data from RT");
|
|
|
|
|
|
|
|
|
|
if (polled == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var sFlow = polled.ToString();
|
2023-07-31 16:38:10 +08:00
|
|
|
|
if (double.TryParse(sFlow, out var dFlow))
|
|
|
|
|
{
|
2023-08-02 16:12:13 +08:00
|
|
|
|
sum += dFlow * ts.TotalSeconds;
|
2023-07-31 16:38:10 +08:00
|
|
|
|
_trigDataPollingError.RST = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_trigDataPollingError.CLK = true;
|
|
|
|
|
if (_trigDataPollingError.Q)
|
|
|
|
|
{
|
|
|
|
|
LOG.Error($"Unable to polling data {DataPath} or the data({sFlow}) is not double value.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 16:12:13 +08:00
|
|
|
|
Total += _dataFilter?.Invoke(sum) ?? sum;
|
|
|
|
|
|
2023-07-31 16:38:10 +08:00
|
|
|
|
_lastPollingTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{Name}: {Total:F1}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|