123
tangxu
2023-04-12 f980bc78ed10c45323a9c5edcf2441124de72241
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Calculation
{
    /// <summary>
    /// 能效依赖多时辅助类
    /// </summary>
    public class EtaAccordMultiHourHelper 
    {
 
        /// <summary>
        /// 依赖
        /// </summary>
        public static List<Model.EtaAccordMultiHourRecord> Accord
            (
                DateTime Day,
                IEnumerable<Model.EtaAccordConfigure> configures,
                IEnumerable<Model.EtaMultiRealRecord> list
            )
        {
            if (configures == null || configures.Count() < 1)
                return default;
            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 run_normal_list = run_list.Where(x => x.AnalyStatus == Model.Eta.eAnalyStatus.Normal).ToList();
            if (run_normal_list.Count < 1)
                return default;
 
            var dt_now = DateTime.Now;
            var record_list = new List<Model.EtaAccordMultiHourRecord>();
            foreach (var configure in configures)
            {
                if (configure.AccordType == Model.Eta.eAccordType.Q)
                {
                    //存在此区间范围内的数据
                    var run_normal_limit_list = run_normal_list.Where(t => t.Qa >= configure.LowerLimit && t.Qa <= configure.UpperLimit).ToList();
                    if (run_normal_limit_list != null && run_normal_limit_list.Count > 0)
                    {
                        for (int i = 0; i < 24; i++)
                        {
                            //此小时的此范围的所有运行点数据
                            var run_normal_limit_hour_list = run_normal_limit_list.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList();
                            if (run_normal_limit_hour_list.Count > 0)
                            {
                                //此小时的所有运行点数据
                                var run_normal_hour_list = run_normal_list.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList();
                                var record = new Model.EtaAccordMultiHourRecord();
                                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 = run_normal_limit_hour_list.Min(t => t.Qa.Value);
                                record.Qmax = run_normal_limit_hour_list.Max(t => t.Qa.Value);
                                record.Qavg = run_normal_limit_hour_list.Average(t => t.Qa.Value);
 
                                record.Emin = run_normal_limit_hour_list.Min(t => t.Ea.Value);
                                record.Emax = run_normal_limit_hour_list.Max(t => t.Ea.Value);
                                record.Eavg = run_normal_limit_hour_list.Average(t => t.Ea.Value);
 
                                record.Hmin = run_normal_limit_hour_list.Min(t => t.Ha.Value);
                                record.Hmax = run_normal_limit_hour_list.Max(t => t.Ha.Value);
                                record.Havg = run_normal_limit_hour_list.Average(t => t.Ha.Value);
 
                                record.Pmin = run_normal_limit_hour_list.Min(t => t.Pa.Value);
                                record.Pmax = run_normal_limit_hour_list.Max(t => t.Pa.Value);
                                record.Pavg = run_normal_limit_hour_list.Average(t => t.Pa.Value);
 
                                record.WPmin = run_normal_limit_hour_list.Min(t => t.WPa.Value);
                                record.WPmax = run_normal_limit_hour_list.Max(t => t.WPa.Value);
                                record.WPavg = run_normal_limit_hour_list.Average(t => t.WPa.Value);
 
                                record.UWPmin = run_normal_limit_hour_list.Min(t => t.UWPa.Value);
                                record.UWPmax = run_normal_limit_hour_list.Max(t => t.UWPa.Value);
                                record.UWPavg = run_normal_limit_hour_list.Average(t => t.UWPa.Value);
 
                                record.Qt = run_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 = run_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.RunTime = run_normal_limit_hour_list.Sum(t => t.Duration);
                                record.TotalRunTime = run_normal_hour_list.Sum(t => t.Duration);
 
                                record.PointCount = run_normal_limit_hour_list.Count;
                                record.TotalPointCount = run_normal_hour_list.Count;
 
                                record_list.Add(record);
                            }
                        }
                    }
                }
                else if (configure.AccordType == Model.Eta.eAccordType.E)
                {
                    //存在此区间范围内的数据
                    var run_normal_limit_list = run_normal_list.Where(t => t.Ea >= configure.LowerLimit && t.Ea <= configure.UpperLimit).ToList();
                    if (run_normal_limit_list != null && run_normal_limit_list.Count > 0)
                    {
                        for (int i = 0; i < 24; i++)
                        {
                            //此小时的此范围的所有运行点数据
                            var run_normal_limit_hour_list = run_normal_limit_list.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList();
                            if (run_normal_limit_hour_list.Count > 0)
                            {
                                //此小时的所有运行点数据
                                var run_normal_hour_list = run_normal_list.Where(t => t.DataTime >= Day.Date.AddHours(i) && t.DataTime < Day.Date.AddHours(i + 1)).ToList();
                                var record = new Model.EtaAccordMultiHourRecord();
                                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 = run_normal_limit_hour_list.Min(t => t.Qa.Value);
                                record.Qmax = run_normal_limit_hour_list.Max(t => t.Qa.Value);
                                record.Qavg = run_normal_limit_hour_list.Average(t => t.Qa.Value);
 
                                record.Emin = run_normal_limit_hour_list.Min(t => t.Ea.Value);
                                record.Emax = run_normal_limit_hour_list.Max(t => t.Ea.Value);
                                record.Eavg = run_normal_limit_hour_list.Average(t => t.Ea.Value);
 
                                record.Hmin = run_normal_limit_hour_list.Min(t => t.Ha.Value);
                                record.Hmax = run_normal_limit_hour_list.Max(t => t.Ha.Value);
                                record.Havg = run_normal_limit_hour_list.Average(t => t.Ha.Value);
 
                                record.Pmin = run_normal_limit_hour_list.Min(t => t.Pa.Value);
                                record.Pmax = run_normal_limit_hour_list.Max(t => t.Pa.Value);
                                record.Pavg = run_normal_limit_hour_list.Average(t => t.Pa.Value);
 
                                record.WPmin = run_normal_limit_hour_list.Min(t => t.WPa.Value);
                                record.WPmax = run_normal_limit_hour_list.Max(t => t.WPa.Value);
                                record.WPavg = run_normal_limit_hour_list.Average(t => t.WPa.Value);
 
                                record.UWPmin = run_normal_limit_hour_list.Min(t => t.UWPa.Value);
                                record.UWPmax = run_normal_limit_hour_list.Max(t => t.UWPa.Value);
                                record.UWPavg = run_normal_limit_hour_list.Average(t => t.UWPa.Value);
 
                                record.Qt = run_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 = run_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.RunTime = run_normal_limit_hour_list.Sum(t => t.Duration);
                                record.TotalRunTime = run_normal_hour_list.Sum(t => t.Duration);
 
                                record.PointCount = run_normal_limit_hour_list.Count;
                                record.TotalPointCount = run_normal_hour_list.Count;
 
                                record_list.Add(record);
                            }
                        }
                    }
                }
            }
            return record_list;
        }
 
    }
}