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++;
|
// }
|
//}
|
}
|
}
|
}
|