using DevExpress.XtraCharts;
|
using DevExpress.XtraEditors;
|
using IStation.Epanet;
|
using IStation.Epanet.Enums;
|
using IStation.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel.DataAnnotations;
|
using System.Drawing;
|
using System.IO;
|
using System.Linq;
|
using System.Text;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
public partial class ModelCorrectionPage1 : DocumentPage
|
{
|
public ModelCorrectionPage1()
|
{
|
InitializeComponent();
|
this.PageTitle.Caption = "模型修正";
|
|
this.gridView1.SetNormalView();
|
this.gridView2.SetNormalView();
|
|
//this.colHz0.Visible = false;
|
this.colHz.Visible = false;
|
this.colRpm.Visible = false;
|
this.colWaterLevel.Visible = false;
|
//this.colInletPressure.Visible = false;
|
|
this.repositoryItemDateEdit1.SetOnlyShowYearMonth();
|
this.repositoryItemDateEdit2.SetOnlyShowYearMonth();
|
this.barEditDateStart.EditValue = new DateTime(2024, 9, 1);
|
this.barEditDateEnd.EditValue = new DateTime(2024, 9, 1);
|
|
this.cmbFlag.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
|
|
this.stationListCtrl1.FocusedChangedEvent += StationListCtrl1_FocusedChangedEvent;
|
this.monitorDataSourcesTreeList1.FocusedChangedEvent += MonitorDataSourcesListCtrl1_FocusedChangedEvent;
|
|
InitialDiagarm();
|
}
|
|
|
private SwiftPlotDiagram _diagram;//图表
|
private Series _series_default_head; //
|
private Series _series_curve_head; //
|
private Series _series_correct_curve_head; //
|
private void InitialDiagarm()
|
{
|
this.chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;//是否在图表上显示图例
|
|
_diagram = (SwiftPlotDiagram)this.chartControl1.Diagram;
|
_diagram.EnableAxisXScrolling = true;//X轴是否允许滚动
|
_diagram.EnableAxisXZooming = true;//X轴是否允许缩放
|
_diagram.PaneLayout.Direction = PaneLayoutDirection.Vertical;//窗格的对齐方式
|
|
_diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Minute;
|
|
|
_series_default_head = chartControl1.GetSeriesByName("SeriesDefaultHead");
|
_series_curve_head = chartControl1.GetSeriesByName("SeriesCurveHead");
|
_series_correct_curve_head = chartControl1.GetSeriesByName("SeriesCorrectCurveHead");
|
|
_series_default_head.CrosshairLabelPattern = "监测压力:{V}";
|
_series_curve_head.CrosshairLabelPattern = "模型压力:{V}";
|
_series_correct_curve_head.CrosshairLabelPattern = "压力偏差:{V}";
|
|
//定制窗格的滚动条的外观
|
ScrollBarOptions scrollBarOptions = _diagram.DefaultPane.ScrollBarOptions;
|
scrollBarOptions.BackColor = Color.White;
|
scrollBarOptions.BarColor = Color.LightSlateGray;
|
scrollBarOptions.BorderColor = Color.DarkGray;
|
scrollBarOptions.BarThickness = 15;
|
scrollBarOptions.XAxisScrollBarAlignment = ScrollBarAlignment.Far;
|
scrollBarOptions.XAxisScrollBarVisible = true;
|
|
}
|
|
|
#region ViewModel
|
|
public class PumpViewModel
|
{
|
|
[Display(Name = "时间")]
|
public string Time { get; set; }
|
|
[Display(Name = "泵")]
|
public int Flag { get; set; }
|
|
[Display(Name = "转速")]
|
public double Rpm { get; set; }
|
|
[Display(Name = "频率")]
|
public double Hz { get; set; }
|
|
[Display(Name = "频率")]
|
public double Hz0 { 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 ModelOutletPressure { get; set; }
|
|
|
[Display(Name = "瞬时流量")]
|
public double Flow { get; set; }
|
|
[Display(Name = "模型流量")]
|
public double ModelFlow { get; set; }
|
|
[Display(Name = "流量差值")]
|
public double FlowDiff { get; set; }
|
|
|
[Display(Name = "压差")]
|
public double PressureDiff { get; set; }
|
|
[Display(Name = "曲线压差")]
|
public double CurvePressureDiff { get; set; }
|
|
[Display(Name = "压差差值")]
|
public double PressureDiffDev { get; set; }
|
|
|
[Display(Name = "修正压差")]
|
public double PressureDiffCt { get; set; }
|
|
[Display(Name = "修正压差差值")]
|
public double PressureDiffDevCt { get; set; }
|
|
|
[Display(Name = "曲线扬程")]
|
public double CurveHead { get; set; }
|
|
[Display(Name = "修正曲线扬程")]
|
public double CurveHeadCt { get; set; }
|
|
[Display(Name = "扬程差值")]
|
public double HeadDiff { get; set; }
|
|
public Model.CurveExpress QHCurve { get; set; }
|
public Model.CurveExpress QPDCurve { get; set; }
|
public Model.CurveExpress QHCtCurve { get; set; }
|
public Model.CurveExpress QPDCtCurve { get; set; }
|
}
|
|
public class ModelDiffViewModel
|
{
|
[Display(Name = "时间")]
|
public string Time { get; set; }
|
|
[Display(Name = "监测标识")]
|
public string MonitorID { get; set; }
|
|
[Display(Name = "模型标识")]
|
public string ModelID { get; set; }
|
|
[Display(Name = "类型")]
|
public string Type { get; set; }
|
|
[Display(Name = "模型值")]
|
public double ModelValue { get; set; }
|
|
[Display(Name = "监测值")]
|
public double MonitorValue { get; set; }
|
|
[Display(Name = "偏差值")]
|
public double DiffVlaue { get; set; }
|
|
[Display(Name = "泵")]
|
public bool IsPump { get; set; }
|
|
[Display(Name = "泵")]
|
public int? Flag { get; set; }
|
|
[Display(Name = "频率")]
|
public double? Hz { get; set; }
|
public double? HzRound { get; set; }
|
|
}
|
|
public class PumpFactorViewModel
|
{
|
[Display(Name = "泵")]
|
public int Flag { get; set; }
|
|
[Display(Name = "频率")]
|
public double Hz { get; set; }
|
|
[Display(Name = "总体标准差")]
|
public double? STDP { get; set; }
|
|
[Display(Name = "扬程(STDP)")]
|
public double? STDPHead { get; set; }
|
|
|
[Display(Name = "备注")]
|
public string Note { get; set; }
|
|
public void Round()
|
{
|
if (this.STDP.HasValue)
|
{
|
this.STDP = Math.Round(this.STDP.Value, 5);
|
}
|
if (this.STDPHead.HasValue)
|
{
|
this.STDPHead = Math.Round(this.STDPHead.Value, 5);
|
}
|
|
}
|
}
|
|
|
public class CurveQhdPoint
|
{
|
public CurveQhdPoint(double q,double h ,double pd) {
|
|
this.Q = q;
|
this.H = h;
|
this.Pd = pd;
|
}
|
public CurveQhdPoint() { }
|
public double Q { get; set; }
|
public double H { get; set; }
|
public double Pd { get; set; }
|
}
|
|
|
#endregion
|
|
private BLL.StationSignalRecordPacket _bll = new BLL.StationSignalRecordPacket();
|
private Model.Station _station = null;
|
private Model.MonitorDataSources _monitorDataSources = null;
|
|
private List<Model.Equipment<Model.Pump>> _pump_list = null;
|
private List<ModelDiffViewModel> _model_diff_vm_list = null;
|
private List<PumpViewModel> _pump_vm_list = null;
|
|
private string _model_file = System.IO.Path.Combine
|
(Settings.File.RootDirectory, Settings.File.DataFolder, "ch2_v3_20240918(Clear).inp");
|
|
/// <summary>
|
/// 清空数据
|
/// </summary>
|
public void Clear()
|
{
|
_pump_vm_list = new List<PumpViewModel>();
|
_model_diff_vm_list = new List<ModelDiffViewModel>();
|
this.cmbFlag.SelectedItem = null;
|
this.cmbFlag.Properties.Items.Clear();
|
this.modelTimeViewModelBindingSource.DataSource = new List<ModelDiffViewModel>();
|
this.pumpFactorViewModelBindingSource.DataSource = new List<PumpFactorViewModel>();
|
this.pumpViewModelBindingSource.DataSource = new List<PumpViewModel>();
|
|
ClearChart();
|
}
|
|
private void ClearChart()
|
{
|
|
this.chartControl1.BeginInit();
|
_series_default_head.Points.Clear();
|
_series_curve_head.Points.Clear();
|
_series_correct_curve_head.Points.Clear();
|
this.chartControl1.EndInit();
|
}
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public override void InitialDataSource()
|
{
|
this.stationListCtrl1.SetBindingData();
|
this.monitorDataSourcesTreeList1.SetBindingData();
|
}
|
|
//泵站变换
|
private void StationListCtrl1_FocusedChangedEvent(Model.Station obj)
|
{
|
_station = obj;
|
WaitFrmHelper.ShowWaitForm();
|
SetBindingData(_monitorDataSources, _station);
|
WaitFrmHelper.HideWaitForm();
|
|
}
|
|
//来源变换
|
private void MonitorDataSourcesListCtrl1_FocusedChangedEvent(Model.MonitorDataSources obj)
|
{
|
_monitorDataSources = obj;
|
WaitFrmHelper.ShowWaitForm();
|
SetBindingData(_monitorDataSources, _station);
|
WaitFrmHelper.HideWaitForm();
|
}
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(Model.MonitorDataSources monitorDataSources, Model.Station station)
|
{
|
|
Clear();
|
if (monitorDataSources == null || station == null)
|
{
|
return;
|
}
|
if (this.barCekLoad.Checked)
|
{
|
return;
|
}
|
|
|
var station_index = station.SortCode;
|
var dt_start = Convert.ToDateTime(this.barEditDateStart.EditValue);
|
var dt_end = Convert.ToDateTime(this.barEditDateEnd.EditValue);
|
var packets = _bll.Get(monitorDataSources.ID, station.ID);
|
packets = packets?.Where(x => (x.Year >= dt_start.Year && x.Year <= dt_end.Year) && (x.Month >= dt_start.Month && x.Month <= dt_end.Month)).ToList();
|
if (packets == null || !packets.Any())
|
return;
|
|
_pump_list = new BLL.Equipment().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID);
|
if (_pump_list == null || !_pump_list.Any())
|
{
|
return;
|
}
|
var flag_pump_dict = _pump_list.ToDictionary(x => x.SortCode, x => x.RatedParas);
|
var flag_list = _pump_list.Select(x => x.SortCode).OrderBy(x => x).ToList();
|
this.cmbFlag.Properties.Items.AddRange(flag_list);
|
var record_list = packets.SelectMany(x => x.StationSignalRecords).ToList();
|
|
var root_folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "分析系数");
|
List<AnalysisFactorHelper.AnalysisFactorDto> ana_factor_list = null;
|
var fileName = root_folder + "\\" + station.Name + ".json";
|
if (File.Exists(fileName))
|
{
|
var json = File.ReadAllText(fileName);
|
ana_factor_list = JsonHelper.Json2Object<List<AnalysisFactorHelper.AnalysisFactorDto>>(json);
|
}
|
|
SetBindingData(_model_file, flag_pump_dict, record_list, ana_factor_list, this.barCekUseAnalysisFactor.Checked);
|
}
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData
|
(
|
string model_inp,
|
Dictionary<int, Model.Pump> flag_pump_dict,
|
List<Model.StationSignalRecord> station_record_list,
|
List<AnalysisFactorHelper.AnalysisFactorDto> ana_factor_list,
|
bool use_ana_factor
|
)
|
{
|
if (!File.Exists(model_inp))
|
{
|
throw new Exception($"model_inp:is null");
|
}
|
|
var bll_curve = new BLL.PumpCurve();
|
var temp_id_build = new StringBuilder(31);
|
var err = EpanetMethods.ENopen(_model_file, "", "");
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENopen:{err}");
|
}
|
|
err = EpanetMethods.ENopenH();
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENopenH:{err}");
|
}
|
|
var curve_point_count = 100;
|
var flag_qh_curve_dict = GetFlagCurveDict();
|
var flag_qhd_point_dict = GetFlagCurvePointDict();
|
var pump_model_mapping_list = AnalysisFactorHelper.GetPumpModelMappingList();
|
foreach (var item in pump_model_mapping_list)
|
{
|
var flag = item.Flag;
|
|
if (EpanetMethods.ENgetlinkindex(item.PumpId, out int pump_index) != ErrorCode.Ok)
|
throw new Exception($"ENgetlinkindex:{err}");
|
|
if (!string.IsNullOrEmpty(item.FlowId))
|
{
|
if (EpanetMethods.ENgetlinkindex(item.FlowId, out int flow_index) != ErrorCode.Ok)
|
throw new Exception($"ENgetlinkindex:{err}");
|
item.FlowIndex = flow_index;
|
}
|
|
if (EpanetMethods.ENgetnodeindex(item.PressureId, out int pressure_index) != ErrorCode.Ok)
|
throw new Exception($"ENgetnodeindex:{err}");
|
|
if (EpanetMethods.ENgetcurveindex(item.CurveId, out int curve_index) != ErrorCode.Ok)
|
throw new Exception($"ENgetcurveindex:{err}");
|
|
item.PumpIndex = pump_index;
|
item.PressureIndex = pressure_index;
|
item.CurveIndex = curve_index;
|
|
|
var qh = flag_qh_curve_dict[flag];
|
var fit_point_list = qh.GetFitPoints(curve_point_count);
|
var flow_list = fit_point_list.Select(x => (float)x.X).ToArray();
|
var head_list = fit_point_list.Select(x => (float)x.Y).ToArray();
|
|
|
var cek = CheckFitPointList(fit_point_list, curve_point_count);
|
if (!cek)
|
{
|
throw new Exception($"CheckFitPointList: false");
|
}
|
err = EpanetMethods.ENsetcurve(item.CurveIndex, flow_list, head_list, curve_point_count);
|
if (err != 0)
|
{
|
throw new Exception($"ENsetcurve:{err}");
|
}
|
}
|
|
var pump_model_mapping_dict = pump_model_mapping_list.ToDictionary(x => x.Flag, y => y);
|
var pattern_id_list = AnalysisFactorHelper.GetPatternIdList();
|
var pattern_id_dict = new Dictionary<string, int>();
|
foreach (var id in pattern_id_list)
|
{
|
if (EpanetMethods.ENgetpatternindex(id, out int index) != ErrorCode.Ok)
|
continue;
|
pattern_id_dict.Add(id, index);
|
}
|
|
var vm_list = new List<PumpViewModel>();
|
foreach (var station_record in station_record_list)
|
{
|
var time = station_record.Time.ToString("G");
|
var model_record_dict = station_record.ModelRecordDict;
|
var pump_record_list = station_record.PumpSignalRecords;
|
foreach (var pattern in pattern_id_dict)
|
{
|
var pattern_id = pattern.Key;
|
var pattern_index = pattern.Value;
|
var pattern_value = 0f;
|
if (model_record_dict.ContainsKey(pattern_id))
|
{
|
pattern_value = (float)model_record_dict[pattern_id];
|
}
|
err = EpanetMethods.ENsetpattern(pattern_index, new float[] { pattern_value }, 1);
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENsetpattern:{err}");
|
}
|
}
|
|
if (ana_factor_list != null && ana_factor_list.Any() && use_ana_factor)
|
{
|
foreach (var pump_record in pump_record_list)
|
{
|
var flag = pump_record.Flag;
|
var pump = flag_pump_dict[flag];
|
var mapping = pump_model_mapping_dict[flag];
|
var rpm_ratio = pump_record.Rpm / pump.Nr;
|
if (!pump.IsBp)
|
rpm_ratio = 1;
|
if (rpm_ratio <= 0.1)
|
continue;
|
|
var hz0 = Math.Round(rpm_ratio * 50, 0);
|
var ana_factor = ana_factor_list.Find(x => x.Hz == hz0 && x.Flag == flag);
|
if (ana_factor == null)
|
{
|
throw new Exception($"ana_factor:is null");
|
}
|
var qh = flag_qh_curve_dict[flag];
|
var head_dev = (float)ana_factor.HeadDeviation;
|
var fit_point_list = new List<Model.CurvePoint>(curve_point_count);
|
if (head_dev == 0)
|
{
|
fit_point_list = qh.GetFitPoints(curve_point_count);
|
}
|
else
|
{
|
var pt_list_ct = qh.DefinePoints.Select(x => new Model.CurvePoint(x.X, x.Y + head_dev)).ToList();
|
var qh_ct = Model.FitCurveHelper.BuildCurveExpress(pt_list_ct, Model.eCurveFitType.CubicCurve);
|
fit_point_list = qh_ct.GetFitPoints(curve_point_count);
|
}
|
|
var x_list = fit_point_list.Select(x => (float)x.X).ToList();
|
var y_list = fit_point_list.Select(x => (float)x.Y).ToList();
|
|
//待判断
|
|
err = EpanetMethods.ENsetcurve(mapping.CurveIndex, x_list.ToArray(), y_list.ToArray(), curve_point_count);
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENsetcurve:{err}");
|
}
|
}
|
}
|
|
err = EpanetMethods.ENinitH(0);
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENinitH:{err}");
|
}
|
|
err = EpanetMethods.ENrunH(out _);
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENrunH:{err}");
|
}
|
|
foreach (var pump_record in pump_record_list)
|
{
|
var flag = pump_record.Flag;
|
var pump = flag_pump_dict[flag];
|
var qh = flag_qh_curve_dict[flag];
|
var mapping = pump_model_mapping_dict[flag];
|
var rpm = pump_record.Rpm;
|
if (!pump.IsBp)
|
rpm = pump.Nr;
|
|
var hz = Math.Round(rpm / pump.Nr * 50, 2);
|
if (hz > 50)
|
{
|
hz = 50;
|
}
|
var hz0 = Math.Round(hz, 0);
|
var wl = pump_record.WaterLevel;
|
var inlet_pressure = Model.CurveCalcuHelper.Mpa2M(pump_record.InletPressure);
|
var outlet_pressure = Model.CurveCalcuHelper.Mpa2M(pump_record.OutletPressure);
|
var pressure_diff = outlet_pressure - inlet_pressure;
|
var flow = pump_record.FlowRate;
|
var curve_head = pump_record.Head;
|
|
err = EpanetMethods.ENgetlinkvalue(mapping.PumpIndex, LinkValue.Flow, out float model_flow);
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENgetnodevalue:{err}");
|
}
|
|
err = EpanetMethods.ENgetlinkvalue(mapping.PumpIndex, LinkValue.HeadLoss, out float model_head);
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENgetnodevalue:{err}");
|
}
|
|
err = EpanetMethods.ENgetnodevalue(mapping.PressureIndex, NodeValue.Pressure, out float model_outlet_herd);
|
err = EpanetMethods.ENgetnodevalue(mapping.PressureIndex, NodeValue.Pressure, out float model_outlet_pressure);
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENgetnodevalue:{err}");
|
}
|
|
model_flow = Math.Abs(model_flow);
|
model_head = Math.Abs(model_head);
|
model_outlet_pressure = Math.Abs(model_outlet_pressure);
|
var model_pressure_diff = model_outlet_pressure - inlet_pressure;
|
|
Model.CurveExpress sim_qpd = null, sim_qh = null;
|
if (flow < 1)
|
{
|
var qh_similar = Model.CurveCalcuHelper.CalculateSimilarQH(qh, pump.Nr, rpm);
|
var fit_pt_list = qh_similar.GetFitPoints();
|
var qpd_fit_pt_list = new List<Model.CurvePoint>();
|
foreach (var pt in fit_pt_list)
|
{
|
var x = pt.X;
|
var other_press = Model.CurveCalcuHelper.CalculateOtherPress(x, pump.Ic, pump.Oc, null, null);
|
var y = pt.Y - other_press;
|
var fit_pt = new Model.CurvePoint(x, y);
|
qpd_fit_pt_list.Add(fit_pt);
|
}
|
|
//Model.FitCurveHelper.GetInterPointX(qpd_fit_pt_list, pressure_diff, out flow);
|
//if (flow < 1)
|
//{
|
// //flow = Model.FitCurveHelper.GetInterPointExX(qpd_fit_pt_list, pressure_diff)?.Last().X ?? 0;
|
//}
|
//flow = model_flow;
|
//model_pressure_diff = qpd_fit_pt_list.GetInterPointY(model_flow).FirstOrDefault();
|
curve_head = qh_similar.GetFitPointY(model_flow);
|
sim_qpd = Model.FitCurveHelper.BuildCurveExpress(qpd_fit_pt_list, Model.eCurveFitType.CubicCurve);
|
sim_qh = qh_similar;
|
}
|
|
|
var flow_diff = flow - model_flow;
|
|
var vm = new PumpViewModel();
|
vm.Time = time;
|
vm.Rpm = rpm;
|
vm.Flag = flag;
|
vm.Hz = hz;
|
vm.Hz0 = hz0;
|
vm.WaterLevel = wl;
|
vm.InletPressure = Math.Round(inlet_pressure, 2);
|
vm.OutletPressure = Math.Round(outlet_pressure, 2);
|
vm.PressureDiff = Math.Round(pressure_diff, 2);
|
|
vm.Flow = Math.Round(flow, 1);
|
vm.ModelFlow = Math.Round(model_flow, 1);
|
vm.ModelOutletPressure = Math.Round(model_outlet_pressure, 2);
|
vm.CurvePressureDiff = Math.Round(model_pressure_diff, 2);
|
vm.PressureDiffDev = Math.Round(pressure_diff - model_pressure_diff, 3);
|
vm.FlowDiff = Math.Round(flow_diff, 1);
|
|
vm.CurveHead = Math.Round(curve_head, 2);
|
|
vm.QHCurve = sim_qh;
|
vm.QPDCurve = sim_qpd;
|
vm_list.Add(vm);
|
|
}
|
}
|
|
err = EpanetMethods.ENcloseH();
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENcloseH:{err}");
|
}
|
err = EpanetMethods.ENclose();
|
if ((int)err > 6)
|
{
|
throw new Exception($"ENclose:{err}");
|
}
|
|
if (!vm_list.Any())
|
{
|
Clear();
|
return;
|
}
|
|
|
var flag_hz_head_diff_list = vm_list.Select(x => new Tuple<int, double, double>(x.Flag, x.Hz0, x.PressureDiffDev)).ToList();
|
var list = AnalysisFactorHelper.GetAnalysisFactorDtoList(flag_pump_dict, flag_hz_head_diff_list);
|
|
var vm_pump_facotr_list = new List<PumpFactorViewModel>();
|
foreach (var item in list)
|
{
|
var vm_pump_facotr = new PumpFactorViewModel();
|
vm_pump_facotr.Flag = item.Flag;
|
vm_pump_facotr.Hz = item.Hz;
|
vm_pump_facotr.STDP = item.HeadSTDP;
|
vm_pump_facotr.STDPHead = item.HeadDeviation;
|
vm_pump_facotr.Note = $"{item.Accuracy == -1}";
|
vm_pump_facotr.Round();
|
vm_pump_facotr_list.Add(vm_pump_facotr);
|
}
|
|
var group_by_flag = vm_list.GroupBy(x => new { x.Flag, x.Hz0 });
|
foreach (var flag_item in group_by_flag)
|
{
|
var flag = flag_item.Key.Flag;
|
var hz0 = flag_item.Key.Hz0;
|
|
var factor = vm_pump_facotr_list?.Find(x => x.Flag == flag && x.Hz == flag_item.Key.Hz0);
|
if (factor == null || !factor.STDPHead.HasValue)
|
{
|
continue;
|
}
|
if (hz0 == 50 && flag == 12)
|
{
|
|
}
|
|
var pump = flag_pump_dict[flag];
|
var qh = flag_qh_curve_dict[flag];
|
var std_dev = factor.STDPHead.Value;
|
|
var qh_similar = Model.CurveCalcuHelper.CalculateSimilarQH(qh, 50, hz0);
|
var qh_similar_fit_point_list = qh_similar.GetFitPoints(50);
|
|
var fit_pt_list = new List<CurveQhdPoint>();
|
foreach (var pt in qh_similar_fit_point_list)
|
{
|
if (pt.X>4000)
|
{
|
|
}
|
var flow = pt.X;
|
var head_src = pt.Y;
|
var other_press = Model.CurveCalcuHelper.CalculateOtherPress(flow, pump.Ic, pump.Oc, null, null);
|
var pressure_diff_src = head_src - other_press;
|
|
var pressure_diff = pressure_diff_src + std_dev;
|
var head = pressure_diff + other_press;
|
|
|
var fit_pt = new CurveQhdPoint();
|
fit_pt.Q = flow;
|
fit_pt.H = head;
|
fit_pt.Pd = pressure_diff;
|
fit_pt_list.Add(fit_pt);
|
}
|
|
var q_qh_ct = Model.FitCurveHelper.BuildCurveExpress(fit_pt_list.Select(x=>new CurvePoint(x.Q,x.H)).ToList(), Model.eCurveFitType.CubicCurve);
|
var q_pd_ct = Model.FitCurveHelper.BuildCurveExpress(fit_pt_list.Select(x=>new CurvePoint(x.Q,x.Pd)).ToList(), Model.eCurveFitType.CubicCurve);
|
foreach (var vm in flag_item)
|
{
|
var in_p = vm.InletPressure;
|
var out_p=vm.OutletPressure;
|
var flow = vm.ModelFlow;
|
var other_press = Model.CurveCalcuHelper.CalculateOtherPress(flow, pump.Ic, pump.Oc, null, null);
|
|
var pressure_diff = q_pd_ct.GetFitPointY(flow);
|
var head = other_press + pressure_diff;
|
var head_diff_ct = vm.CurveHead - head;
|
|
var t = q_qh_ct.GetFitPointY(flow);
|
|
var pressure_diff_dev = vm.PressureDiff - pressure_diff;
|
|
vm.PressureDiffCt = Math.Round(pressure_diff, 2);
|
vm.PressureDiffDevCt = Math.Round(pressure_diff_dev, 3);
|
vm.HeadDiff = Math.Round(head_diff_ct, 4);
|
|
vm.CurveHeadCt = Math.Round(head, 2);
|
vm.HeadDiff = Math.Round(vm.CurveHead - head, 3);
|
|
vm.QHCtCurve = q_qh_ct;
|
vm.QPDCtCurve = q_pd_ct;
|
}
|
|
|
}
|
|
|
_pump_vm_list = vm_list;
|
this.pumpViewModelBindingSource.DataSource= vm_list;
|
this.pumpViewModelBindingSource.ResetBindings(false);
|
this.gridView1.BestFitColumns();
|
|
|
this.pumpFactorViewModelBindingSource.DataSource = vm_pump_facotr_list;
|
this.pumpFactorViewModelBindingSource.ResetBindings(false);
|
this.gridView2.BestFitColumns();
|
|
}
|
|
private double GetCurveHead(Model.CurveExpress curve_qh, double nr, double rpm, double flow)
|
{
|
if (curve_qh == null)
|
return default;
|
var similar_qh = Model.CurveCalcuHelper.CalculateSimilarQH(curve_qh, nr, rpm);
|
if (similar_qh == null)
|
return default;
|
var head = similar_qh.GetFitPointY(flow);
|
return head;
|
}
|
|
|
|
bool CheckFitPointList(List<CurvePoint> fit_point_list, int nPoints)
|
{
|
var arr = fit_point_list.ToArray();
|
var max_y = fit_point_list[0].Y;
|
for (int j = 1; j < nPoints; j++)
|
{
|
if (arr[j].Y > max_y)
|
{
|
return false;
|
}
|
else
|
{
|
max_y = fit_point_list.Take(j).Max(x => x.Y);
|
}
|
}
|
return true;
|
}
|
|
bool CheckYValues(float[] xValues, int nPoints)
|
{
|
for (int j = 1; j < nPoints; j++)
|
{
|
if (xValues[j - 1] <= xValues[j])
|
{
|
return false;
|
}
|
}
|
return true;
|
}
|
|
private Dictionary<int, Model.CurveExpress> GetFlagCurveDict()
|
{
|
var dict = new Dictionary<int, Model.CurveExpress>();
|
var bll_curve = new BLL.PumpCurve();
|
var station_list = new BLL.Station().GetAll();
|
foreach (var station in station_list)
|
{
|
var eq_list = new BLL.Equipment().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID);
|
if (eq_list == null || !eq_list.Any())
|
{
|
return default;
|
}
|
|
foreach (var eq in eq_list)
|
{
|
Model.CurveExpress qh = null;
|
var curve_info = bll_curve.GetDefaultWorkingByPumpID(eq.ID)?.CurveInfo;
|
if (curve_info != null)
|
{
|
qh = curve_info.CurveQH;
|
}
|
dict.Add(eq.SortCode, qh);
|
}
|
}
|
|
return dict;
|
}
|
|
private Dictionary<int, List<CurveQhdPoint>> GetFlagCurvePointDict()
|
{
|
var dict = new Dictionary<int, List<CurveQhdPoint>>();
|
var bll_curve = new BLL.PumpCurve();
|
var station_list = new BLL.Station().GetAll();
|
foreach (var station in station_list)
|
{
|
var eq_list = new BLL.Equipment().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID);
|
if (eq_list == null || !eq_list.Any())
|
{
|
return default;
|
}
|
|
foreach (var eq in eq_list)
|
{
|
var pump = eq.RatedParas;
|
List<CurveQhdPoint> qhd_point_list = null;
|
var curve_info = bll_curve.GetDefaultWorkingByPumpID(eq.ID)?.CurveInfo;
|
if (curve_info != null)
|
{
|
qhd_point_list = new List<CurveQhdPoint>();
|
foreach (var dp in curve_info.CurveQH.DefinePoints)
|
{
|
var flow = dp.X;
|
var head = dp.Y;
|
var pressure_diff = head - Model.CurveCalcuHelper.CalculateOtherPress(flow, pump.Ic, pump.Oc, null, null);
|
qhd_point_list.Add(new CurveQhdPoint() { Q = flow, H = head, Pd = pressure_diff });
|
}
|
}
|
dict.Add(eq.SortCode, qhd_point_list);
|
}
|
}
|
|
return dict;
|
}
|
|
private void cmbFlag_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
ClearChart();
|
if (_pump_vm_list == null || !_pump_vm_list.Any())
|
{
|
return;
|
}
|
if (!int.TryParse(this.cmbFlag.Text, out int flag))
|
{
|
return;
|
}
|
var vm_list = _pump_vm_list.Where(x => x.Flag == flag).ToList();
|
if (vm_list == null || !vm_list.Any())
|
{
|
return;
|
}
|
this.chartControl1.BeginInit();
|
foreach (var vm in vm_list)
|
{
|
var time = vm.Time;
|
_series_default_head.Points.Add(new SeriesPoint(time, vm.OutletPressure));
|
_series_curve_head.Points.Add(new SeriesPoint(time, vm.ModelOutletPressure));
|
//_series_correct_curve_head.Points.Add(new SeriesPoint(time, vm.OutletPressureDiff));
|
}
|
|
this.chartControl1.EndInit();
|
}
|
|
|
//加载
|
private void barCekLoad_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
SetBindingData(_monitorDataSources, _station);
|
WaitFrmHelper.HideWaitForm();
|
}
|
|
|
// 刷新数据
|
private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
InitialDataSource();
|
}
|
|
private void barBtnExportAnalysisFactor_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_monitorDataSources == null || _station == null)
|
{
|
return;
|
}
|
if (_pump_list == null || !_pump_list.Any())
|
{
|
return;
|
}
|
if (_pump_vm_list == null || !_pump_vm_list.Any())
|
{
|
return;
|
}
|
|
WaitFrmHelper.ShowWaitForm("正在导出");
|
|
var flag_hz_head_diff_list = _pump_vm_list.Select(x => new Tuple<int, double, double>(x.Flag, x.Hz0, x.PressureDiffDev)).ToList();
|
var bol = AnalysisFactorHelper.SaveAnalysisFactorDtoList(_station.Name, _pump_list, flag_hz_head_diff_list);
|
if (!bol)
|
{
|
XtraMessageBox.Show("导出失败!");
|
return;
|
}
|
WaitFrmHelper.HideWaitForm();
|
AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!");
|
|
}
|
|
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
if (e.Column == this.colCurveHead)
|
{
|
var vm = this.gridView1.GetRow(e.RowHandle) as PumpViewModel;
|
if (vm == null)
|
return;
|
var dlg = new ChartView();
|
dlg.SetBindingData(vm.QHCurve, vm.QPDCurve);
|
dlg.ShowDialog();
|
}
|
else if (e.Column == this.colCurveHeadCt)
|
{
|
|
var vm = this.gridView1.GetRow(e.RowHandle) as PumpViewModel;
|
if (vm == null)
|
return;
|
var dlg = new ChartView();
|
//dlg.SetBindingData(vm.QHCtCurve, vm.QPDCtCurve);
|
dlg.SetBindingData(vm.QHCtCurve, vm.QPDCtCurve);
|
dlg.ShowDialog();
|
}
|
|
|
|
}
|
}
|
|
|
}
|