ningshuxia
2022-11-17 112f6bf8aa6c76b055d19627ccef21fb59515436
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.EtaCalculation.SHYS
{
    internal partial class EtaAnalyCalculator4Logic
    {
        List<IStation.Calculation.Eta.Model.StationAnaInfoBundle> _allStationBundles = null;
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="allStationBundles"></param>
        public void AnaContext(IStation.Model.EtaCorpAnalyContext context, List<IStation.Calculation.Eta.Model.StationAnaInfoBundle> allStationBundles)
        {
            this._allStationBundles = allStationBundles;
            foreach (var logicCatalogContextItem in context.LogicCatalogContextItems)
            {
                if (logicCatalogContextItem.UseStatus != IStation.Model.eUseStatus.Enable)
                {
                    continue;
                }
 
                foreach (var node in logicCatalogContextItem.LogicTreeContextItems)
                {
                    AnaLogic(node);
                }
            }
        }
 
        private IStation.Calculation.Eta.Model.LogicAnaInfoBundle AnaLogic(IStation.Model.EtaLogicTreeAnalyContextItem context_item)
        {
            var logic_area = context_item.LogicContextItem as IStation.Model.EtaLogicAreaAnalyContextItem;
 
            switch (logic_area.ID)
            {
                case 4:
                    {
                        var logicInfo = Calc一个泵站(context_item, _allStationBundles, 3);
                        _allLogicRecordList.Add(logicInfo.AnaResult);
                        return logicInfo;
                    }
                case 5:
                    {
                        var logicInfo = Calc一个泵站(context_item, _allStationBundles, 5);
                        _allLogicRecordList.Add(logicInfo.AnaResult);
                        return logicInfo;
                    }
                case 6:
                    {
                        var logicInfo = Calc一个泵站(context_item, _allStationBundles, 9);
                        _allLogicRecordList.Add(logicInfo.AnaResult);
                        return logicInfo;
                    }
                case 11:
                    {
                        var logicInfo = Calc一个泵站(context_item, _allStationBundles, 16);
                        _allLogicRecordList.Add(logicInfo.AnaResult);
                        return logicInfo;
                    }
                case 13:
                    {
                        //金泽联通管
                        if (this.jzltgLogicAnaInfoBundle == null)
                        {
                            this.jzltgLogicAnaInfoBundle = Calc一个泵站(context_item, _allStationBundles, 19);
                            _allLogicRecordList.Add(this.jzltgLogicAnaInfoBundle.AnaResult);
                        }
                        return this.jzltgLogicAnaInfoBundle;
                    }
                case 12:
                    {
                        var logicInfo = AnaLogic金泽系统(context_item);
                        _allLogicRecordList.Add(logicInfo.AnaResult);
                        return logicInfo;
                    }
            }
 
            var current_logic_ana = new Calculation.Eta.Model.LogicAnaInfoBundle();
            current_logic_ana.LogicID = logic_area.ID;
            current_logic_ana.ChildStationBundleList = new List<Calculation.Eta.Model.StationAnaInfoBundle>();
            current_logic_ana.ChildLogicBundleList = new List<Calculation.Eta.Model.LogicAnaInfoBundle>();
            List<IStation.Model.EtaBasicRealRecord> child_ana_records = new List<Model.EtaBasicRealRecord>();//只含一级,不含下一集
 
            double uwpaSum = 0;
            double qSum = 0;
            IStation.Model.EtaLogicRealRecordPure current_result = new Model.EtaLogicRealRecordPure();
            foreach (var child in context_item.Children)
            {
                if (child.IsStation())
                {
                    var station_ana = this._allStationBundles.Find(x => x.StationID == child.ObjectID);
                    if (station_ana == null)
                    {
                        continue;
                    }
                    current_logic_ana.ChildStationBundleList.Add(station_ana);
                    child_ana_records.Add(station_ana.AnaResult);
 
                    if (!string.IsNullOrEmpty(station_ana.AnaResult?.AnalyInfo))
                    {
                        if (!current_result.IsHaveStationTag(station_ana.StationID))
                        {
                            current_result.PutAnalyInfo(Model.EtaSingleRealRecordPure.InfoTag_Station, station_ana.StationID.ToString());
                        }
                    }
 
 
                    uwpaSum += (station_ana.AnaResult.Qa ?? 0) * (station_ana.AnaResult.UWPa ?? 0);
                    qSum += station_ana.AnaResult.Qa ?? 0;
                }
                else
                {
                    var child_logic_ana = AnaLogic(child);
                    current_logic_ana.ChildLogicBundleList.Add(child_logic_ana);
                    current_result.PutLogicAnalyInfo(child_logic_ana.AnaResult?.AnalyInfo);
                    child_ana_records.Add(child_logic_ana.AnaResult);
 
                    var q = GetQSumValue(child_logic_ana);
                    qSum += q;
                    uwpaSum += q * child_logic_ana.AnaResult.UWPa ?? 0;
                }
            }
 
 
            current_result.CorpID = 0;
            current_result.ObjectType = IStation.ObjectType.LogicArea;
            current_result.ObjectID = logic_area.ID;
            if (child_ana_records.Count() == 0)
            {
                current_result.Qa = 0;
                current_result.Ha = 0;
                current_result.Pa = 0;
                current_result.Ea = 0;
                current_result.WPa = 0;
                current_result.UWPa = 0;
                current_result.AnalyStatus = Model.Eta.eAnalyStatus.Normal;
            }
            else
            {
                current_result.Qa = Math.Round((from x in child_ana_records where (x.Qa.HasValue && x.Qa.Value > 10) select x.Qa.Value).Sum(), 1);//暂时取合计值
                current_result.Ha = Math.Round((from x in child_ana_records where x.Ha.HasValue select x.Ha.Value).Sum(), 2);//暂时取合计值
                current_result.Pa = Math.Round((from x in child_ana_records where x.Pa.HasValue select x.Pa.Value).Sum(), 1);//暂时取合计值
 
 
 
                double qa_total = 0;
                double qh_total = 0;
                foreach (var item in child_ana_records)
                {
                    if (item.Ea.HasValue && item.Qa.HasValue && item.Ea.Value > 10 && item.Qa.Value > 10)
                    {
                        qa_total += item.Qa.Value;
                        if (item.Ha.HasValue)
                        {
                            qh_total += item.Qa.Value * item.Ha.Value;
                        }
                    }
                }
 
                if (qa_total > 100)
                {
                    double eta = 0;
                    foreach (var item in child_ana_records)
                    {
                        if (item.Ea.HasValue && item.Qa.HasValue && item.Ea.Value > 10 && item.Qa.Value > 10)
                        {
                            if (item.Ha.HasValue && item.Ha.Value != 0)
                            {
                                eta += item.Ea.Value * (item.Qa.Value * item.Ha.Value / qh_total);//叠加扬程换算
                            }
 
                            // eta += item.Ea.Value * item.Qa.Value / qa_total; 旧算法
                        }
                    }
 
                    double wpa = 0;
                    foreach (var item in child_ana_records)
                    {
                        if (item.WPa.HasValue && item.Qa.HasValue && item.WPa.Value > 0 && item.Qa.Value > 10)
                        {
                            wpa += item.WPa.Value * item.Qa.Value / qa_total;
                        }
                    }
                     
                    double uwpa = 0;
                    uwpa = uwpaSum / qSum;
                     
 
                    current_result.Ea = Math.Round(eta, 1);
                    current_result.WPa = Math.Round(wpa, 2);
                    current_result.UWPa = Math.Round(uwpa, 2);
                }
                else
                {
                    current_result.Ea = 0;
                    current_result.WPa = 0;
                    current_result.UWPa = 0;
                }
                current_result.AnalyStatus = Model.Eta.eAnalyStatus.Normal;
            }
 
            current_logic_ana.AnaResult = current_result;
 
            if (current_result != null)
                _allLogicRecordList.Add(current_result);
 
            return current_logic_ana;
        }
 
 
        List<Model.EtaLogicRealRecordPure> _allLogicRecordList = new List<Model.EtaLogicRealRecordPure>();
        internal List<Model.EtaLogicRealRecordPure> GetAllLogicAnaRecord()
        {
            return _allLogicRecordList;
        }
 
        private double GetUwpaSumValue(Calculation.Eta.Model.LogicAnaInfoBundle eta)
        {
            double uwpaSum = 0;
            var childStationBundleList = eta.ChildStationBundleList;
            if (childStationBundleList != null && childStationBundleList.Count > 0)
            {
                foreach (var item in childStationBundleList)
                {
                    var reulst = item.AnaResult;
                    uwpaSum += (reulst.UWPa ?? 0) * (reulst.Qa ?? 0);
                }
            }
 
            if (eta.ChildLogicBundleList != null && eta.ChildLogicBundleList.Count > 0)
            {
                foreach (var logic in eta.ChildLogicBundleList)
                {
                    uwpaSum += GetUwpaSumValue(logic);
                }
            }
 
            return uwpaSum;
        }
 
 
 
        private double GetQSumValue(Calculation.Eta.Model.LogicAnaInfoBundle eta)
        {
            double qSum = 0;
            var childStationBundleList = eta.ChildStationBundleList;
            if (childStationBundleList != null && childStationBundleList.Count > 0)
            {
                foreach (var item in childStationBundleList)
                {
                    var reulst = item.AnaResult;
                    qSum += reulst.Qa ?? 0;
                }
            }
 
            if (eta.ChildLogicBundleList != null && eta.ChildLogicBundleList.Count > 0)
            {
                foreach (var logic in eta.ChildLogicBundleList)
                {
                    qSum += GetUwpaSumValue(logic);
                }
            }
 
            return qSum;
        }
 
    }
}