using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.Calculation { /// /// 能效依赖业务时辅助类 /// public class EtaAccordLogicHourHelper { /// /// 依赖 /// public static List Accord ( DateTime Day, IEnumerable configures, IEnumerable list ) { if (configures == null || configures.Count() < 1) return default; if (list == null || list.Count() < 1) return default; var normal_list = list.Where(x => x.AnalyStatus == Model.Eta.eAnalyStatus.Normal).ToList(); if (normal_list.Count < 1) return default; var dt_now = DateTime.Now; var record_list = new List(); foreach (var configure in configures) { if (configure.AccordType == Model.Eta.eAccordType.Q) { //存在此区间范围内的数据 var normal_limit_list = normal_list.Where(t => t.Qa >= configure.LowerLimit && t.Qa <= configure.UpperLimit).ToList(); if (normal_limit_list != null && normal_limit_list.Count > 0) { for (int i = 0; i < 24; i++) { //此小时的此范围的所有运行点数据 var normal_limit_hour_list = normal_limit_list.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList(); if (normal_limit_hour_list.Count > 0) { //此小时的所有运行点数据 var normal_hour_list = normal_list.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList(); var record = new Model.EtaAccordLogicHourRecord(); record.CorpID = configure.CorpID; record.ConfigureID = configure.ID; record.ObjectType = configure.BelongType; record.ObjectID = configure.BelongID; record.DataDay = Day.Date; record.DataHour = i + 1; record.DataTime = dt_now; record.AccordType = configure.AccordType; record.LowerLimit = configure.LowerLimit; record.UpperLimit = configure.UpperLimit; record.Qmin = normal_limit_hour_list.Min(t => t.Qa.Value); record.Qmax = normal_limit_hour_list.Max(t => t.Qa.Value); record.Qavg = normal_limit_hour_list.Average(t => t.Qa.Value); record.Emin = normal_limit_hour_list.Min(t => t.Ea.Value); record.Emax = normal_limit_hour_list.Max(t => t.Ea.Value); record.Eavg = normal_limit_hour_list.Average(t => t.Ea.Value); record.Hmin = normal_limit_hour_list.Min(t => t.Ha.Value); record.Hmax = normal_limit_hour_list.Max(t => t.Ha.Value); record.Havg = normal_limit_hour_list.Average(t => t.Ha.Value); record.Pmin = normal_limit_hour_list.Min(t => t.Pa.Value); record.Pmax = normal_limit_hour_list.Max(t => t.Pa.Value); record.Pavg = normal_limit_hour_list.Average(t => t.Pa.Value); record.WPmin = normal_limit_hour_list.Min(t => t.WPa.Value); record.WPmax = normal_limit_hour_list.Max(t => t.WPa.Value); record.WPavg = normal_limit_hour_list.Average(t => t.WPa.Value); record.UWPmin = normal_limit_hour_list.Min(t => t.UWPa.Value); record.UWPmax = normal_limit_hour_list.Max(t => t.UWPa.Value); record.UWPavg = normal_limit_hour_list.Average(t => t.UWPa.Value); record.Qt = normal_limit_hour_list.Sum(x => x.Qa.Value * x.Duration) / 3600f; record.Qtt = normal_hour_list.Sum(x => x.Qa.Value * x.Duration) / 3600f; record.Dt = normal_limit_hour_list.Sum(x => x.Pa.Value * x.Duration) / 3600f; record.Dtt = normal_hour_list.Sum(x => x.Pa.Value * x.Duration) / 3600f; record.PointCount = normal_limit_hour_list.Count; record.TotalPointCount = normal_hour_list.Count; record_list.Add(record); } } } } else if (configure.AccordType == Model.Eta.eAccordType.E) { //存在此区间范围内的数据 var normal_limit_list = normal_list.Where(t => t.Ea >= configure.LowerLimit && t.Ea <= configure.UpperLimit).ToList(); if (normal_limit_list != null && normal_limit_list.Count > 0) { for (int i = 0; i < 24; i++) { //此小时的此范围的所有运行点数据 var normal_limit_hour_list = normal_limit_list.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList(); if (normal_limit_hour_list.Count > 0) { //此小时的所有运行点数据 var run_normal_hour_list = normal_list.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList(); var record = new Model.EtaAccordLogicHourRecord(); record.CorpID = configure.CorpID; record.ConfigureID = configure.ID; record.ObjectType = configure.BelongType; record.ObjectID = configure.BelongID; record.DataDay = Day.Date; record.DataHour = i + 1; record.DataTime = dt_now; record.AccordType = configure.AccordType; record.LowerLimit = configure.LowerLimit; record.UpperLimit = configure.UpperLimit; record.Qmin = normal_limit_hour_list.Min(t => t.Qa.Value); record.Qmax = normal_limit_hour_list.Max(t => t.Qa.Value); record.Qavg = normal_limit_hour_list.Average(t => t.Qa.Value); record.Emin = normal_limit_hour_list.Min(t => t.Ea.Value); record.Emax = normal_limit_hour_list.Max(t => t.Ea.Value); record.Eavg = normal_limit_hour_list.Average(t => t.Ea.Value); record.Hmin = normal_limit_hour_list.Min(t => t.Ha.Value); record.Hmax = normal_limit_hour_list.Max(t => t.Ha.Value); record.Havg = normal_limit_hour_list.Average(t => t.Ha.Value); record.Pmin = normal_limit_hour_list.Min(t => t.Pa.Value); record.Pmax = normal_limit_hour_list.Max(t => t.Pa.Value); record.Pavg = normal_limit_hour_list.Average(t => t.Pa.Value); record.WPmin = normal_limit_hour_list.Min(t => t.WPa.Value); record.WPmax = normal_limit_hour_list.Max(t => t.WPa.Value); record.WPavg = normal_limit_hour_list.Average(t => t.WPa.Value); record.UWPmin = normal_limit_hour_list.Min(t => t.UWPa.Value); record.UWPmax = normal_limit_hour_list.Max(t => t.UWPa.Value); record.UWPavg = normal_limit_hour_list.Average(t => t.UWPa.Value); record.Qt = normal_limit_hour_list.Sum(x => x.Qa.Value * x.Duration) / 3600f; record.Qtt = run_normal_hour_list.Sum(x => x.Qa.Value * x.Duration) / 3600f; record.Dt = normal_limit_hour_list.Sum(x => x.Pa.Value * x.Duration) / 3600f; record.Dtt = run_normal_hour_list.Sum(x => x.Pa.Value * x.Duration) / 3600f; record.PointCount = normal_limit_hour_list.Count; record.TotalPointCount = run_normal_hour_list.Count; record_list.Add(record); } } } } } return record_list; } } }