ningshuxia
2025-04-03 4917fb959e2befec07a693e72d7010c09494ec7c
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
269
270
271
272
273
274
275
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();
        }
 
    }
 
 
}