ningshuxia
2022-10-21 e2e1b847ac42b351e0bccd10dd753d1b8a6936ff
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
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;
        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:
                    {
                        var logicInfo = Calc一个泵站(context_item, _allStationBundles, 19);
                        _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>();//只含一级,不含下一集
 
            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());
                        }
                    }
                }
                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);
                }
            }
 
 
            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;
                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 (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)
                        {
                            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;
 
                    if (current_result.Pa != null)
                    {
                        if (!child_ana_records.Exists(x => !x.Ha.HasValue))
                        {
                            var haTatol = child_ana_records.Sum(x => x.Ha.Value);
                            uwpa = current_result.Pa.Value / qa_total / haTatol * 1000;
                        }
                        else
                        {
                            current_result.PutAnalyInfo(Model.EtaSingleRealRecordPure.InfoTag_Ha, null);
                        }
                    }
                    else
                    {
                        current_result.PutAnalyInfo(Model.EtaSingleRealRecordPure.InfoTag_Pa, null);
                    }
 
                    /* foreach (var item in child_ana_records)
                     {
                         if (item.UWPa.HasValue && item.Qa.HasValue && item.UWPa.Value > 0 && item.Qa.Value > 10)
                         {
                             uwpa += item.UWPa.Value * item.Qa.Value / qa_total;
                         }
                     }*/
 
                    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_result.AnalyInfo = null;
            }
 
            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;
        }
 
     
    }
}