ningshuxia
2025-03-31 d321346f204a69b1929cc39098a5d88f44509e7b
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
 
namespace IStation.WinFrmUI.Monitor
{
    public partial class DataVerificationPage : DocumentPage
    {
        public DataVerificationPage()
        {
            InitializeComponent();
            PageTitle.Caption = "数据验证";
 
            gridView1.SetNormalView();
            gridView2.SetNormalView();
            gridView3.SetNormalView();
            gridView4.SetNormalView();
            gridView5.SetNormalView();
 
            colYearMonth.Visible = false;
            colTime.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            colTime.DisplayFormat.FormatString = "G";
 
            colTime1.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            colTime1.DisplayFormat.FormatString = "G";
 
            colTime2.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            colTime2.DisplayFormat.FormatString = "G";
 
            stationListCtrl1.FocusedChangedEvent += StationListCtrl1_FocusedChangedEvent;
            monitorDataSourcesTreeList1.FocusedChangedEvent += MonitorDataSourcesListCtrl1_FocusedChangedEvent;
 
        }
 
        #region ViewModel
 
        public class CombineStatisticsViewModel
        {
            [Display(Name = "年月")]
            public string YearMonth { get; set; }
 
            [Display(Name = "时间")]
            public DateTime Time { get; set; }
 
            [Display(Name = "运行工况")]
            public string RunFlags { get; set; }
 
            [Display(Name = "转速")]
            public string RpmList { get; set; }
 
            [Display(Name = "扬程")]
            public string HeadList { get; set; }
 
            [Display(Name = "出口压力")]
            public string OutletPressureList { get; set; }
 
            [Display(Name = "总流量")]
            public double TotalFlow { get; set; }
 
            [Display(Name = "总功率")]
            public double TotalPower { get; set; }
        }
 
        public class CombineMeterDeviationViewModel
        {
            [Display(Name = "运行工况")]
            public string RunFlags { get; set; }
 
            [Display(Name = "转速")]
            public string RpmList { get; set; }
 
            [Display(Name = "出口")]
            public string OutletList { get; set; }
 
            [Display(Name = "流量偏差")]
            public double FlowDeviation { get; set; }
 
            [Display(Name = "功率偏差")]
            public double PowerDeviation { get; set; }
 
            [Display(Name = "数据列表")]
            public List<CombineStatisticsViewModel> RecordList { get; set; }
 
            [Display(Name = "数据量")]
            public int RecordCount { get; set; }
        }
 
        public class PumpViewModel
        {
            [Display(Name = "时间")]
            public DateTime Time { get; set; }
 
            [Display(Name = "泵")]
            public int Flag { get; set; }
 
            [Display(Name = "转速")]
            public double Rpm { get; set; }
 
            [Display(Name = "水位")]
            public double WaterLevel { get; set; }
 
            [Display(Name = "进口压力")]
            public double InletPressure { get; set; }
 
            [Display(Name = "出口压力")]
            public double OutletPressure { get; set; }
 
            [Display(Name = "扬程")]
            public double Head { get; set; }
 
            [Display(Name = "瞬时流量")]
            public double Flow { get; set; }
 
            [Display(Name = "瞬时功率")]
            public double Power { get; set; }
 
        }
 
        public class PumpMeterDeviationViewModel
        {
            [Display(Name = "泵")]
            public int Flag { get; set; }
 
            [Display(Name = "转速")]
            public double Rpm { get; set; }
 
            [Display(Name = "出口")]
            public double Outlet { get; set; }
 
            [Display(Name = "流量偏差")]
            public double FlowDeviation { get; set; }
 
            [Display(Name = "功率偏差")]
            public double PowerDeviation { get; set; }
 
            [Display(Name = "数据列表")]
            public List<PumpViewModel> RecordList { get; set; }
 
            [Display(Name = "数据量")]
            public int RecordCount { get; set; }
 
        }
        #endregion
 
        private BLL.StationSignalRecordPacket _bll = new BLL.StationSignalRecordPacket();
        private Model.Station _station = null;
        private Model.MonitorDataSources _monitorDataSources = null;
 
        /// <summary>
        /// 清空数据
        /// </summary>
        public void Clear()
        {
            combineStatisticsViewModelBindingSource.DataSource = new List<CombineStatisticsViewModel>();
            combineMeterDeviationViewModelBindingSource.DataSource = new List<CombineMeterDeviationViewModel>();
 
            pumpViewModelBindingSource.DataSource = new List<PumpViewModel>();
            pumpMeterDeviationViewModelBindingSource.DataSource = new List<PumpMeterDeviationViewModel>();
 
            pumpViewModelBindingSource1.DataSource = new List<PumpViewModel>();
        }
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            stationListCtrl1.SetBindingData();
            monitorDataSourcesTreeList1.SetBindingData();
        }
 
        //泵站变换
        private void StationListCtrl1_FocusedChangedEvent(Model.Station obj)
        {
            _station = obj;
            SetBindingData(_monitorDataSources, _station);
        }
 
        //来源变换
        private void MonitorDataSourcesListCtrl1_FocusedChangedEvent(Model.MonitorDataSources obj)
        {
            _monitorDataSources = obj;
            SetBindingData(_monitorDataSources, _station);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(Model.MonitorDataSources monitorDataSources, Model.Station station)
        {
            Clear();
            if (monitorDataSources == null || station == null)
            {
                return;
            }
            if (barCekLoad.Checked)
            {
                return;
            }
            var packets = _bll.Get(_monitorDataSources.ID, _station.ID);
            SetBindingData(packets);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(List<Model.StationSignalRecordPacket> packets)
        {
            WaitFrmHelper.ShowWaitForm();
            var vm_combine_list = new List<CombineStatisticsViewModel>();
            var vm_combine_meter_dev_list = new List<CombineMeterDeviationViewModel>();
 
            var vm_pump_list = new List<PumpViewModel>();
            var vm_pump_meter_dev_list = new List<PumpMeterDeviationViewModel>();
            if (packets != null && packets.Any())
            {
                foreach (var packet in packets)
                {
                    var station_signal_records = packet.StationSignalRecords;
                    if (station_signal_records == null || !station_signal_records.Any())
                        continue;
                    var year_month = $"{packet.Year}-{packet.Month}";
                    foreach (var record in station_signal_records)
                    {
                        var pump_signal_records = record.PumpSignalRecords;
                        if (pump_signal_records == null || !pump_signal_records.Any())
                            continue;
                        pump_signal_records = pump_signal_records.OrderBy(x => x.Flag).ToList();
 
                        var total_power = pump_signal_records.Sum(x => x.InstantaneousPower);
                        var run_flags = pump_signal_records.Select(x => x.Flag).ToList();
                        var rpm_list = pump_signal_records.Select(x =>
                        {
                            if (x.Rpm == 0 && (x.Flag == 15 || x.Flag == 16))
                            {
                                return 590;
                            }
                            return x.Rpm;
                        }).ToList();
                        var outlet_pressure_list = pump_signal_records.Select(x =>
                        {
                            return x.OutletPressure;
                        }).ToList();
                        var head_list = pump_signal_records.Select(x =>
                        {
                            return x.Head;
                        }).ToList();
 
 
                        var vm_combine = new CombineStatisticsViewModel();
                        vm_combine.YearMonth = year_month;
                        vm_combine.Time = record.Time;
                        vm_combine.RunFlags = IStation.Untity.IntListHelper.ToString(run_flags);
                        vm_combine.RpmList = IStation.Untity.DoubleListHelper.ToString(rpm_list);
                        vm_combine.OutletPressureList = IStation.Untity.DoubleListHelper.ToString(outlet_pressure_list);
                        vm_combine.HeadList = IStation.Untity.DoubleListHelper.ToString(head_list);
                        vm_combine.TotalPower = Math.Round(total_power, 1);
                        vm_combine_list.Add(vm_combine);
 
                        foreach (var pump_record in pump_signal_records)
                        {
                            if (pump_record.Rpm == IStation.Error.Default || pump_record.Head == IStation.Error.Default)
                            {
                                continue;
                            }
                            var vm_pump = new PumpViewModel();
                            vm_pump.Time = record.Time;
                            vm_pump.Flag = pump_record.Flag;
                            vm_pump.Rpm = pump_record.Rpm;
                            vm_pump.WaterLevel = pump_record.WaterLevel;
                            vm_pump.Flow = pump_record.FlowRate;
                            vm_pump.InletPressure = pump_record.InletPressure;
                            vm_pump.OutletPressure = pump_record.OutletPressure;
                            vm_pump.Head = pump_record.Head;
                            vm_pump.Power = pump_record.InstantaneousPower;
                            vm_pump_list.Add(vm_pump);
                        }
                    }
                }
            }
 
            var use_head = barCekUseHead.Checked;
            if (vm_combine_list.Any())
            {
                var group_by_run_flags = vm_combine_list.GroupBy(x => x.RunFlags);
                foreach (var run_flags_item in group_by_run_flags)
                {
                    var run_flags_key = run_flags_item.Key;
                    var group_by_rpm_list = run_flags_item.GroupBy(x => x.RpmList);
                    foreach (var rpm_item in group_by_rpm_list)
                    {
                        var rpm_list_key = rpm_item.Key;
                        var outlet_dict = new Dictionary<string, List<CombineStatisticsViewModel>>();
                        if (use_head)
                        {
                            outlet_dict = rpm_item.GroupBy(x => x.HeadList).ToDictionary(x => x.Key, y => y.ToList());
                        }
                        else
                        {
                            outlet_dict = rpm_item.GroupBy(x => x.OutletPressureList).ToDictionary(x => x.Key, y => y.ToList());
                        }
 
                        foreach (var item in outlet_dict)
                        {
                            var outlet_key = item.Key;
                            var list = item.Value;
                            if (list.Count() < 2)
                                continue;
 
                            var max_flow = list.Max(x => x.TotalFlow);
                            var min_flow = list.Min(x => x.TotalFlow);
                            var diff_flow = max_flow - min_flow;
                            diff_flow = Math.Round(diff_flow, 1);
 
                            var max_power = list.Max(x => x.TotalPower);
                            var min_power = list.Min(x => x.TotalPower);
                            var diff_power = max_power - min_power;
                            diff_power = Math.Round(diff_power, 1);
 
                            var vm_combine_meter_dev = new CombineMeterDeviationViewModel();
                            vm_combine_meter_dev.RunFlags = run_flags_key;
                            vm_combine_meter_dev.RpmList = rpm_list_key;
                            vm_combine_meter_dev.OutletList = outlet_key;
                            vm_combine_meter_dev.FlowDeviation = diff_flow;
                            vm_combine_meter_dev.PowerDeviation = diff_power;
                            vm_combine_meter_dev.RecordList = list.ToList();
                            vm_combine_meter_dev.RecordCount = list.Count();
                            vm_combine_meter_dev_list.Add(vm_combine_meter_dev);
                        }
                    }
 
                }
            }
 
            if (vm_pump_list.Any())
            {
                var group_by_flag = vm_pump_list.GroupBy(x => x.Flag);
                foreach (var flag_item in group_by_flag)
                {
                    var flag_key = flag_item.Key;
                    var group_by_rpm = flag_item.GroupBy(x => x.Rpm);
                    foreach (var rpm_item in group_by_rpm)
                    {
                        var rpm_key = rpm_item.Key;
                        var outlet_dict = new Dictionary<double, List<PumpViewModel>>();
                        //if (use_head)
                        //{
                        //    outlet_dict = rpm_item.GroupBy(x => x.Head).ToDictionary(x => x.Key, y => y.ToList()); 
                        //    foreach (var item in outlet_dict)
                        //    {
                        //        var outlet_key = item.Key;
                        //        var list = item.Value;
                        //        if (list.Count() < 2)
                        //            continue;
 
                        //        var max_flow = list.Max(x => x.Flow);
                        //        var min_flow = list.Min(x => x.Flow);
                        //        var diff_flow = max_flow - min_flow;
                        //        diff_flow = Math.Round(diff_flow, 1);
 
                        //        var max_power = list.Max(x => x.Power);
                        //        var min_power = list.Min(x => x.Power);
                        //        var diff_power = max_power - min_power;
                        //        diff_power = Math.Round(diff_power, 1);
 
                        //        var vm_pump_meter_dev = new PumpMeterDeviationViewModel();
                        //        vm_pump_meter_dev.Flag = flag_key;
                        //        vm_pump_meter_dev.Rpm = rpm_key;
                        //        vm_pump_meter_dev.Outlet = outlet_key;
                        //        vm_pump_meter_dev.FlowDeviation = diff_flow;
                        //        vm_pump_meter_dev.PowerDeviation = diff_power;
                        //        vm_pump_meter_dev.RecordList = list.ToList();
                        //        vm_pump_meter_dev.RecordCount = list.Count();
                        //        vm_pump_meter_dev_list.Add(vm_pump_meter_dev);
                        //    }
                        //}
                        //else
                        //{
                        //   var outlet_dict1 = rpm_item.GroupBy(x => new { x.OutletPressure, x.WaterLevel }).ToDictionary(x => x.Key, y => y.ToList()); 
                        //    foreach (var item in outlet_dict1)
                        //    {
                        //        var outlet_key = item.Key.OutletPressure;
                        //        var list = item.Value;
                        //        if (list.Count() < 2)
                        //            continue;
 
                        //        var max_flow = list.Max(x => x.Flow);
                        //        var min_flow = list.Min(x => x.Flow);
                        //        var diff_flow = max_flow - min_flow;
                        //        diff_flow = Math.Round(diff_flow, 1);
 
                        //        var max_power = list.Max(x => x.Power);
                        //        var min_power = list.Min(x => x.Power);
                        //        var diff_power = max_power - min_power;
                        //        diff_power = Math.Round(diff_power, 1);
 
                        //        var vm_pump_meter_dev = new PumpMeterDeviationViewModel();
                        //        vm_pump_meter_dev.Flag = flag_key;
                        //        vm_pump_meter_dev.Rpm = rpm_key;
                        //        vm_pump_meter_dev.Outlet = outlet_key;
                        //        vm_pump_meter_dev.FlowDeviation = diff_flow;
                        //        vm_pump_meter_dev.PowerDeviation = diff_power;
                        //        vm_pump_meter_dev.RecordList = list.ToList();
                        //        vm_pump_meter_dev.RecordCount = list.Count();
                        //        vm_pump_meter_dev_list.Add(vm_pump_meter_dev);
                        //    }
                        //}
 
                        #region bak
 
                        if (use_head)
                        {
                            outlet_dict = rpm_item.GroupBy(x => x.Head).ToDictionary(x => x.Key, y => y.ToList());
                        }
                        else
                        {
                            outlet_dict = rpm_item.GroupBy(x => x.OutletPressure).ToDictionary(x => x.Key, y => y.ToList());
                        }
 
                        foreach (var item in outlet_dict)
                        {
                            var outlet_key = item.Key;
                            var list = item.Value;
                            if (list.Count() < 2)
                                continue;
 
                            var max_flow = list.Max(x => x.Flow);
                            var min_flow = list.Min(x => x.Flow);
                            var diff_flow = max_flow - min_flow;
                            diff_flow = Math.Round(diff_flow, 1);
 
                            var max_power = list.Max(x => x.Power);
                            var min_power = list.Min(x => x.Power);
                            var diff_power = max_power - min_power;
                            diff_power = Math.Round(diff_power, 1);
 
                            var vm_pump_meter_dev = new PumpMeterDeviationViewModel();
                            vm_pump_meter_dev.Flag = flag_key;
                            vm_pump_meter_dev.Rpm = rpm_key;
                            vm_pump_meter_dev.Outlet = outlet_key;
                            vm_pump_meter_dev.FlowDeviation = diff_flow;
                            vm_pump_meter_dev.PowerDeviation = diff_power;
                            vm_pump_meter_dev.RecordList = list.ToList();
                            vm_pump_meter_dev.RecordCount = list.Count();
                            vm_pump_meter_dev_list.Add(vm_pump_meter_dev);
                        }
 
                        #endregion
                    }
                }
            }
 
 
 
            combineStatisticsViewModelBindingSource.DataSource = vm_combine_list;
            combineMeterDeviationViewModelBindingSource.DataSource = vm_combine_meter_dev_list;
 
 
            pumpViewModelBindingSource.DataSource = vm_pump_list;
            pumpMeterDeviationViewModelBindingSource.DataSource = vm_pump_meter_dev_list;
            WaitFrmHelper.HideWaitForm();
        }
 
 
 
        //加载
        private void barCekLoad_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SetBindingData(_monitorDataSources, _station);
        }
 
 
        //扬程验证
        private void barCekUseHead_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SetBindingData(_monitorDataSources, _station);
        }
 
        #region 菜单 
 
        //全部展开
        private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.ExpandAllGroups();
        }
 
        //全部折叠
        private void barBtnCollapseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.CollapseAllGroups();
        }
 
        //检索
        private void barCekSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (barCekSearch.Checked)
                gridView1.ShowFindPanel();
            else
                gridView1.HideFindPanel();
        }
 
        // 刷新数据
        private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            InitialDataSource();
        }
 
 
 
 
 
        #endregion
 
        private void gridView4_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            var vm = gridView4.GetRow(e.FocusedRowHandle) as PumpMeterDeviationViewModel;
            if (vm == null)
            {
                pumpViewModelBindingSource1.DataSource = new List<PumpViewModel>();
                return;
            }
            pumpViewModelBindingSource1.DataSource = vm.RecordList;
            pumpViewModelBindingSource1.ResetBindings(false);
 
        }
    }
}