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
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using IStation.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
 
namespace IStation.WinFrmUI.Monitor
{
    public partial class ScadaVerifyPage : DocumentPage
    {
        public ScadaVerifyPage()
        {
            InitializeComponent();
            this.PageTitle.Caption = "工况验证";
 
            this.repDateEdit.ShowToday = false;
            this.repDateEdit.ShowMonthHeaders = true;
            this.repDateEdit.CalendarView = DevExpress.XtraEditors.Repository.CalendarView.Vista;
            this.repDateEdit.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearView;
            this.repDateEdit.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView;
            this.repDateEdit.Mask.EditMask = "yyyy-MM";
            this.repDateEdit.Mask.UseMaskAsDisplayFormat = true;
            this.barEditDate.EditValue = DateTime.Now.AddYears(-1);
 
            this.equipmentExTreeListCtrl1.FocusedChangedEvent += EquipmentExTreeListCtrl1_FocusedChangedEvent; ;
            this.monitorDataSourcesTreeList.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent;
 
            InitialChart();
        }
 
 
        public class VerifyViewModel : PumpSignalRecord
        {
 
            public VerifyViewModel(Model.PumpSignalRecord rhs) : base(rhs) { }
            public VerifyViewModel(Model.PumpSignalRecord rhs, DateTime dateTime) : base(rhs)
            {
                this.Time = dateTime;
            }
 
            [Display(Name = "时间")]
            public DateTime Time { get; set; }
            [Display(Name = "曲线功率")]
            public double InterPower { get; set; }
            [Display(Name = "功率差值")]
            public double PowerDiff { get; set; }
 
            [Display(Name = "曲线扬程")]
            public double InterHead { get; set; }
            [Display(Name = "扬程差值")]
            public double HeadDiff { get; set; }
        }
 
 
        private List<VerifyViewModel> _verifyViewModelList = null;
 
        private Model.MonitorDataSources _monitorDataSources = null;
        private Model.Equipment _equipment = null;
        private readonly BLL.MonitorDataSet _bll = new BLL.MonitorDataSet();
        private readonly BLL.EquipmentMonitorMapping _bllEquipmentMonitorMapping = new BLL.EquipmentMonitorMapping();
        private readonly BLL.MonitorPoint _bllMonitorPoint = new BLL.MonitorPoint();
 
        private XYDiagram _diagram = null;
        private SecondaryAxisY _secondaryAxisYHead = null;
 
 
        /// <summary>
        /// 初始化图表
        /// </summary>
        public void InitialChart()
        {
            _diagram = this.chartControl1.Diagram as XYDiagram;
            _diagram.EnableAxisXScrolling = true;
            _diagram.EnableAxisYScrolling = true;
            _diagram.EnableAxisXZooming = true;
            _diagram.EnableAxisYZooming = true;
            _diagram.AxisX.CrosshairAxisLabelOptions.Visibility = DevExpress.Utils.DefaultBoolean.False;
            _diagram.AxisX.GridLines.Visible = true;
            _diagram.AxisY.GridLines.Visible = false;
            _secondaryAxisYHead = _diagram.SecondaryAxesY[0];
 
 
            this.chartControl1.RuntimeHitTesting = true;
            this.chartControl1.CrosshairOptions.ShowArgumentLine = false;
            this.chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True;
            this.chartControl1.Legend.MarkerMode = LegendMarkerMode.CheckBoxAndMarker;
            this.chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right;
        }
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            this.chartControl1.BeginInit();
            this.chartControl1.Series.Clear();
            this.chartControl1.EndInit();
 
            this.equipmentExTreeListCtrl1.SetBindingData();
            this.monitorDataSourcesTreeList.SetBindingData();
        }
 
        private void MonitorDataSourcesTreeList1_FocusedChangedEvent(Model.MonitorDataSources obj)
        {
            _monitorDataSources = obj;
        }
 
        private void EquipmentExTreeListCtrl1_FocusedChangedEvent(Model.Equipment obj)
        {
            _equipment = obj;
        }
 
        //验证
        private void barBtnVerify_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.barEditDate.EditValue == null)
            {
                XtraMessageBox.Show("请选择时间!");
                return;
            }
            if (_monitorDataSources == null || _equipment == null)
                return;
            var lays = this.chartControl1.ShowOverlay();
            this.chartControl1.BeginInit();
            this.chartControl1.Series.Clear();
            this.chartControl1.EndInit();
            _verifyViewModelList = new List<VerifyViewModel>();
 
            var date = (DateTime)this.barEditDate.EditValue;
            var packet = new BLL.StationSignalRecordPacket().Get(_monitorDataSources.ID, _equipment.BelongID, date.Year, date.Month);
            var stationSignalRecords = packet?.StationSignalRecords?.ToList();
            if (stationSignalRecords == null || !stationSignalRecords.Any())
            {
                lays.Close();
                XtraMessageBox.Show("无数据!");
                return;
            }
 
            var pump = new BLL.Equipment().GetByID(_equipment.ID);
 
            foreach (var stationSignalRecord in stationSignalRecords)
            {
                foreach (var pumpSignalRecord in stationSignalRecord.PumpSignalRecords)
                {
                    _verifyViewModelList.Add(new VerifyViewModel(pumpSignalRecord, stationSignalRecord.Time));
                }
            }
            var verifyVMGroup = _verifyViewModelList.GroupBy(x => x.Flag);
            var bllPumpCurve = new BLL.PumpCurve();
            foreach (var item in verifyVMGroup)
            {
                var pump = pumps?.Find(x => x.SortCode == item.Key);
                if (pump == null)
                    continue;
                var curveInfo = bllPumpCurve.GetDefaultWorkingByPumpID(pump.ID)?.CurveInfo;
                if (curveInfo == null)
                    continue;
                var seriesViewPower = new DevExpress.XtraCharts.LineSeriesView();
                var seriesPower = new DevExpress.XtraCharts.Series
                {
                    Name = pump.SortCode + "-功率",
                    View = seriesViewPower,
                    LegendText = pump.SortCode + "-功率"
                };
 
                var seriesViewHead = new DevExpress.XtraCharts.LineSeriesView();
                seriesViewHead.AxisY = _secondaryAxisYHead;
                var seriesHead = new DevExpress.XtraCharts.Series
                {
                    Name = pump.SortCode + "-扬程",
                    View = seriesViewHead,
                    LegendText = pump.SortCode + "-扬程"
                };
                foreach (var record in item)
                {
                    if (record.InstantaneousPower == IStation.Error.Default)
                    {
                        continue;
                    }
                    var rpm = record.Rpm;
                    if (rpm == IStation.Error.Default || rpm < 1)
                    {
                        if (record.Frequency > 0 && record.Frequency != IStation.Error.Default)
                        {
                            rpm = (record.Frequency / 50) * pump.RatedParas.Nr;
                        }
                        else
                        {
                            continue;
                        }
                    }
 
 
                    var time = record.Time;
                    var flowRate = record.FlowRate;
                    var curveQH = Model.CurveCalcuHelper.CalculateSimilarQH(curveInfo.CurveQH, pump.RatedParas.Nr, record.Rpm);
                    var curveQP = Model.CurveCalcuHelper.CalculateSimilarQP(curveInfo.CurveQP, pump.RatedParas.Nr, record.Rpm);
 
                    //if (flowRate < 1)
                    //{
                    //    flowRate = curveQH.GetFitPointY(record.Head);
                    //}
 
                    record.InterPower = curveQP.GetFitPointY(flowRate);
                    record.PowerDiff = record.InstantaneousPower - record.InterPower;
                    record.PowerDiff = Math.Round(record.PowerDiff, 2);
 
 
                    record.InterHead = curveQH.GetFitPointY(flowRate);
                    record.HeadDiff = record.Head - record.InterHead;
                    record.HeadDiff = Math.Round(record.HeadDiff, 2);
 
                    seriesPower.Points.Add(new SeriesPoint(time, record.PowerDiff));
                    seriesHead.Points.Add(new SeriesPoint(time, record.HeadDiff));
                }
 
                if (pump.SortCode != 25)
                {
                    this.chartControl1.Series.Add(seriesPower);
                }
                this.chartControl1.Series.Add(seriesHead);
 
            }
 
 
            lays.Close();
 
        }
 
 
 
 
        //刷新
        private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            InitialDataSource();
        }
 
        //图表点击
        private void chartControl1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (_verifyViewModelList != null && _verifyViewModelList.Any())
                {
                    var hitInfo = chartControl1.CalcHitInfo(e.Location);
                    if (hitInfo.InChart)
                    {
                        var diagramCoordinates = _diagram.PointToDiagram(e.Location);
                        var axisValue = diagramCoordinates.GetAxisValue(_diagram.AxisX);
                        if (axisValue == null)
                            return;
                        var pt_dt = axisValue.DateTimeValue;
                        var vm = _verifyViewModelList.Find(x => x.Time == pt_dt);
                        if (vm == null)
                        {
                            vm = _verifyViewModelList.FindLast(x => x.Time > pt_dt);
                        }
                        this.propertyGridControl1.SelectedObject = vm;
                    }
                }
            }
 
        }
    }
}