123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MeterVision.model
- {
- public class ResultModel
- {
- private static double divisor = 10000;
- public static Dictionary<uint,int> decimalPlaceMapping = new Dictionary<uint, int>
- {
- { 10000000, -3 }, // 100000 表示负 1 位小数,10000立方
- { 1000000, -2 }, // 100000 表示负 1 位小数,100立方
- { 100000, -1 }, // 100000 表示负 1 位小数,10立方
- { 10000, 0 }, // 10000 表示 0 位小数,即 1 立方
- { 1000, 1 }, // 1000 表示 1 位小数,即 0.1 立方
- { 100, 2 }, // 100 表示 2 位小数,即 0.01 立方
- { 10, 3 }, // 10 表示 3 位小数,即 0.001 立方
- { 1, 4 } // 1 表示 4 位小数,即 0.0001 立方
- };
- public string SrcImage { get; set; }
- //public string RunFlag { get; set; }
- //public string RunTime { get; set; }
- public string DstImage { get; set; }
- //仪表类型(0:不是水表图片,1:数字+指针,2:全指针 3:全数字)
- public int MeterType { get; set; }
- public int DigitCount { get; set; }
-
- public int PointerCount { get; set; }
- //小数尾数
- public int DecimalPlaces
- {
- get
- {
- if(decimalPlaceMapping.TryGetValue(LastUnit, out int decimalPlaces))
- {
- return decimalPlaces;
- }
- return 0;
- }
- }
- //1DL单位
- //单位等级0x00 - 0x08(0.0001 - 10000m³)
- public uint LastUnit { get; set; }
- public string SLastUnit
- {
- get => GetSValueByIValue(LastUnit);
- }
- public int ResultType { get; set; }
- public ulong RawValue { get; set; }
- public string SRawValue
- {
- get => GetSValueByIValue(RawValue);
- }
- public ulong FinalValue { get; set; }
- public string sFinalValue
- {
- get => GetSValueByIValue(FinalValue);
- }
- public string AiVer { get; set; }
- public byte[] DebugInfoBytes { get; set; }
- public string LogPath { get; set; }
- public ResultModel()
- {
- }
- private string GetSValueByIValue(ulong iValue)
- {
- if (DecimalPlaces > 0)
- {
- double value = (double)iValue / divisor;
- // 不进行四舍五入,使用 Math.Truncate 来截断小数部分
- value = Math.Truncate(value * Math.Pow(10, DecimalPlaces)) / Math.Pow(10, DecimalPlaces);
- return value.ToString($"F{DecimalPlaces}");
- //return value.ToString($"F{DecimalPlaces}");
- }
- else
- {
- double value = (double)(iValue / divisor) * Math.Pow(10, Math.Abs(DecimalPlaces));
- // 不进行四舍五入,使用 Math.Truncate 来截断小数部分
- value = Math.Truncate(value);
- return value.ToString("F0");
- }
- }
- //------------------------------------------------------
- }
- }
|