duheng
2024-03-26 bb006801e4d7fc281e8c1b43ab4b7b83da044ab6
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
using IStation.CalcModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
 
 
namespace IStation.Calc
{
    internal partial class ErQuCalcBaseHelper
    { 
        protected int _timeDataListCount = 0; 
        protected List<TimePoint> _timeList;
        protected double GetReservoirDropFlowTotalByTimeIndex(int time_index)
        {
            if (time_index >= _timeDataListCount)
                return _timeList.Last().ReservoirDropFlowTotal;
            return _timeList[time_index].ReservoirDropFlowTotal;
        }
        internal IStation.CalcModel.TimeDataBundle _timeDataListOpen1;
        internal IStation.CalcModel.TimeDataBundle _timeDataListOpen2;
        internal IStation.CalcModel.TimeDataBundle _timeDataListOpen3;
        internal IStation.CalcModel.TimeDataBundle _timeDataListOpen4;
        internal IStation.CalcModel.TimeDataBundle GetTimeDataBundle(int PumpCount)
        {
            if (PumpCount == 0)
            {
                return null;
            }
            if (PumpCount == 1)
            {
                return _timeDataListOpen1;
            }
            if (PumpCount == 2)
            {
                return _timeDataListOpen2;
            }
            if (PumpCount == 3)
            {
                return _timeDataListOpen3;
            }
            if (PumpCount == 4)
            {
                return _timeDataListOpen4;
            }
            return null;
        }
 
 
        /// <summary>
        /// 导出实时数据
        /// </summary>
        /// <param name="error_info"></param>
        /// <returns></returns>
        public bool ExportTimeData(string file_path, out string error_info)
        {
            error_info = null;
 
            #region 检查数据
            if (this._calStartTime >= this._calEndTime)
            {
                error_info = "时间范围不对";
                return false;
            }
            if (this._allPumpInfo == null || this._allPumpInfo.Count() != 5)
            {
                error_info = "泵台数不正确";
                return false;
            }
            if (this._riverWaterLevels == null || this._riverWaterLevels.Count() < 1)
            {
                error_info = "长江水位未赋值";
                return false;
            }
 
            if (_listRiverWaterLevelDrop == null)
            {
                _listRiverWaterLevelDrop = IStation.AnaGlobalParas.RiverWaterLevelDropList;
                if (_listRiverWaterLevelDrop == null || _listRiverWaterLevelDrop.Count() == 0)
                {
                    error_info = "无法读取长江水位与水池落差的关系数据";
                    return false;
                }
            }
 
            #endregion
 
 
 
 
            //
            int dd_minute = 0;
            CalcTimeData(dd_minute);
 
 
 
 
            StreamWriter streamWriter = new StreamWriter(file_path, false, System.Text.Encoding.GetEncoding("gb2312"));
 
            StringBuilder StringBuilder = new StringBuilder();
            // 写出表头 
            StringBuilder.AppendFormat("{0},{1},{2},{3},{4} ",
                "时间",
                "1台时前池水位",
                "1台时水量",
                "1台时电量",
                "1台时电费");
 
            StringBuilder.AppendFormat(",{0},{1},{2},{3}",
                "2台时前池水位",
                "2台时水量",
                "2台时电量",
                "2台时电费");
 
 
            StringBuilder.AppendFormat(",{0},{1},{2},{3}",
                "3台时前池水位",
                "3台时水量",
                "3台时电量",
                "3台时电费");
 
            StringBuilder.AppendFormat(",{0},{1},{2},{3}",
                "4台时前池水位",
                "4台时水量",
                "4台时电量",
                "4台时电费");
 
            // 写出数据
            for (int i = 0; i < _timeDataListOpen1.TimeDatas.Count; i++)
            {
                StringBuilder.AppendLine();
                StringBuilder.AppendFormat("{0},{1},{2},{3},{4} ",
                    _timeList[i],
                    _timeDataListOpen1.TimeDatas[i].WaterLevelQ,
                    _timeDataListOpen1.TimeDatas[i].SumFlow,
                    _timeDataListOpen1.TimeDatas[i].SumPower,
                    _timeDataListOpen1.TimeDatas[i].SumMoney);
 
                StringBuilder.AppendFormat(",{0},{1},{2},{3}",
                    _timeDataListOpen2.TimeDatas[i].WaterLevelQ,
                    _timeDataListOpen2.TimeDatas[i].SumFlow,
                    _timeDataListOpen2.TimeDatas[i].SumPower,
                    _timeDataListOpen2.TimeDatas[i].SumMoney);
 
 
                StringBuilder.AppendFormat(",{0},{1},{2},{3}",
                    _timeDataListOpen3.TimeDatas[i].WaterLevelQ,
                    _timeDataListOpen3.TimeDatas[i].SumFlow,
                    _timeDataListOpen3.TimeDatas[i].SumPower,
                    _timeDataListOpen3.TimeDatas[i].SumMoney);
 
                StringBuilder.AppendFormat(",{0},{1},{2},{3}",
                    _timeDataListOpen4.TimeDatas[i].WaterLevelQ,
                    _timeDataListOpen4.TimeDatas[i].SumFlow,
                    _timeDataListOpen4.TimeDatas[i].SumPower,
                    _timeDataListOpen4.TimeDatas[i].SumMoney);
 
            }
            streamWriter.Write(StringBuilder.ToString());
 
            streamWriter.Flush();
            streamWriter.Close();
            return true;
        }
 
        //protected List<int> _defaultOpenPumpIndex1, _defaultOpenPumpIndex2, _defaultOpenPumpIndex3, _defaultOpenPumpIndex4;
        /// <summary>
        /// 计算时序数据
        /// </summary>
        /// <param name="dd_minute"></param>
        protected void CalcTimeData(int dd_minute)
        {
            //时间段
            _timeList = new List<TimePoint>();
            for (var time = _calStartTime; time <= this._calEndTime; time = time.AddMinutes(this._calcSpaceMinute))
            {
                var t = new TimePoint(time);
                t.WaterLevelC = IStation.Calc.ErQuCalcBaseHelper.GetRiverWaterLevelByTime(
                    this._riverWaterLevels, time);
 
                _timeList.Add(t);
            }
            _timeDataListCount = _timeList.Count();
 
 
            //是否受限  
            if (_limitSwitchPumpTimes != null)
            {
                for (int i = 0; i < _timeDataListCount; i++)
                {
                    var time = _timeList[i].Time;
                    bool isSwitchPump = true;
                    foreach (var s in _limitSwitchPumpTimes)
                    {
                        if (time >= s.Start && time <= s.End)
                        {
                            isSwitchPump = false;
                            break;
                        }
                    }
                    _timeList[i].IsSwitchPumpAble = isSwitchPump;
                }
            }
 
 
 
 
            //
            CalcReservoirTimeData();
 
 
 
 
 
 
 
 
 
            //根据同扬程下 流量从大到小的泵 2->5->3->1->4   
 
            _timeDataListOpen4 = new IStation.CalcModel.TimeDataBundle();
            _timeDataListOpen4.TimeDatas = new List<StationTimeData>(_timeDataListCount);
            //if(_defaultOpenPumpIndex4 != null && _defaultOpenPumpIndex4.Count() == 4)
            //{
            //    _timeDataListOpen4.OpenPumpInfos = new List<PumpCurveInfo> { 
            //        this._allPumpInfo[_defaultOpenPumpIndex4[0]], 
            //        this._allPumpInfo[_defaultOpenPumpIndex4[1]], 
            //        this._allPumpInfo[_defaultOpenPumpIndex4[2]], 
            //        this._allPumpInfo[_defaultOpenPumpIndex4[3]] }; 
            //}
            //else
            {
                _timeDataListOpen4.OpenPumpInfos = new List<IStation.CalcModel.PumpCurveInfo> { this._allPumpInfo[1], this._allPumpInfo[4], this._allPumpInfo[2], this._allPumpInfo[0] };
            }
            CalcTimeDataList(dd_minute, ref _timeDataListOpen4);
 
 
 
 
            _timeDataListOpen3 = new IStation.CalcModel.TimeDataBundle();
            _timeDataListOpen3.TimeDatas = new List<StationTimeData>(_timeDataListCount);
            //if (_defaultOpenPumpIndex3 != null && _defaultOpenPumpIndex3.Count() == 3)
            //{
            //    _timeDataListOpen3.OpenPumpInfos = new List<PumpCurveInfo> {
            //        this._allPumpInfo[_defaultOpenPumpIndex3[0]],
            //        this._allPumpInfo[_defaultOpenPumpIndex3[1]],
            //        this._allPumpInfo[_defaultOpenPumpIndex3[2]]  };
            //}
            //else
            {
                _timeDataListOpen3.OpenPumpInfos = new List<IStation.CalcModel.PumpCurveInfo> { this._allPumpInfo[1], this._allPumpInfo[4], this._allPumpInfo[2] };
            }
            CalcTimeDataList(dd_minute, ref _timeDataListOpen3);
 
 
 
 
            _timeDataListOpen2 = new IStation.CalcModel.TimeDataBundle();
            _timeDataListOpen2.TimeDatas = new List<StationTimeData>(_timeDataListCount);
            //if (_defaultOpenPumpIndex2 != null && _defaultOpenPumpIndex2.Count() == 2)
            //{
            //    _timeDataListOpen2.OpenPumpInfos = new List<PumpCurveInfo> {
            //        this._allPumpInfo[_defaultOpenPumpIndex2[0]],
            //        this._allPumpInfo[_defaultOpenPumpIndex2[1]]  };
            //}
            //else
            {
                _timeDataListOpen2.OpenPumpInfos = new List<IStation.CalcModel.PumpCurveInfo> { this._allPumpInfo[1], this._allPumpInfo[4] };
            }
            CalcTimeDataList(dd_minute, ref _timeDataListOpen2);
 
 
 
 
            _timeDataListOpen1 = new IStation.CalcModel.TimeDataBundle();
            _timeDataListOpen1.TimeDatas = new List<StationTimeData>(_timeDataListCount);
            //if (_defaultOpenPumpIndex1 != null && _defaultOpenPumpIndex1.Count() == 1)
            //{
            //    _timeDataListOpen1.OpenPumpInfos = new List<PumpCurveInfo> {
            //        this._allPumpInfo[_defaultOpenPumpIndex1[0]]  };
            //}
            //else
            {
                _timeDataListOpen1.OpenPumpInfos = new List<IStation.CalcModel.PumpCurveInfo> { this._allPumpInfo[1] };
            }
 
            CalcTimeDataList(dd_minute, ref _timeDataListOpen1);
        }
 
        internal void CalcTimeDataList(int dd_minute, ref IStation.CalcModel.TimeDataBundle timeDataList)
        {
            if (timeDataList.TimeDatas == null)
                timeDataList.TimeDatas = new List<StationTimeData>(_timeDataListCount);
 
            int openPumpCount = timeDataList.OpenPumpInfos.Count;
            double dropHeight1 = GetDropHeightByPumpCount(openPumpCount);
 
            //timeData.PumpDatas = new List<TimeData.PumpData>(timeDataList.OpenPumpInfos.Count());
            bool isLimitOpenPumpTime = false;
            if (_limitOpenPumpTimes != null && _limitOpenPumpTimes.Count > 0)
            {
                isLimitOpenPumpTime = true;
            }
               
            for (int t = 0; t < _timeDataListCount; t++)
            {
                StationTimeData timeData = new StationTimeData();
                timeData.PumpDatas = new List<PumpTimeData>(5);
                for (int pu = 0; pu < 5; pu++)
                {
                    timeData.PumpDatas.Add(new PumpTimeData());
                }
 
 
                var time = this._timeList[t].Time;
                var m2 = CalcPumpOutletPressM(time);
                var riverWaterLevel = GetRiverWaterLevelByTime(time);//长江水位
                double dropHeight前池 = dropHeight1;
                double head4Drop = 0;//扬程
                for (int i = 0; i < 3; i++)
                {
                    head4Drop = m2 - (riverWaterLevel - dropHeight前池);
                    //不断迭代 计算扬程, 因为流量变量会造成吸水高度差变化, 从而造成扬程有变化
                    double totalFlow4drop = 0;
                    foreach (var pump_curve in timeDataList.OpenPumpInfos)
                    {
                        var grpPt = pump_curve.GetPointByH(head4Drop);
                        if (grpPt == null)
                        {
                            throw new Exception("出现特殊情况,未考虑!");
                        }
                        totalFlow4drop += grpPt.Q;
                    }
 
                    dropHeight前池 = GetDropHeightByFlow(totalFlow4drop);
                }
 
 
 
 
 
 
 
                double realHead = head4Drop;
                double totalFlow = 0;
                double totalPower = 0;
                foreach (var pump_curve in timeDataList.OpenPumpInfos)
                {
                    var indx = pump_curve.PumpIndex;
 
                    var pumpData = timeData.PumpDatas[indx];
 
                    pumpData.Head = realHead;
                    var grpPt2 = pump_curve.GetPointByH(realHead);
                    if (grpPt2 == null)
                    {
                        throw new Exception("出现特殊情况,未考虑!");
                    }
                    pumpData.Flow = grpPt2.Q;
                    pumpData.Power = grpPt2.P;
                    pumpData.SumFlow = Math.Round(pumpData.Flow * this._calcSpaceMinute / 60, 1);
                    pumpData.SumPower = Math.Round(pumpData.Power * this._calcSpaceMinute / 60, 1);
                    pumpData.SumMoney = Math.Round(CalcMoney(time, pumpData.Power) * this._calcSpaceMinute / 60, 1);
 
 
                    totalFlow += grpPt2.Q;
                    totalPower += grpPt2.P;
                }
 
                timeData.WaterLevelQ = riverWaterLevel - dropHeight前池;
 
 
                timeData.Head = realHead;
                timeData.Flow = Math.Round(totalFlow, 1);
                timeData.Power = Math.Round(totalPower, 1);
 
                timeData.SumFlow = Math.Round(totalFlow * this._calcSpaceMinute / 60, 1);
                timeData.SumPower = Math.Round(totalPower * this._calcSpaceMinute / 60, 1);
                timeData.SumMoney = Math.Round(CalcMoney(time, totalPower) * this._calcSpaceMinute / 60, 1);
 
                if (isLimitOpenPumpTime)
                {
                    foreach (var lt in _limitOpenPumpTimes)
                    {
                        if (time >= lt.Start && time < lt.End)
                        {
                            timeData.Power = double.MaxValue;
                            timeData.SumFlow = 0;
                            timeData.SumPower = double.MaxValue;
                            timeData.SumMoney = double.MaxValue;
                        }
                    }
                }
 
                timeDataList.TimeDatas.Add(timeData);
            }
 
            //缓存用
            // timeDataList.InitialSpanCache( );
            timeDataList.CalcSpanCache(this._clacOptType);
        }
    }
}