ningshuxia
2023-04-13 13aeccc4305083d2d61274709a0066511fae42a1
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Model.Monitor 
{
    /// <summary>
    /// 比较映射计算公式参数
    /// </summary>
    public class CompareMappingCalculationFormulaParas : JsonModel<CompareMappingCalculationFormulaParas>
    {
        /// <summary>
        /// 测点标识
        /// </summary>
        public long ObjectID { get; set; }
 
        /// <summary>
        /// 映射关系
        /// </summary>
        public List<CompareMappingMatrix> 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;
        }
    }
}