using NPOI.HSSF.Record;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel.DataAnnotations;
|
using System.Drawing;
|
using System.Linq;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
public partial class StationRelationshipPage : DocumentPage
|
{
|
public StationRelationshipPage()
|
{
|
|
InitializeComponent();
|
PageTitle.Caption = "泵站关系图";
|
|
repositoryItemDateEdit1.SetOnlyShowDate();
|
repositoryItemDateEdit2.SetOnlyShowDate();
|
barEditDateStart.EditValue = new DateTime(2024, 8, 1);
|
barEditDateEnd.EditValue = new DateTime(2024, 8, 2);
|
|
this.gridView1.SetNormalView();
|
|
monitorDataSourcesTreeList1.FocusedChangedEvent += MonitorDataSourcesListCtrl1_FocusedChangedEvent;
|
//timeValueSwiftPlotChartView1.SetTimeAxisX(DevExpress.XtraCharts.DateTimeMeasureUnit.Minute);
|
|
}
|
|
|
#region ViewModel
|
|
public class PumpViewModel
|
{
|
|
[Display(Name = "时间")]
|
public string Time { get; set; }
|
|
[Display(Name = "泵")]
|
public int Flag { get; set; }
|
|
[Display(Name = "转速")]
|
public double Flow2 { get; set; }
|
|
[Display(Name = "转速")]
|
public double Flow1 { get; set; }
|
}
|
|
public class ModelDiffViewModel
|
{
|
[Display(Name = "时间")]
|
public DateTime Date { get; set; }
|
|
[Display(Name = "时间")]
|
public string Time { get; set; }
|
|
[Display(Name = "名称")]
|
public string Name { get; set; }
|
|
[Display(Name = "监测压力")]
|
public double ScadaPressure { get; set; }
|
|
[Display(Name = "监测流量")]
|
public double ScadaFlow { get; set; }
|
|
[Display(Name = "模型压力")]
|
public double MonitorPressure { get; set; }
|
|
[Display(Name = "模型流量")]
|
public double MonitorFlow { get; set; }
|
|
[Display(Name = "压力偏差")]
|
public double PressureDiff { get; set; }
|
|
[Display(Name = "流量偏差")]
|
public double FlowDiff { get; set; }
|
|
}
|
|
public class PointViewModel
|
{
|
public PointViewModel() { }
|
public PointViewModel(DateTime dt, double x, double y, int index)
|
{
|
this.Time = dt;
|
this.X = x;
|
this.Y = y;
|
this.Index = index;
|
}
|
|
public DateTime Time { get; set; }
|
public int Index { get; set; }
|
public double X { get; set; }
|
public double Y { get; set; }
|
public string Label { get; set; }
|
|
}
|
|
public class RecordViewModel
|
{
|
public RecordViewModel() { }
|
|
[Display(Name = "时间")]
|
public DateTime Time { get; set; }
|
|
[Display(Name = "流量1")]
|
public double Flow1 { get; set; }
|
|
[Display(Name = "压力1")]
|
public double Pressure1 { get; set; }
|
|
[Display(Name = "流量2")]
|
public double Flow2 { get; set; }
|
|
[Display(Name = "压力2")]
|
public double Pressure2 { get; set; }
|
}
|
|
|
|
|
|
#endregion
|
|
private BLL.StationSignalRecordPacket _bll = new BLL.StationSignalRecordPacket();
|
private Model.MonitorDataSources _monitorDataSources = null;
|
|
|
|
/// <summary>
|
/// 清空数据
|
/// </summary>
|
public void Clear()
|
{
|
|
}
|
|
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public override void InitialDataSource()
|
{
|
monitorDataSourcesTreeList1.SetBindingData();
|
}
|
|
|
//来源变换
|
private void MonitorDataSourcesListCtrl1_FocusedChangedEvent(Model.MonitorDataSources obj)
|
{
|
_monitorDataSources = obj;
|
}
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(Model.MonitorDataSources monitorDataSources)
|
{
|
/*Clear();
|
if (monitorDataSources == null)
|
{
|
return;
|
}
|
|
var stationList = new BLL.Station().GetAll();
|
if (stationList == null || !stationList.Any())
|
{
|
return;
|
}
|
|
var ptList = new List<PointViewModel>();
|
|
var dt_start = Convert.ToDateTime(barEditDateStart.EditValue);
|
var dt_end = Convert.ToDateTime(barEditDateEnd.EditValue);
|
dt_end = dt_end.AddHours(24);
|
|
|
foreach (var station in stationList)
|
{
|
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())
|
continue;
|
var records = packets.SelectMany(x => x.StationSignalRecords).ToList();
|
//records = records.Where(x => x.Time > dt_start && x.Time < dt_end).ToList();
|
if (records == null || !records.Any())
|
continue;
|
|
// var packet = _bll.Get(monitorDataSources.ID, station.ID, dt_start.Year, dt_start.Month);
|
// if (packet == null)
|
// continue;
|
// var records = packet.StationSignalRecords;
|
//// records = records.Where(x => x.Time > dt_start && x.Time < dt_end).ToList();
|
// if (records == null || !records.Any())
|
// continue;
|
|
foreach (var item in records)
|
{
|
ptList.Add(new PointViewModel(item.Time, item.TotalFlow, item.TotalPressure, station.SortCode));
|
}
|
}
|
|
var record_list = new List<RecordViewModel>();
|
var time_group = ptList.GroupBy(x => x.Time);
|
foreach (var group in time_group)
|
{
|
var r = new RecordViewModel
|
{
|
Time = group.Key
|
};
|
foreach (var item in group)
|
{
|
if (item.Index == 1)
|
{
|
r.Flow1 = item.X;
|
r.Pressure1 = item.Y;
|
}
|
else
|
{
|
r.Flow2 = item.X;
|
r.Pressure2 = item.Y;
|
}
|
}
|
|
record_list.Add(r);
|
}
|
|
var p1List = record_list.Select(x => x.Pressure1).ToList();
|
var p2List = record_list.Select(x => x.Pressure2).ToList();
|
|
var v = Correlation.Pearson(p1List, p2List);
|
var v1 = v;
|
|
//var minQ = record_list.Min(x => x.Flow1);
|
//var maxQ = record_list.Max(x => x.Flow1);
|
|
//minQ = Math.Floor(minQ / 100) * 100;
|
//maxQ = Math.Ceiling(maxQ / 100) * 100;
|
|
//var diffQ = maxQ - minQ;
|
//var count = diffQ / 100;
|
//count += 1;
|
|
//var list = new List<(double Min, double Max, List<RecordViewModel> Records)>();
|
//for (int i = 0; i < count; i++)
|
//{
|
// var minSpace = minQ + i * 100;
|
// var maxSpace = minSpace + 100;
|
|
// var spaceList = record_list.Where(x => x.Flow1 >= minSpace && x.Flow1 < maxSpace).ToList();
|
// if (spaceList == null|| !spaceList.Any())
|
// {
|
// continue;
|
// }
|
|
// list.Add(new(minSpace, maxSpace, spaceList));
|
//}
|
//var a = list;*/
|
}
|
|
|
private void barBtnCalc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
SetBindingData(_monitorDataSources);
|
WaitFrmHelper.HideWaitForm();
|
}
|
|
}
|
|
|
}
|