duheng
2025-02-07 c5136b7517998a076f1bd2e4abdda01decae8b6f
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
using IStation.Application;
using System.Net.Sockets;
using Yw;
using static IStation.ChEr.Application.SSAData;
 
namespace IStation.ChEr.WebApi
{
    internal class PredictHelper
    {
        public static bool IsOpenState()
        {
            var result = ConnectHelper.GetByPumpOpenState(DateTime.Now, DateTime.Now.AddDays(1));
            foreach (var item in result)
            {
                if (item.DateTime.Hour == DateTime.Now.Hour)
                {
                    if (item.Total != 0)
                    {
                        LogHelper.Info("开机时间与累计流量不对应");
                        return true;
                    }
                    return false;
                }
            }
            return false;
        }
 
        public static double GetAccWater(List<RealScadaData> arrarlist, int code, out string error)
        {
            /* var json = File.ReadAllText("C:\\Users\\ZKC\\Desktop\\7-2.txt");
             var alllist2 = JsonHelper.Json2Object<List<double>>(json);
             //var RealData = ConnectHelper.GetByPumpNowDayAndLastDayRealData(DateTime.Today, "120s");
             //var select = RealData[code].MonitorRecords;
             //var timebucket = select.Where(x => x.Time.Hour <= dateTime.Hour && x.Time.Hour >= dateTime.Hour).ToList();
 */
            error = string.Empty;
            var select = arrarlist[code].MonitorRecords;
            var alllist = select.Select(x => x.Value).ToList();
            LogHelper.Info("数据个数" + alllist.Count.ToString());
            var total = GetAccWater(alllist, out error);
            return total;
        }
 
        //获取小时内累计流量
        public static double GetAccWater(List<double?> realdata, out string error)
        {
            error = string.Empty;
            if (realdata.Count < 28)
            {
                error = "小时内数据不足28个点";
                return 0;
            }
            if (realdata == null)
            {
                error = "小时内数据为空";
                return 0;
            }
 
            var realdata2 = (from x in realdata where x >= 0 && x != null select x.Value).ToList();
            LogHelper.Info("一小时内数据" + JsonHelper.Object2Json(realdata2));
            return GetAccWater(realdata2, out error);
        }
 
        public static double GetAccWater(List<double> realdata2, out string error)
        {
            error = string.Empty;
            int lowtotalcount = 0; //总计下降次数
            var startValue = realdata2.FirstOrDefault();
            double total = 0;
            for (int i = 1; i < realdata2.Count(); i++)
            {
                if (realdata2[i - 1] > realdata2[i])
                {
                    lowtotalcount++;
                    total = total + realdata2[i - 1] - startValue;
                    startValue = realdata2[i];
                }
                if (i == realdata2.Count() - 1)
                {
                    if (realdata2[i] > realdata2[i - 1])
                    {
                        total = total + realdata2[i] - startValue;
                    }
                }
            }
            if (lowtotalcount >= 3)
            {
                error = "小时内连续清零次数较多";
            }
            return total;
 
            //double total = 0;
            //int startindex = 0;  //比较的开始下标
            //int lowtotalcount = 0; //总计下降次数
            //for (int i = 0; i < realdata.Count - 1; i++)
            //{
            //    var current = realdata[i];
            //    var next = realdata[i + 1];
            //    if (!current.HasValue || !next.HasValue)
            //    {
            //        continue;
            //    }
 
            //    // 在这里进行比较
            //    if (next > current)
            //    {
            //        if (i == realdata.Count - 2)
            //        {
            //            total += (double)(next - realdata[startindex].Value);
            //        }
            //        continue;
            //    }
            //    else
            //    {
            //        total += (double)(current.Value - realdata[startindex].Value);
            //        startindex = i + 1;
            //        lowtotalcount++;
            //    }
            //}
        }
    }
}