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);
|
|
}
|
}
|
}
|