ResultModel.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace MeterVision.model
  7. {
  8. public class ResultModel
  9. {
  10. private static double divisor = 10000;
  11. public static Dictionary<uint,int> decimalPlaceMapping = new Dictionary<uint, int>
  12. {
  13. { 10000000, -3 }, // 100000 表示负 1 位小数,10000立方
  14. { 1000000, -2 }, // 100000 表示负 1 位小数,100立方
  15. { 100000, -1 }, // 100000 表示负 1 位小数,10立方
  16. { 10000, 0 }, // 10000 表示 0 位小数,即 1 立方
  17. { 1000, 1 }, // 1000 表示 1 位小数,即 0.1 立方
  18. { 100, 2 }, // 100 表示 2 位小数,即 0.01 立方
  19. { 10, 3 }, // 10 表示 3 位小数,即 0.001 立方
  20. { 1, 4 } // 1 表示 4 位小数,即 0.0001 立方
  21. };
  22. public string SrcImage { get; set; }
  23. //public string RunFlag { get; set; }
  24. //public string RunTime { get; set; }
  25. public string DstImage { get; set; }
  26. //仪表类型(0:不是水表图片,1:数字+指针,2:全指针 3:全数字)
  27. public int MeterType { get; set; }
  28. public int DigitCount { get; set; }
  29. public int PointerCount { get; set; }
  30. //小数尾数
  31. public int DecimalPlaces
  32. {
  33. get
  34. {
  35. if(decimalPlaceMapping.TryGetValue(LastUnit, out int decimalPlaces))
  36. {
  37. return decimalPlaces;
  38. }
  39. return 0;
  40. }
  41. }
  42. //1DL单位
  43. //单位等级0x00 - 0x08(0.0001 - 10000m³)
  44. public uint LastUnit { get; set; }
  45. public string SLastUnit
  46. {
  47. get => GetSValueByIValue(LastUnit);
  48. }
  49. public int ResultType { get; set; }
  50. public ulong RawValue { get; set; }
  51. public string SRawValue
  52. {
  53. get => GetSValueByIValue(RawValue);
  54. }
  55. public ulong FinalValue { get; set; }
  56. public string sFinalValue
  57. {
  58. get => GetSValueByIValue(FinalValue);
  59. }
  60. public string AiVer { get; set; }
  61. public byte[] DebugInfoBytes { get; set; }
  62. public string LogPath { get; set; }
  63. public ResultModel()
  64. {
  65. }
  66. private string GetSValueByIValue(ulong iValue)
  67. {
  68. if (DecimalPlaces > 0)
  69. {
  70. double value = (double)iValue / divisor;
  71. // 不进行四舍五入,使用 Math.Truncate 来截断小数部分
  72. value = Math.Truncate(value * Math.Pow(10, DecimalPlaces)) / Math.Pow(10, DecimalPlaces);
  73. return value.ToString($"F{DecimalPlaces}");
  74. //return value.ToString($"F{DecimalPlaces}");
  75. }
  76. else
  77. {
  78. double value = (double)(iValue / divisor) * Math.Pow(10, Math.Abs(DecimalPlaces));
  79. // 不进行四舍五入,使用 Math.Truncate 来截断小数部分
  80. value = Math.Truncate(value);
  81. return value.ToString("F0");
  82. }
  83. }
  84. //------------------------------------------------------
  85. }
  86. }