using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Model.Monitor
|
{
|
/// <summary>
|
/// 区间映射计算公式参数
|
/// </summary>
|
public class RangeMappingCalculationFormulaParas : JsonModel<RangeMappingCalculationFormulaParas>
|
{
|
/// <summary>
|
/// 对象标识
|
/// </summary>
|
public long ObjectID { get; set; }
|
|
/// <summary>
|
/// 映射关系
|
/// </summary>
|
public List<RangeMappingMatrix> Mappings { get; set; }
|
|
/// <summary>
|
/// 计算
|
/// </summary>
|
public bool Calculate(double fromValue, out double toValue)
|
{
|
toValue = fromValue;
|
if (Mappings == null || Mappings.Count < 1)
|
return false;
|
var item = Mappings.Find(x => x.Meet(fromValue));
|
if (item == null)
|
return false;
|
toValue = item.Value;
|
return true;
|
}
|
|
/// <summary>
|
/// 计算
|
/// </summary>
|
public bool Calculate(string fromValue, out double toValue)
|
{
|
if (!double.TryParse(fromValue, out double value1))
|
{
|
toValue = value1;
|
return false;
|
}
|
if (!Calculate(value1, out double toValue1))
|
{
|
toValue = toValue1;
|
return false;
|
}
|
toValue = toValue1;
|
return true;
|
}
|
}
|
}
|