Shuxia Ning
2024-10-08 cf4967a0aebab18c5a37137f3e4c61b2d73a54bb
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
using IStation.Unit;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace IStation.WinFrmUI.Monitor
{
    public partial class WaterLevelAnalysisPage : DocumentPage
    {
        public WaterLevelAnalysisPage()
        {
            InitializeComponent();
            this.PageTitle.Caption = "水位分析";
            this.sceneTreeList1.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent;
        }
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            this.timeValueEasyChartView1.InitialDefaultSeries(null);
            this.sceneTreeList1.SetBindingData();
 
        }
 
        private Model.MonitorDataSources _scene = null;
        private void MonitorDataSourcesTreeList1_FocusedChangedEvent(Model.MonitorDataSources obj)
        {
            _scene = obj;
        }
        private void barBtnAnalysis_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Analysis(_scene);
        }
 
        private void Analysis(Model.MonitorDataSources scene)
        {
 
            this.chartControl1.Series[0].Points.Clear();
            if (scene == null)
                return;
            var point陈行水库水位 = new BLL.MonitorPoint().GetAllExSignalWithSignalType()?.Find(x => x.Name == "陈行水库水位");
            if (point陈行水库水位 == null)
                return;
 
            var bllData = new BLL.MonitorDataSet();
 
            var packet = bllData.GetSignalRecordPacket(scene.ID, point陈行水库水位.MonitorPointID, point陈行水库水位.SignalID);
            if (packet == null || packet.RecordList == null)
                return;
            var validList = packet.RecordList.Where(x => x.Value != IStation.Error.Default && x.Value != IStation.Error.Abnormal)
                ?.Select(x => new TimeValue(x.Time, x.Value)).ToList();
            if (validList == null || validList == null)
                return;
 
 
            var WaterSums = new WaterLevelAnaly().Get(scene.ID);
            var waterLevelDeviation = new List<TimeValue>();
            TimeValue top = null;
            TimeValue bottom = null;
            WaterSum waterSum = null;
            bool asc = false;
            for (int i = 0; i < validList.Count(); i++)
            {
                if (i == 0)
                {
                    var item = validList[i];
                    var next = validList[i + 1];
                    if (item.Value > next.Value)
                    {
                        asc = false;
                        top = item;
                    }
                    else
                    {
                        asc = true;
                        bottom = item;
                    }
                    continue;
                }
 
                if (i + 1 == validList.Count())
                    break;
 
 
                var positiveLast = validList[i - 1];
                var positiveItem = validList[i];
                var positiveNext = validList[i + 1];
 
 
                if (waterSum == null)
                {
                    waterSum = WaterSums.Find(x => x.Year == positiveItem.Time.Year && x.Month == positiveItem.Time.Month);
                }
                if (waterSum.Year != positiveItem.Time.Year || waterSum.Month != positiveItem.Time.Month)
                {
                    waterSum = WaterSums.Find(x => x.Year == positiveItem.Time.Year && x.Month == positiveItem.Time.Month);
                }
 
                if (positiveLast.Value < positiveItem.Value && positiveItem.Value > positiveNext.Value)
                {
                    if (bottom == null)
                    {
                        asc = false;
                    }
                    top = positiveItem;
                }
                else if (positiveLast.Value > positiveItem.Value && positiveItem.Value < positiveNext.Value)
                {
                    if (top == null)
                    {
                        asc = true;
                    }
                    bottom = positiveItem;
                }
                if (bottom != null && top != null)
                {
                    bool calcu = false;
                    var topSum = waterSum.Records.Find(x => x.Time == top.Time);
                    var bottomSum = waterSum.Records.Find(x => x.Time == bottom.Time);
                    if (topSum != null && bottomSum != null)
                    {
                        calcu = true;
                        topSum.CalcuWater();
                        bottomSum.CalcuWater();
                    }
 
 
                    var vm = new TimeValue();
                    vm.Time = positiveItem.Time;
                    if (asc)
                    {
 
                        var ascValue = top.Value - bottom.Value;
                        vm.Value = ascValue;
 
                        if (calcu)
                        {
                            var area = Math.Abs((topSum.Water.Value - bottomSum.Water.Value)) / Math.Abs(ascValue);
                            if (area < 10000000)
                            {
                                this.chartControl1.Series[0].Points.Add(new DevExpress.XtraCharts.SeriesPoint(area, positiveItem.Value));
                            }
                        }
 
                        bottom = null;
                        asc = false;
                    }
                    else
                    {
                        var descValue = bottom.Value - top.Value;
                        vm.Value = descValue;
 
                        if (calcu)
                        {
                            var area = Math.Abs((bottomSum.Water.Value - topSum.Water.Value)) / Math.Abs(descValue);
                            if (area < 10000000)
                            {
                                this.chartControl1.Series[0].Points.Add(new DevExpress.XtraCharts.SeriesPoint(area, positiveItem.Value));
                            }
                        }
 
                        top = null;
                        asc = true;
 
                    }
                    waterLevelDeviation.Add(vm);
                }
            }
 
 
 
 
 
 
 
 
            if (int.TryParse(point陈行水库水位.UnitValue, out int unitValue))
            {
                var dict = UnitHelper.GetEnUnitDict(point陈行水库水位.UnitType);
                if (dict != null)
                    this.timeValueEasyChartView1.SetAxisYTitle(dict[unitValue]);
            }
            else
            {
                this.timeValueEasyChartView1.SetAxisYTitle(point陈行水库水位.UnitValue);
            }
            this.timeValueEasyChartView1.InitialDefaultSeries(waterLevelDeviation);
 
        }
 
 
 
        /*private BLL.MonitorDataSet bllData = new BLL.MonitorDataSet();
        private List<Model.SignalRecord> GetSignalRecords(Model.MonitorPointExSignal monitor)
        {
            var data = bllData.GetSignalRecordPacket(monitor.MonitorPointID, monitor.SignalID)
                 .RecordList.Where(x => x.Value != IStation.Error.Default && x.Value != IStation.Error.Abnormal)?
                 .ToList();
 
            return data;
        }*/
 
 
 
    }
}
 
 
/*
var ch1_1 = dataCh1.Find(x => x.Time == top.Time);
var ch2_1 = dataCh2.Find(x => x.Time == top.Time);
var ch3_1 = dataCh3.Find(x => x.Time == top.Time);
var ch4_1 = dataCh4.Find(x => x.Time == top.Time);
var ch5_1 = dataCh5.Find(x => x.Time == top.Time);
 
var jd1_1 = dataJd1.Find(x => x.Time == top.Time);
var jd2_1 = dataJd2.Find(x => x.Time == top.Time);
var jd3_1 = dataJd3.Find(x => x.Time == top.Time);
 
var dn24_1 = dataDn2400.Find(x => x.Time == top.Time);
var dn27_1 = dataDn2700.Find(x => x.Time == top.Time);
 
var ch1_2 = dataCh1.Find(x => x.Time == bottom.Time);
var ch2_2 = dataCh2.Find(x => x.Time == bottom.Time);
var ch3_2 = dataCh3.Find(x => x.Time == bottom.Time);
var ch4_2 = dataCh4.Find(x => x.Time == bottom.Time);
var ch5_2 = dataCh5.Find(x => x.Time == bottom.Time);
 
var jd1_2 = dataJd1.Find(x => x.Time == bottom.Time);
var jd2_2 = dataJd2.Find(x => x.Time == bottom.Time);
var jd3_2 = dataJd3.Find(x => x.Time == bottom.Time);
 
var dn24_2 = dataDn2400.Find(x => x.Time == bottom.Time);
var dn27_2 = dataDn2700.Find(x => x.Time == bottom.Time);
*/
/*var ch1累计流量 = new BLL.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongIDAndGroupID(belongType, belongId, 500865961361484)?.Find(x => x.Name == "累积流量");
var ch2累计流量 = new BLL.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongIDAndGroupID(belongType, belongId, 500865961361497)?.Find(x => x.Name == "累积流量");
var ch3累计流量 = new BLL.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongIDAndGroupID(belongType, belongId, 500865961361510)?.Find(x => x.Name == "累积流量");
var ch4累计流量 = new BLL.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongIDAndGroupID(belongType, belongId, 500865961361523)?.Find(x => x.Name == "累积流量");
var ch5累计流量 = new BLL.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongIDAndGroupID(belongType, belongId, 500865961365573)?.Find(x => x.Name == "累积流量");
 
var point嘉定1线累计流量 = new BLL.MonitorPoint().GetAllExSignalWithSignalType()?.Find(x => x.Name == "嘉定1线累计流量");
var point嘉定2线累计流量 = new BLL.MonitorPoint().GetAllExSignalWithSignalType()?.Find(x => x.Name == "嘉定2线累计流量");
var point嘉定3线累计流量 = new BLL.MonitorPoint().GetAllExSignalWithSignalType()?.Find(x => x.Name == "嘉定3线累计流量");
 
var point2400总管累计流量 = new BLL.MonitorPoint().GetAllExSignalWithSignalType()?.Find(x => x.Name == "2400总管累计流量");
var point2700总管累计流量 = new BLL.MonitorPoint().GetAllExSignalWithSignalType()?.Find(x => x.Name == "2700总管累计流量");
 
var dataCh1 = GetSignalRecords(ch1累计流量);
var dataCh2 = GetSignalRecords(ch2累计流量);
var dataCh3 = GetSignalRecords(ch3累计流量);
var dataCh4 = GetSignalRecords(ch4累计流量);
var dataCh5 = GetSignalRecords(ch5累计流量);
 
var dataJd1 = GetSignalRecords(point嘉定1线累计流量);
var dataJd2 = GetSignalRecords(point嘉定2线累计流量);
var dataJd3 = GetSignalRecords(point嘉定3线累计流量);
var dataDn2400 = GetSignalRecords(point2400总管累计流量);
var dataDn2700 = GetSignalRecords(point2700总管累计流量);*/
 
 
/*
for (int i = 0; i < validList.Count(); i++)
{
    if (i == 0)
        continue;
    if (i + 1 == validList.Count())
        break;
 
    var positiveLast = validList[i - 1];
    var positiveItem = validList[i];
    var positiveNext = validList[i + 1];
 
    if (positiveLast.Value < positiveItem.Value && positiveItem.Value > positiveNext.Value)
    {
        if (bottom == null)
        {
            asc = false;
        }
        top = positiveItem;
 
        *//*    for (int j = i - 1; j > 0; j--)
            {
                var negativeLast = validList[j];
                if (negativeLast.Value > positiveItem.Value)
                {
                    var a = negativeLast.Value - positiveItem.Value;
                    break;
                }
            }
            _allBindList.Add(new TimeValue(positiveItem.Time, positiveItem.Value));*//*
    }
    else if (positiveLast.Value > positiveItem.Value && positiveItem.Value < positiveNext.Value)
    {
        if (top == null)
        {
            asc = true;
        }
        bottom = positiveItem;
    }
    if (bottom != null && bottom != null)
    {
        if (asc)
        {
            var ascValue = top.Value - bottom.Value;
            bottom = null;
        }
        else
        {
            var descValue = bottom.Value - top.Value;
            top = null;
        }
    }
}*/