using DevExpress.XtraCharts; using DevExpress.XtraEditors; using IStation.Model; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; namespace IStation.WinFrmUI.Monitor { public partial class ScadaDiffVerifyPage : DocumentPage { public ScadaDiffVerifyPage() { InitializeComponent(); PageTitle.Caption = "工况均差验证"; repDateEdit.ShowToday = false; repDateEdit.ShowMonthHeaders = true; repDateEdit.CalendarView = DevExpress.XtraEditors.Repository.CalendarView.Vista; repDateEdit.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearView; repDateEdit.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView; repDateEdit.Mask.EditMask = "yyyy-MM"; repDateEdit.Mask.UseMaskAsDisplayFormat = true; barEditDate.EditValue = DateTime.Now.AddMonths(-1); //DateTime.Now.AddYears(-1); equipmentExTreeListCtrl1.FocusedChangedEvent += EquipmentExTreeListCtrl1_FocusedChangedEvent; ; monitorDataSourcesTreeList.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent; gridView1.SetNormalView(); //this.colUpdateHeadDiff.Visible = false; InitialChart(); } public class VerifyViewModel : PumpSignalRecord { public VerifyViewModel(Model.PumpSignalRecord rhs) : base(rhs) { } public VerifyViewModel(Model.PumpSignalRecord rhs, DateTime dateTime) : base(rhs) { Time = dateTime; } [Display(Name = "时间", Order = 0)] public DateTime Time { get; set; } [Display(Name = "曲线功率", Order = 11)] public double InterPower { get; set; } [Display(Name = "功率差值", Order = 12)] public double PowerDiff { get; set; } [Display(Name = "曲线扬程", Order = 9)] public double InterHead { get; set; } [Display(Name = "扬程差值", Order = 10)] public double HeadDiff { get; set; } [Display(Name = "扬程差值(修正后)", Order = 10)] public double UpdateHeadDiff { get; set; } [Display(Name = "效率", Order = 8)] public double Eff { get; set; } } private List _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; /// /// 初始化图表 /// public void InitialChart() { _diagram = 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.Color = System.Drawing.Color.LightCoral; _diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Second; _diagram.AxisX.DateTimeScaleOptions.ScaleMode = ScaleMode.Manual; _diagram.AxisX.GridLines.Visible = true; _diagram.AxisY.GridLines.Visible = false; _secondaryAxisYHead = _diagram.SecondaryAxesY[0]; chartControl1.RuntimeHitTesting = true; chartControl1.CrosshairOptions.ShowArgumentLine = false; chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True; chartControl1.Legend.MarkerMode = LegendMarkerMode.CheckBoxAndMarker; chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right; } /// /// 初始化数据 /// public override void InitialDataSource() { chartControl1.BeginInit(); chartControl1.Series.Clear(); chartControl1.EndInit(); equipmentExTreeListCtrl1.SetBindingData(); 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) { memoInfo.Text = string.Empty; if (barEditDate.EditValue == null) { XtraMessageBox.Show("请选择时间!"); return; } if (_monitorDataSources == null || _equipment == null) return; var lays = chartControl1.ShowOverlay(); chartControl1.BeginInit(); chartControl1.Series.Clear(); chartControl1.EndInit(); _verifyViewModelList = new List(); var pump = new BLL.Equipment().GetChildPumpByEnginePumpID(_equipment.ID); var date = (DateTime)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; } foreach (var stationSignalRecord in stationSignalRecords) { foreach (var pumpSignalRecord in stationSignalRecord.PumpSignalRecords) { if (pumpSignalRecord.Flag != pump.SortCode) continue; var time = stationSignalRecord.Time; var rpm = pumpSignalRecord.Rpm; var fre = pumpSignalRecord.Frequency; var vm = new VerifyViewModel(pumpSignalRecord, time); _verifyViewModelList.Add(vm); } } var curveInfo = new BLL.PumpCurve().GetDefaultWorkingByPumpID(pump.ID)?.CurveInfo; if (curveInfo == null) { lays.Close(); return; } var seriesViewPower = new DevExpress.XtraCharts.LineSeriesView(); seriesViewPower.Color = System.Drawing.Color.LightCoral; var seriesPower = new DevExpress.XtraCharts.Series { Name = pump.SortCode + "-功率", View = seriesViewPower, LegendText = pump.SortCode + "-功率" }; var seriesViewHead = new DevExpress.XtraCharts.LineSeriesView(); seriesViewHead.AxisY = _secondaryAxisYHead; seriesViewHead.Color = System.Drawing.Color.DodgerBlue; var seriesHead = new DevExpress.XtraCharts.Series { Name = pump.SortCode + "-扬程", View = seriesViewHead, LegendText = pump.SortCode + "-扬程" }; var verifyViewModelList = Verify(pump.RatedParas.Nr, curveInfo, _verifyViewModelList); var rpm_diff_dict = new Dictionary(); var new_verify_vm_rpm_group = verifyViewModelList.GroupBy(x => Math.Round(x.Rpm)).OrderBy(x => x.Key); if (new_verify_vm_rpm_group != null && new_verify_vm_rpm_group.Any()) { var str = new StringBuilder(); foreach (var group in new_verify_vm_rpm_group) { var points = group.Where(x => Math.Abs(x.HeadDiff) < 10)?.ToList(); if (points != null && points.Any()) { var head_diff_avg = points.Average(x => x.HeadDiff); str.AppendLine($"{group.Key}Rpm 平均值:{head_diff_avg:N4}"); rpm_diff_dict.Add(group.Key, head_diff_avg); } } memoInfo.Text = str.ToString(); } foreach (var record in verifyViewModelList) { if (record.Flag > 18) { if (record.FlowRate < 1) { continue; } } if (record.Head == IStation.Error.Default || record.Head == 0) { continue; } if (record.InstantaneousPower == IStation.Error.Default) { continue; } var rpm = record.Rpm; rpm = Math.Round(rpm); if (rpm_diff_dict.ContainsKey(rpm)) { var update_head = rpm_diff_dict[rpm]; record.UpdateHeadDiff = VerifyUpdate(pump.RatedParas.Nr, curveInfo, update_head, record); } var time = record.Time; seriesPower.Points.Add(new SeriesPoint(time, record.PowerDiff)); if (record.Flag > 19) { seriesHead.Points.Add(new SeriesPoint(time, record.HeadDiff)); } } chartControl1.Series.Add(seriesPower); if (pump.SortCode > 19) { chartControl1.Series.Add(seriesHead); } lays.Close(); verifyViewModelBindingSource.DataSource = verifyViewModelList; verifyViewModelBindingSource.ResetBindings(false); } private List Verify(double Nr, FeatCurveExpressGroup curveInfo, List verifyViewModels) { foreach (var record in verifyViewModels) { if (record.Flag > 18) { if (record.FlowRate < 1) { continue; } } if (record.Head == IStation.Error.Default || record.Head == 0) { continue; } 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) * Nr; } else { continue; } } var time = record.Time; var flowRate = record.FlowRate; Model.CurveExpress curveQH, curveQP; curveQH = Model.CurveCalcuHelper.CalculateSimilarQH(curveInfo.CurveQH, Nr, record.Rpm); curveQP = Model.CurveCalcuHelper.CalculateSimilarQP(curveInfo.CurveQP, Nr, record.Rpm); if (curveQH == null || curveQP == null) continue; if (flowRate < 1) { var qhPoints = curveQH.GetFitPoints(); Model.FitCurveHelper.GetInterPointX(qhPoints, record.Head, out flowRate); } record.InterPower = Math.Round(curveQP.GetFitPointY(flowRate), 2); record.PowerDiff = record.InstantaneousPower - record.InterPower; record.PowerDiff = Math.Round(record.PowerDiff, 2); if (record.Flag > 19) { record.InterHead = Math.Round(curveQH.GetFitPointY(flowRate), 2); record.HeadDiff = record.Head - record.InterHead; record.HeadDiff = Math.Round(record.HeadDiff, 2); } record.Eff = Model.CurveCalcuHelper.CalculateE(flowRate, record.Head, record.InstantaneousPower); } return verifyViewModels; } private double VerifyUpdate(double Nr, FeatCurveExpressGroup curveInfo, double update_head, VerifyViewModel record) { double head_diff = 0; if (record.Flag > 18) { if (record.FlowRate < 1) { return default; } } if (record.Head == IStation.Error.Default || record.Head == 0) { return default; } if (record.InstantaneousPower == IStation.Error.Default) { return default; } var rpm = record.Rpm; if (rpm == IStation.Error.Default || rpm < 1) { if (record.Frequency > 0 && record.Frequency != IStation.Error.Default) { rpm = (record.Frequency / 50) * Nr; } else { return default; } } var curveQhPoints50 = curveInfo.CurveQH.DefinePoints?.Select(x => new Model.CurvePoint(x.X, x.Y + update_head)).ToList(); var curveQh50 = new CurveExpress(curveQhPoints50, Model.eCurveFitType.FourM, true); var flowRate = record.FlowRate; Model.CurveExpress curveQH; curveQH = Model.CurveCalcuHelper.CalculateSimilarQH(curveQh50, Nr, record.Rpm); if (curveQH == null) return default; if (record.Flag > 19) { var inter_head = curveQH.GetFitPointY(flowRate); head_diff = Math.Round(record.Head - inter_head, 2); } return head_diff; } //刷新 private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { InitialDataSource(); } //图表点击 private void chartControl1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { if (chartControl1.Series.Count < 1) return; 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); } propertyGridControl1.Text = "数据"; propertyGridControl1.SelectedObject = vm; } } } } //导出表格 private void barBtnExportExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { gridView1.ExportExcel(); } private void barBtnExportWaterDesk_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (barEditDate.EditValue == null) { XtraMessageBox.Show("请选择时间!"); return; } if (_monitorDataSources == null || _equipment == null) return; var dlg = new SetTimeStepDlg(); dlg.SetBindingData(300); dlg.ReloadDataEvent += (timeStep) => { WaitFrmHelper.ShowWaitForm("正在导出"); ExportWaterDeskHelper.Export(_monitorDataSources.ID, _equipment.BelongID, timeStep); WaitFrmHelper.HideWaitForm(); AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!"); }; dlg.ShowDialog(); } private void barBtnExportEapnet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (barEditDate.EditValue == null) { XtraMessageBox.Show("请选择时间!"); return; } if (_monitorDataSources == null || _equipment == null) return; var date = (DateTime)barEditDate.EditValue; var year = date.Year; var month = date.Month; var dlg = new SetTimeStepDlg(); dlg.SetBindingData(300); dlg.ReloadDataEvent += (timeStep) => { WaitFrmHelper.ShowWaitForm("正在导出"); //ExportEpanetHelper.ExportByDay(_monitorDataSources.ID, _equipment.BelongID, year, month, timeStep); ExportEpanetHelper.Export(_monitorDataSources.ID, _equipment.BelongID, timeStep); WaitFrmHelper.HideWaitForm(); AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!"); }; dlg.ShowDialog(); } } }