using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.Calculation
{
///
/// 能效标准业务时辅助类
///
public class EtaStandardLogicHourHelper
{
///
/// 依赖
///
public static List Standard
(
long CorpID,
string ObjectType,
long ObjectID,
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)
{
//存在此区间范围内的数据
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.EtaStandardLogicHourRecord();
record.CorpID = CorpID;
record.ConfigureID = configure.ID;
record.ObjectType = ObjectType;
record.ObjectID = ObjectID;
record.DataDay = Day.Date;
record.DataHour = i + 1;
record.DataTime = dt_now;
record.LowerLimit = configure.LowerLimit;
record.UpperLimit = configure.UpperLimit;
record.Qmin = normal_limit_hour_list.Where(x=>x.Qa.HasValue).Min(t => t.Qa.Value);
record.Qmax = normal_limit_hour_list.Where(x => x.Qa.HasValue).Max(t => t.Qa.Value);
record.Qavg = normal_limit_hour_list.Where(x => x.Qa.HasValue).Average(t => t.Qa.Value);
record.Emin = normal_limit_hour_list.Where(x => x.Ea.HasValue).Min(t => t.Ea.Value);
record.Emax = normal_limit_hour_list.Where(x => x.Ea.HasValue).Max(t => t.Ea.Value);
record.Eavg = normal_limit_hour_list.Where(x => x.Ea.HasValue).Average(t => t.Ea.Value);
record.Hmin = normal_limit_hour_list.Where(x => x.Ha.HasValue).Min(t => t.Ha.Value);
record.Hmax = normal_limit_hour_list.Where(x => x.Ha.HasValue).Max(t => t.Ha.Value);
record.Havg = normal_limit_hour_list.Where(x => x.Ha.HasValue).Average(t => t.Ha.Value);
record.Pmin = normal_limit_hour_list.Where(x => x.Pa.HasValue).Min(t => t.Pa.Value);
record.Pmax = normal_limit_hour_list.Where(x => x.Pa.HasValue).Max(t => t.Pa.Value);
record.Pavg = normal_limit_hour_list.Where(x => x.Pa.HasValue).Average(t => t.Pa.Value);
record.WPmin = normal_limit_hour_list.Where(x => x.WPa.HasValue).Min(t => t.WPa.Value);
record.WPmax = normal_limit_hour_list.Where(x => x.WPa.HasValue).Max(t => t.WPa.Value);
record.WPavg = normal_limit_hour_list.Where(x => x.WPa.HasValue).Average(t => t.WPa.Value);
record.UWPmin = normal_limit_hour_list.Where(x => x.UWPa.HasValue).Min(t => t.UWPa.Value);
record.UWPmax = normal_limit_hour_list.Where(x => x.UWPa.HasValue).Max(t => t.UWPa.Value);
record.UWPavg = normal_limit_hour_list.Where(x => x.UWPa.HasValue).Average(t => t.UWPa.Value);
record.Qt = normal_limit_hour_list.Where(x => x.Qa.HasValue).Sum(x => x.Qa.Value * x.Duration) / 3600f;
record.Qtt = run_normal_hour_list.Where(x => x.Qa.HasValue).Sum(x => x.Qa.Value * x.Duration) / 3600f;
record.Dt = normal_limit_hour_list.Where(x => x.Pa.HasValue).Sum(x => x.Pa.Value * x.Duration) / 3600f;
record.Dtt = run_normal_hour_list.Where(x => x.Pa.HasValue).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;
}
}
}