using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Model
|
{
|
public partial class MonitorFluctRecord
|
{
|
/// <summary>
|
/// 验证
|
/// </summary>
|
public bool Verify()
|
{
|
if (this.TimeArray == null || this.TimeArray.Count < 1)
|
return default;
|
if (this.MaxValues == null || this.MaxValues.Count < 1)
|
return default;
|
if (this.MinValues == null || this.MinValues.Count < 1)
|
return default;
|
if ((this.TimeArray.Count == this.MaxValues.Count) && (this.MaxValues.Count == this.MinValues.Count))
|
return true;
|
return default;
|
}
|
|
/// <summary>
|
/// 获取最小值
|
/// </summary>
|
public double? GetMinValue(DateTime time)
|
{
|
if (!Verify())
|
return default;
|
var seconds = (int)Math.Floor(time.TimeOfDay.TotalSeconds);
|
var index = this.TimeArray.IndexOf(seconds);
|
if (index < 0)
|
return default;
|
return this.MinValues[index];
|
}
|
|
/// <summary>
|
/// 获取大约最小值
|
/// </summary>
|
public double? GetRoundMinValue(DateTime time)
|
{
|
if (!Verify())
|
return default;
|
var seconds = (int)Math.Floor(time.TimeOfDay.TotalSeconds);
|
var index = this.TimeArray.IndexOf(seconds);
|
if (index < 0)
|
{
|
var smallerIndex = this.TimeArray.FindLastIndex(x => x < seconds);
|
var biggerIndex = this.TimeArray.FindIndex(x => x > seconds);
|
if (smallerIndex > -1)
|
{
|
//大一点和小一点的都存在
|
if (biggerIndex > -1)
|
{
|
var smaller = this.MinValues[smallerIndex];
|
var bigger = this.MinValues[biggerIndex];
|
var value = smaller + (bigger - smaller) / (this.TimeArray[biggerIndex] - this.TimeArray[smallerIndex]) * (seconds - this.TimeArray[smallerIndex]);
|
return value;
|
}
|
else//小一点的存在 大一点的不存在
|
{
|
var smaller = this.MinValues[smallerIndex];
|
return smaller;
|
}
|
}
|
else
|
{
|
//小一点的不存在 大一点的存在
|
if (biggerIndex > -1)
|
{
|
var bigger = this.MinValues[biggerIndex];
|
return bigger;
|
}
|
else//小一点的和大一点的都不存在
|
{
|
return default;
|
}
|
}
|
|
}
|
return this.MinValues[index];
|
}
|
|
/// <summary>
|
/// 获取最大值
|
/// </summary>
|
public double? GetMaxValue(DateTime time)
|
{
|
if (!Verify())
|
return default;
|
var seconds = (int)Math.Floor(time.TimeOfDay.TotalSeconds);
|
var index = this.TimeArray.IndexOf(seconds);
|
if (index < 0)
|
return default;
|
return this.MaxValues[index];
|
}
|
|
/// <summary>
|
/// 获取大约最大值
|
/// </summary>
|
public double? GetRoundMaxValue(DateTime time)
|
{
|
if (!Verify())
|
return default;
|
var seconds = (int)Math.Floor(time.TimeOfDay.TotalSeconds);
|
var index = this.TimeArray.IndexOf(seconds);
|
if (index < 0)
|
{
|
var smallerIndex = this.TimeArray.FindLastIndex(x => x < seconds);
|
var biggerIndex = this.TimeArray.FindIndex(x => x > seconds);
|
if (smallerIndex > -1)
|
{
|
//大一点和小一点的都存在
|
if (biggerIndex > -1)
|
{
|
var smaller = this.MaxValues[smallerIndex];
|
var bigger = this.MaxValues[biggerIndex];
|
var value = smaller + (bigger - smaller) / (this.TimeArray[biggerIndex] - this.TimeArray[smallerIndex]) * (seconds - this.TimeArray[smallerIndex]);
|
return value;
|
}
|
else//小一点的存在 大一点的不存在
|
{
|
var smaller = this.MaxValues[smallerIndex];
|
return smaller;
|
}
|
}
|
else
|
{
|
//小一点的不存在 大一点的存在
|
if (biggerIndex > -1)
|
{
|
var bigger = this.MaxValues[biggerIndex];
|
return bigger;
|
}
|
else//小一点的和大一点的都不存在
|
{
|
return default;
|
}
|
}
|
}
|
return this.MaxValues[index];
|
}
|
|
/// <summary>
|
/// 设置值
|
/// </summary>
|
public void SetValue(DateTime time, double value)
|
{
|
if (this.TimeArray == null)
|
this.TimeArray = new List<int>();
|
if (this.MaxValues == null)
|
this.MaxValues = new List<double>();
|
if (this.MinValues == null)
|
this.MinValues = new List<double>();
|
var seconds = (int)Math.Floor(time.TimeOfDay.TotalSeconds);
|
var index = this.TimeArray.IndexOf(seconds);
|
if (index < 0)
|
{
|
var biggerIndex = this.TimeArray.FindIndex(x => x > seconds);
|
if (biggerIndex < 0)
|
{
|
this.TimeArray.Add(seconds);
|
this.MaxValues.Add(value);
|
this.MinValues.Add(value);
|
}
|
else
|
{
|
this.TimeArray.Insert(biggerIndex, seconds);
|
this.MaxValues.Insert(biggerIndex, value);
|
this.MinValues.Insert(biggerIndex, value);
|
}
|
}
|
else
|
{
|
if (this.MaxValues[index] < value)
|
this.MaxValues[index] = value;
|
if (this.MinValues[index] > value)
|
this.MinValues[index] = value;
|
}
|
}
|
|
}
|
}
|