using DevExpress.XtraReports.Native.Templates; using IStation.Model; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.WinFrmUI.Monitor { public class OutWaterHelper { public List GetMeanValue( List realHistoryData) { List listoutwater = new List(); List currentlist = new List(realHistoryData); // 创建一个新的列表,并将 realHistoryData 的内容复制过来 for (int i = 0; i < 15; i++) { var totalSumByTimePoint = currentlist .SelectMany(otdl => otdl.pumpOutWater) .GroupBy(totalDay => totalDay.DateTime.TimeOfDay) // 按照小时和分钟进行分组 .Select(group => { var time = group.First().DateTime.TimeOfDay; // 从组中获取时间 var totalSumForTimePoint = group.Sum(totalDay => totalDay.Total); // 在时间点分组中计算总和 return new { Time = time, Total = totalSumForTimePoint }; }); List demo = new List(); foreach (var item in totalSumByTimePoint) { listoutwater.Add(new TotalOneDay() { DateTime = currentlist.Last().DateTime.AddDays(1) + item.Time, Total = Math.Round(item.Total / currentlist.Count, 2) }); demo.Add(new TotalOneDay() { DateTime = currentlist.Last().DateTime.AddDays(1) + item.Time, Total = Math.Round(item.Total / currentlist.Count, 2) }); } currentlist.Add(new OutTotalOneDayList() { DateTime = currentlist.Last().DateTime.AddDays(1), pumpOutWater = demo }); currentlist.RemoveAt(0); demo = new List(); } return listoutwater; } } }