duheng
8 天以前 4de480ec624d3b79ca690dc906e10cd2fbdc9be7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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<SSAData> GetMeanValue(List<OutTotalOneDayList> realHistoryData)
        {
            List<SSAData> listoutwater = new List<SSAData>();
            List<OutTotalOneDayList> currentlist = new List<OutTotalOneDayList>(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<SSAData> demo = new List<SSAData>();
                foreach (var item in totalSumByTimePoint)
                {
                    listoutwater.Add(new SSAData() { DateTime = currentlist.Last().DateTime.AddDays(1) + item.Time, Total = Math.Round(item.Total / currentlist.Count, 2) });
                    demo.Add(new SSAData() { 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<SSAData>();
            }
            return listoutwater;
        }
    }
}