using System; using System.Collections.Generic; using System.Linq; using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; namespace IStation.Model { /// /// /// public class EtaBasicRealRecord { /// /// /// public EtaBasicRealRecord() { } /// /// /// public EtaBasicRealRecord(EtaBasicRealRecord rhs) { this.CorpID = rhs.CorpID; this.ObjectType = rhs.ObjectType; this.ObjectID = rhs.ObjectID; this.DataTime = rhs.DataTime; this.Duration = rhs.Duration; this.Qa = rhs.Qa; this.Ha = rhs.Ha; this.Pa = rhs.Pa; this.Ea = rhs.Ea; this.WPa = rhs.WPa; this.UWPa = rhs.UWPa; this.AnalyStatus = rhs.AnalyStatus; this.AnalyInfo = rhs.AnalyInfo; } /// /// 复制分析参数 /// /// public void CopyAnaPara(EtaBasicRealRecord rhs) { if (rhs == null) return; this.Qa = rhs.Qa; this.Ha = rhs.Ha; this.Pa = rhs.Pa; this.Ea = rhs.Ea; this.WPa = rhs.WPa; this.UWPa = rhs.UWPa; this.AnalyStatus = rhs.AnalyStatus; this.AnalyInfo = rhs.AnalyInfo; } /// /// 客户标识 /// public long CorpID { get; set; } /// /// 对象类型 /// public string ObjectType { get; set; } /// /// 对象标识 /// public long ObjectID { get; set; } /// /// 数据时间 /// public DateTime DataTime { get; set; } /// /// 间隔 /// public int Duration { get; set; } /// /// 分析瞬时流量 /// public double? Qa { get; set; } /// /// 分析扬程 /// public double? Ha { get; set; } /// /// 分析功率 /// public double? Pa { get; set; } /// /// 分析效率 /// public double? Ea { get; set; } /// /// 分析千吨能耗 /// public double? WPa { get; set; } /// /// 分析单位能耗 /// public double? UWPa { get; set; } /// /// 分析状态 /// public Eta.eAnalyStatus AnalyStatus { get; set; } /// /// 分析信息 /// public string AnalyInfo { get; set; } #region AnalyInfo #region InfoTag /// /// 运行状态发生异常的标识 /// public const string InfoTag_RU = "RU"; /// /// 频率发生异常的标识 /// public const string InfoTag_HZ = "HZ"; /// /// 流量发生异常的标识 /// public const string InfoTag_Qa = "Qa"; /// /// 扬程发生异常的标识 /// public const string InfoTag_Ha = "Ha"; /// /// 进口压力发生异常的标识 /// public const string InfoTag_P1 = "P1"; /// /// 出口压力发生异常的标识 /// public const string InfoTag_P2 = "P2"; /// /// 功率发生异常的标识 /// public const string InfoTag_Pa = "Pa"; /// /// 效率发生异常的标识 /// public const string InfoTag_Ea = "Ea"; /// /// 电流发生异常的标识 /// public const string InfoTag_Ia = "Ia"; /// /// 曲线发生异常的标识 /// public const string InfoTag_Curve = "Cu"; /// /// 泵站发生异常的标识 /// public const string InfoTag_Station = "St"; #endregion #region Basic /// /// 添加状态 /// /// public void PutAnalyInfo(string tag) { if (string.IsNullOrEmpty(AnalyInfo)) { AnalyInfo = string.Format("V1|{0}:", tag); } else { AnalyInfo = string.Format("{0}|{1}:", AnalyInfo, tag); } } /// /// 添加AnalyInfo标识 /// /// 标识 /// 更多信息 public void PutAnalyInfo(string tag, string more) { if (string.IsNullOrEmpty(AnalyInfo)) { if (string.IsNullOrEmpty(more)) { AnalyInfo = string.Format("V1|{0}:", tag); } else { AnalyInfo = string.Format("V1|{0}:{1}", tag, more); } } else { if (string.IsNullOrEmpty(more)) { AnalyInfo = string.Format("{0}|{1}:", AnalyInfo, tag); } else { AnalyInfo = string.Format("{0}|{1}:{2}", AnalyInfo, tag, more); } } } /// /// 添加AnalyInfo标识 /// /// 标识 public void RemoveAnalyInfo(string tag) { if (string.IsNullOrEmpty(AnalyInfo)) { return; } var sss = AnalyInfo.Split('|').ToList(); for (int i = 0; i < sss.Count(); i++) { if (sss[i].StartsWith(tag)) { sss.RemoveAt(i); AnalyInfo = string.Join("|", sss); if (AnalyInfo == "V1") { AnalyInfo = null; } return; } } } /// /// 有分析异常 /// /// /// public bool IsHaveAnaTag(string tag) { if (string.IsNullOrEmpty(AnalyInfo)) { return false; } return AnalyInfo.Contains("|" + tag); } /// /// 有分析异常 /// /// /// public bool IsHaveStationTag(long stationId) { if (string.IsNullOrEmpty(AnalyInfo)) { return false; } return AnalyInfo.Contains($"{InfoTag_Station}:{stationId}"); } #endregion /// /// 添加泵站 AnalyInfo标识 /// /// 机泵错误信息 /// 机泵标识 public void PutStationAnalyInfo(string ePumpAnalyInfo, long ePumpId) { if (string.IsNullOrEmpty(ePumpAnalyInfo)) return; var defaultEdition = "V1"; if (string.IsNullOrEmpty(AnalyInfo)) { AnalyInfo = defaultEdition; } var infoArry = ePumpAnalyInfo.Split('|').ToList(); foreach (var item in infoArry) { if (item == defaultEdition) continue; AnalyInfo = $"{AnalyInfo}|{item}:{ePumpId}"; } if (AnalyInfo == defaultEdition) { AnalyInfo = null; } } /// /// 添加业务 AnalyInfo标识 /// /// 业务错误信息 public void PutLogicAnalyInfo(string logicAnalyInfo) { if (string.IsNullOrEmpty(logicAnalyInfo)) return; var defaultEdition = "V1"; if (string.IsNullOrEmpty(AnalyInfo)) { AnalyInfo = defaultEdition; } var infoArry = logicAnalyInfo.Split('|').ToList(); foreach (var item in infoArry) { if (item == defaultEdition) continue; if (item.StartsWith(InfoTag_Station)) { AnalyInfo = $"{AnalyInfo}|{item}"; } } if (AnalyInfo == defaultEdition) { AnalyInfo = null; } } /// /// 获取错误信息 /// /// public List GetStatioinIds() { if (string.IsNullOrEmpty(this.AnalyInfo)) return default; var list = new List(); var infoArry = AnalyInfo.Split('|').ToList(); foreach (var item in infoArry) { if (item.StartsWith(InfoTag_Station)) { var valueArr = item.Split(':'); if (valueArr != null && valueArr.Count() > 1) { var stationId = valueArr[1]; if (long.TryParse(stationId, out long id)) { list.Add(id); } } } } return list; } /// /// 获取错误信息 /// /// public List GetPumpIds() { if (string.IsNullOrEmpty(this.AnalyInfo)) return default; var list = new List(); var infoArry = AnalyInfo.Split('|').ToList(); foreach (var item in infoArry) { var valueArr = item.Split(':'); if (valueArr != null && valueArr.Count() > 2) { var pumpId = valueArr[2]; if (long.TryParse(pumpId, out long id)) { list.Add(id); } } } return list; } /// /// 获取错误信息 /// /// public string GetAnaInfoCN() { var errCN = string.Empty; if (string.IsNullOrEmpty(this.AnalyInfo)) return string.Empty; var tagList = new List(); var infoArry = AnalyInfo.Split('|').ToList(); foreach (var item in infoArry) { if (item == "V1") continue; var valueList = item.Split(':'); if (valueList != null && valueList.Count() > 0) { if (valueList.Count() > 2) continue; var tag = valueList[0]; tagList.Add(tag); } } if (tagList.Count < 1) return default; foreach (var item in tagList) { errCN += GetAnaTagCN(item) + "、"; } return errCN.Substring(0, errCN.Length - 1) + "异常!"; } /// /// 获取分析错误类型 /// public string GetAnaTagCN(string anaTag) { var tagCN = "未知"; switch (anaTag) { case InfoTag_RU: tagCN = "运行状态"; break; case InfoTag_HZ: tagCN = "频率"; break; case InfoTag_Qa: tagCN = "流量"; break; case InfoTag_Ha: tagCN = "扬程"; break; case InfoTag_P1: tagCN = "进口压力"; break; case InfoTag_P2: tagCN = "出口压力"; break; case InfoTag_Pa: tagCN = "功率"; break; case InfoTag_Ea: tagCN = "效率"; break; case InfoTag_Ia: tagCN = "电流"; break; case InfoTag_Curve: tagCN = "曲线"; break; } return tagCN; } #endregion #region 计算 /// /// /// /// /// public static double MPa2M(double mpa) { return mpa * 1000 / 9.81; } /// /// /// /// /// /// /// /// /// public static double Calc_Eta(double Q, double H, double P, double midu, double gavity) { P = P * 1000;//此处 1000 是 kw换成w Q = Q / 3600;//此处 3600 是 小时换成秒 double E = 0; if (P < 0.1) E = 0; else E = midu * gavity * Q * H / P; return Math.Round(E * 100, 2);//效率用百分数 } /// /// /// /// /// /// /// public static double Calc_Eta(double Q, double H, double P) { double midu = 1000; double gavity = 9.81; P = P * 1000;//此处 1000 是 kw换成w Q = Q / 3600;//此处 3600 是 小时换成秒 double E = 0; if (P < 0.1) E = 0; else E = midu * gavity * Q * H / P; return Math.Round(E * 100, 2);//效率用百分数 } /// /// /// /// public bool CalcUnitPower() { Calcu_WP(); return Calcu_UWP(); } /// /// /// /// private bool Calcu_WP() { this.WPa = 0; if (this.Qa == null || this.Qa < 0.1) return false; if (this.Pa == null || this.Pa < 0.1) return false; this.WPa = Math.Round(this.Pa.Value / this.Qa.Value * 1000f, 3); return true; } /// /// 单位水耗 千吨水 /// /// private bool Calcu_UWP() { this.UWPa = 0; if (this.Qa == null || this.Qa < 0.1) return false; if (this.Pa == null || this.Pa < 0.1) return false; if (this.Ha == null || this.Ha < 0.1) return false; this.UWPa = Math.Round(this.Pa.Value / this.Qa.Value / this.Ha.Value * 1000f, 4); return true; } #endregion } }