duheng
2025-02-11 7e0414c91a51219a92515c90ccb803ebade5613a
WaterPredict/IStation.ChEr.WebApi.Predict/ÈÎÎñ/PredictHelper.cs
@@ -1,9 +1,7 @@
using IStation.Application;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using Yw;
using static IStation.ChEr.Application.SSAData;
namespace IStation.ChEr.WebApi
{
@@ -11,16 +9,114 @@
    {
        public static bool IsOpenState()
        {
            var result = ConnectHelper.GetByPumpOpenState(DateTime.Now, DateTime.Now.AddHours(-1));
            var result = ConnectHelper.GetByPumpOpenState(DateTime.Now, DateTime.Now.AddDays(1));
            foreach (var item in result)
            {
                if (item.Total != 0)
                if (item.DateTime.Hour == DateTime.Now.Hour)
                {
                    LogHelper.Info("开机时间与累计流量不对应");
                    return true;
                    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++;
            //    }
            //}
        }
    }
}