tangxu
2024-03-26 edd23f115dba31d764fdaf75a6207d888d0419d3
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
using IStation.CalcModel; 
using System;
using System.Collections.Generic;
using System.Data; 
using System.Linq; 
 
namespace IStation.Calc
{
    internal partial class ErQuCalcHelper_2_递归 : ErQuCalcBaseHelper
    {
        class BlockItemList
        {
            public List<RunBlock> Items { get; set; }
            public double TotalCompare;//功率或者电费(合计)
            public double TotalFlow; 
        }
 
 
 
 
        protected override List<AnaPrj> CalcOptPrjsCore()
        {
            _minTimeCountOpenPump = this.MinOpenPumpMinute / this.CalcSpaceMinute;
            _minTimeCountSwitch = this.MinSwitchPumpMinute / this.CalcSpaceMinute;
            //this._maxPumpSwitchCount = 5;
 
            if (_isHaveLevelLimit)
            {
                var result = CalcOptPrjsCore控制水位();
                if (result == null)
                    return null;
                return ToAnaPrj(result);
            }
            else
            {
                var result = CalcOptPrjsCore只考虑总流量();
                if (result == null)
                    return null;
                return ToAnaPrj(result);
            }
 
 
          
 
 
 
            //AnaPrj opt_prj = new AnaPrj();
            //opt_prj.BlockTimes = new List<AnaPrjBlockTime>();
            //opt_prj.PointTimes = new List<AnaPrjPointTime>();
            //opt_prj.ID = Guid.NewGuid().ToString("N");
            //opt_prj.StartTime = this._calStartTime;
            //opt_prj.EndTime = this._calEndTime;
 
            //double sumPower = 0, sumFlow = 0, sumMoney = 0;
            //foreach (var s in from x in result.Items orderby x.StartIndx select x)
            //{
            //    if (s.PumpCount == 0)
            //    {
            //        var itemSumDatas = new List<AnaPrjPointTime>();
            //        for (int i = s.StartIndx; i < s.EndIndx; i++)
            //        {
            //            itemSumDatas.Add(new AnaPrjPointTime(_timeList[i]));
            //        }
 
            //        opt_prj.BlockTimes.Add(new AnaPrjBlockTime()
            //        {
            //            StartTime = _timeList[s.StartIndx].Time,
            //            EndTime = _timeList[s.EndIndx].Time,
            //            OpenPumpCount = 0,
            //            //SumData = itemSumDatas
            //        });
            //    }
            //    else
            //    {
            //        var itemSumDatas = new List<AnaPrjPointTime>();
            //        var td = GetTimeDataBundle(s.PumpCount);
 
            //        for (int i = s.StartIndx; i < s.EndIndx; i++)
            //        {
            //            itemSumDatas.Add(new AnaPrjPointTime(_timeList[i],
            //                td.TimeDatas[i], s.PumpCount));
            //            sumPower += td.TimeDatas[i].SumPower;
            //            sumFlow += td.TimeDatas[i].SumFlow;
            //            sumMoney += td.TimeDatas[i].SumMoney;
            //        }
 
            //        opt_prj.BlockTimes.Add(new AnaPrjBlockTime()
            //        {
            //            StartTime = _timeList[s.StartIndx].Time,
            //            EndTime = _timeList[s.EndIndx].Time,
            //            OpenPumpCount = td.OpenPumpInfos.Count,
            //            //SumData = itemSumDatas
            //        });
            //    } 
            //}
            //if (double.IsNaN(sumMoney) || double.IsInfinity(sumMoney) || sumMoney == double.MaxValue)
            //    return null;
            //if (double.IsNaN(sumPower) || double.IsInfinity(sumPower) || sumPower == double.MaxValue)
            //    return null;
            //opt_prj.SumMoney = sumMoney;
            //opt_prj.SumFlow = sumFlow;
            //opt_prj.SumPower = sumPower;
 
 
            //OnShowDebugInfo.Invoke(string.Format("计算次数:{0:N0}, 缓存使用次数:{1:N0}", this._totalCalcCount, this._totalCacheCount));
 
 
            //var opt_prjs = new List<AnaPrj>();
            //opt_prjs.Add(opt_prj);
            //return opt_prjs;
        }
        private List<AnaPrj> ToAnaPrj(BlockItemList opt_bundle)
        {
            AnaPrj opt_prj = new AnaPrj();
            opt_prj.ID = Guid.NewGuid().ToString("N");
            opt_prj.StartTime = this._calStartTime;
            opt_prj.EndTime = this._calEndTime;
            opt_prj.BlockTimes = new List<AnaPrjBlockTime>();
            opt_prj.PointTimes = new List<AnaPrjPointTime>();
            opt_prj.CalcSpaceMinute = this.CalcSpaceMinute;
 
            var items = (from x in opt_bundle.Items orderby x.StartIndx select x).ToArray();
            int item_count = items.Count();
            for (int k = 0; k < item_count; k++)
            {
                var item = items[k];
 
                double sumPower_item = 0, sumFlow_item = 0, sumMoney_item = 0;
                var block_time = new AnaPrjBlockTime();
                block_time.StartTime = _timeList[item.StartIndx].Time;
                block_time.EndTime = _timeList[item.EndIndx].Time;
                block_time.OpenPumpCount = item.PumpCount;
 
                int last_index = item.EndIndx;
                //if (k == item_count - 1)
                //    last_index = item.EndIndx + 1;
                int start_indx = item.StartIndx  ;
 
 
                if (item.PumpCount == 0)
                {
                    for (int i = start_indx; i < last_index; i++)
                    {
                        var si = new AnaPrjPointTime(_timeList[i]);
                        //si.WaterLevelH = CalcReservoirHeight(_timeList[i].ReservoirDropFlowTotal, 0,
                        //    item.ReservoirStartHeight);
                        si.WaterLevelH = Math.Round(
item.ReservoirStartHeight +
(item.StartIndx - i) * (-item.ReservoirStartHeight + item.ReservoirEndHeight) / (item.StartIndx - item.EndIndx), 4);
 
                        opt_prj.PointTimes.Add(si);
                    }
                }
                else
                {
                    var td = GetTimeDataBundle(item.PumpCount);
 
                    for (int i = start_indx; i < last_index; i++)
                    {
                        var si = new AnaPrjPointTime(_timeList[i], td.TimeDatas[i], item.PumpCount);
                        si.WaterLevelH = Math.Round(
                item.ReservoirStartHeight +
                (item.StartIndx - i) * (-item.ReservoirStartHeight + item.ReservoirEndHeight) / (item.StartIndx - item.EndIndx), 4);
 
                        sumPower_item += td.TimeDatas[i].SumPower;
                        sumFlow_item += td.TimeDatas[i].SumFlow;
                        sumMoney_item += td.TimeDatas[i].SumMoney;
 
                        opt_prj.PointTimes.Add(si);
                    }
                }
 
                block_time.SumPower = sumPower_item;
                block_time.SumFlow = sumFlow_item;
                block_time.SumMoney = sumMoney_item;
            
                opt_prj.BlockTimes.Add(block_time);
            }
 
            double sumPower = 0, sumFlow = 0, sumMoney = 0;
            foreach (var item in opt_prj.BlockTimes)
            {
                sumPower += item.SumPower;
                sumFlow += item.SumFlow;
                sumMoney += item.SumMoney;
            }
            if (double.IsNaN(sumMoney) || double.IsInfinity(sumMoney) || sumMoney == double.MaxValue)
                return null;
            if (double.IsNaN(sumPower) || double.IsInfinity(sumPower) || sumPower == double.MaxValue)
                return null;
            opt_prj.SumMoney = sumMoney;
            opt_prj.SumFlow = sumFlow;
            opt_prj.SumPower = sumPower;
 
 
            OnShowDebugInfo.Invoke(string.Format("计算次数:{0:N0}, 缓存使用次数:{1:N0}", this._totalCalcCount, this._totalCacheCount));
 
 
            var opt_prjs = new List<AnaPrj>();
            opt_prjs.Add(opt_prj);
            return opt_prjs;
        }
 
    }
}