ningshuxia
2022-12-01 ad494f13d2ddf31f142cf7fb908b3a6e90395a1a
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IStation.Untity;
 
namespace IStation.Calculation 
{
    /// <summary>
    /// 能效汇总多时辅助类
    /// </summary>
    public class EtaSumMultiHourHelper
    {
        /// <summary>
        /// 汇总
        /// </summary>
        /// <returns></returns>
        public static List<Model.EtaSumMultiHourRecord> Sum
            (
                long CorpID,
                string ObjectType,
                long ObjectID,
                DateTime Day,
                IEnumerable<Model.EtaMultiRealRecord> list
            )
        {
            if (list == null || list.Count() < 1)
                return default;
            var run_list = list.Where(x =>x.RunningCount>0).ToList();
            if (run_list.Count < 1)
                return default;
            var group_list = run_list.GroupBy(x => new {
                CorpID = x.CorpID,
                ObjectType = x.ObjectType,
                ObjectID = x.ObjectID,
                RunningCount = x.RunningCount,
                RunningFlag = IntListHelper.ToString(x.RunningFlag)
            }).ToList();
 
            var result = new List<Model.EtaSumMultiHourRecord>();
            foreach (var group in group_list)
            {
                for (int i = 0; i < 24; i++)
                {
                    var run_hour_list = group.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList();
                    var run_normal_hour_list = run_hour_list.Where(t => t.AnalyStatus == Model.Eta.eAnalyStatus.Normal).ToList();
 
                    var model = new Model.EtaSumMultiHourRecord();
                    model.CorpID = CorpID;
                    model.ObjectType = ObjectType;
                    model.ObjectID = ObjectID;
                    model.DataDay = Day.Date;
                    model.DataHour = i + 1;
                    model.DataTime = DateTime.Now;
                    model.RunningCount = group.Key.RunningCount;
                    model.RunningFlag = IntListHelper.ToList(group.Key.RunningFlag);
                    model.Qt = run_hour_list.Sum(x => (x.Qa ?? 0) * x.Duration) / 3600f;
                    model.Dt = run_hour_list.Sum(x => (x.Pa ?? 0) * x.Duration) / 3600f;
                    model.RunTime = run_hour_list.Sum(x => x.Duration);
                    model.PointCount = run_hour_list.Count;
 
                    if (run_normal_hour_list.Count > 0)
                    {
                        model.Qmin = run_normal_hour_list.Min(x => x.Qa.Value);
                        model.Qmax = run_normal_hour_list.Max(x => x.Qa.Value);
                        model.Qavg = run_normal_hour_list.Average(x => x.Qa.Value);
 
                        model.Hmin = run_normal_hour_list.Min(x => x.Ha.Value);
                        model.Hmax = run_normal_hour_list.Max(x => x.Ha.Value);
                        model.Havg = run_normal_hour_list.Average(x => x.Ha.Value);
 
                        model.Emin = run_normal_hour_list.Min(x => x.Ea.Value);
                        model.Emax = run_normal_hour_list.Max(x => x.Ea.Value);
                        model.Eavg = run_normal_hour_list.Average(x => x.Ea.Value);
 
                        model.Pmin = run_normal_hour_list.Min(x => x.Pa.Value);
                        model.Pmax = run_normal_hour_list.Max(x => x.Pa.Value);
                        model.Pavg = run_normal_hour_list.Average(x => x.Pa.Value);
 
                        model.WPmin = run_normal_hour_list.Min(x => x.WPa.Value);
                        model.WPmax = run_normal_hour_list.Max(x => x.WPa.Value);
                        model.WPavg = run_normal_hour_list.Average(x => x.WPa.Value);
 
                        model.UWPmin = run_normal_hour_list.Min(x => x.UWPa.Value);
                        model.UWPmax = run_normal_hour_list.Max(x => x.UWPa.Value);
                        model.UWPavg = run_normal_hour_list.Average(x => x.UWPa.Value);
                    }
 
                    result.Add(model);
                }
            }
 
 
 
            return result;
        }
 
 
 
    }
}