TPatchDetail.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using MeterVision.Config;
  2. using MeterVision.FreeAi;
  3. using MeterVision.model;
  4. using MeterVision.Util;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace MeterVision.db
  11. {
  12. public class TPatchDetail
  13. {
  14. public string PatchDetailId { get; set; }
  15. public string PatchId { get; set; }
  16. public string CreateTime { get; set; }
  17. public string StandDetailId { get; set; }
  18. public string StandValue { get; set; }
  19. public string SrcImage { get; set; }
  20. public string SampleTime { get; set; } //图片的采样时间
  21. public int RunFlag { get; set; }
  22. public string RunTime { get; set; }
  23. public string DstImage { get; set; }
  24. public int ResultType { get; set; }
  25. public long RawValue { get; set; }
  26. public long FinalValue { get; set; }
  27. public long CompleteValue { get; set; } //识别后的完整结果
  28. public int ValueChanged { get; set; }
  29. public int ResultMeter { get; set; } //识别后的水表类型
  30. //0:还未运行比较 1:比较后相等 2:比较后不等 3:比较后识别无效
  31. public int EqualFlag { get; set; }
  32. public string AiVer { get; set; }
  33. public string DebugInfo { get; set; }
  34. public string LogPath { get; set; }
  35. public string Memo { get; set; }
  36. //--20250313 add by djs
  37. public string StationKey { get; set; } //站点表-主键
  38. public string StationId { get; set; } //站点ID
  39. public int MeterType { get; set; }
  40. public double BrightVal { get; set; } //配置参数-图片亮度
  41. public int FlowRate { get; set; } //配置参数-每小时最大水流
  42. public int DigitCount { get; set; }
  43. public int PointerCount { get; set; }
  44. public double LastUnit { get; set; }
  45. public string MeterRegion { get; set; } //配置参数-表盘区域
  46. public string FeatureRegion { get; set; } //配置参数-特征区域
  47. public int LastCompress { get; set; } //上一次压缩大小
  48. public long LatestValue { get; set; } //上次正确结果值
  49. public string LatestTime { get; set; } //上次正确值的时间
  50. public long LatestComplete { get; set; } //上次完整结果值
  51. // 构造函数,初始化默认值
  52. public TPatchDetail()
  53. {
  54. PatchDetailId = string.Empty;
  55. PatchId = string.Empty;
  56. CreateTime = string.Empty;
  57. StandDetailId = string.Empty;
  58. StandValue = string.Empty;
  59. SrcImage = string.Empty;
  60. RunFlag = 0;
  61. RunTime = string.Empty;
  62. DstImage = string.Empty;
  63. MeterType = -1;
  64. DigitCount = -1;
  65. PointerCount = -1;
  66. LastUnit = -1;
  67. ResultType = 0;
  68. RawValue = -1;
  69. FinalValue = -1;
  70. EqualFlag = 0;
  71. AiVer = string.Empty;
  72. DebugInfo = string.Empty;
  73. LogPath = string.Empty;
  74. Memo = string.Empty;
  75. StationKey = string.Empty;
  76. StationId = string.Empty;
  77. ResultMeter = -1;
  78. CompleteValue = -1;
  79. ValueChanged = -1;
  80. BrightVal = 1.2f;
  81. FlowRate = -1;
  82. MeterRegion = string.Empty;
  83. FeatureRegion = string.Empty;
  84. LastCompress = -1;
  85. LatestValue = -1;
  86. LatestTime = string.Empty;
  87. LatestComplete = -1;
  88. }
  89. public TPatchDetail(PatchDetailItem patchDetail, ResultModel resultModel)
  90. {
  91. //PatchDetailId = patchDetail.PatchDetailId;
  92. //PatchId = patchDetail.PatchId;
  93. //CreateTime = patchDetail.CreateTime;
  94. //StandDetailId = patchDetail.StandDetailId;
  95. //StandValue = patchDetail.StandValue;
  96. //SrcImage = patchDetail.SrcImage;
  97. ObjectHelper.CopyMatchingFields(patchDetail, this);
  98. RunFlag = 1;
  99. RunTime = ThisApp.GetNowTime_yyyyMMddHHmmss();
  100. DstImage = resultModel.DstImage;
  101. ResultMeter = resultModel.ResultMeter;
  102. ResultType = resultModel.ResultType;
  103. RawValue = (long)resultModel.RawValue; //resultModel.SRawValue;
  104. FinalValue = (long)resultModel.FinalValue; //resultModel.sFinalValue;
  105. CompleteValue = (long)resultModel.CompleteValue; //resultModel.sCompleteValue;
  106. AiVer = resultModel.AiVer;
  107. LogPath = resultModel.LogPath;
  108. // 使用 LINQ 进行转换和条件判断
  109. var formattedBytes = resultModel.DebugInfoBytes.Select(b => b == 88 ? "" : b.ToString());
  110. DebugInfo = string.Join(",", formattedBytes);
  111. //EqualFlag,这里需要判断,是否相等、约等、不等
  112. //先简单判断
  113. //20250317 delte by djs (无标准值的数据不会进入到这里
  114. if (string.IsNullOrWhiteSpace(StandValue))
  115. {
  116. //EqualFlag = 2;
  117. EqualFlag = -1; //无标准值可供比较(理论上不会出现这种情况)
  118. }
  119. else
  120. {
  121. if (double.TryParse(StandValue, out double dStandValue))
  122. {
  123. //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
  124. EqualFlag = GetEqualFlag(dStandValue, FinalValue);
  125. }//if
  126. }
  127. }
  128. //设置结果
  129. public void SetResult(ResultModel resultModel)
  130. {
  131. RunFlag = 1;
  132. RunTime = ThisApp.GetNowTime_yyyyMMddHHmmss();
  133. DstImage = resultModel.DstImage;
  134. //MeterType = resultModel.MeterType;
  135. ResultMeter = resultModel.ResultMeter;
  136. ResultType = resultModel.ResultType;
  137. RawValue = (long)resultModel.RawValue;
  138. FinalValue = (long)resultModel.FinalValue;
  139. CompleteValue = (long)resultModel.CompleteValue;
  140. AiVer = resultModel.AiVer;
  141. LogPath = resultModel.LogPath;
  142. // 使用 LINQ 进行转换和条件判断
  143. var formattedBytes = resultModel.DebugInfoBytes.Select(b => b == 88 ? "" : b.ToString());
  144. DebugInfo = string.Join(",", formattedBytes);
  145. //EqualFlag,这里需要判断,是否相等、约等、不等
  146. //先简单判断
  147. if (string.IsNullOrWhiteSpace(StandValue))
  148. {
  149. EqualFlag = -1;
  150. }
  151. else
  152. {
  153. //if (int.TryParse(StandValue, out int iStandValue))
  154. if(double.TryParse(StandValue,out double dStandValue))
  155. {
  156. //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
  157. EqualFlag = GetEqualFlag(dStandValue, FinalValue);
  158. }
  159. }
  160. }
  161. public bool IsGoodResult()
  162. {
  163. bool isGood = false;
  164. if(MeterType == ResultMeter &&
  165. (ResultType == 1 || ResultType == 2 || ResultType == 7 || ResultType == 8))
  166. {
  167. isGood = true;
  168. }
  169. return isGood;
  170. }
  171. public bool CheckEquailityWithStandValue(double standValue, long finalValue)
  172. {
  173. bool isEqual = false;
  174. //比较结果值与标准值是否相等
  175. if (MeterType == ResultMeter)
  176. {
  177. if (MeterType == 1)
  178. {
  179. //数字+指针(只比较数字部分)
  180. //获取真正数据部分的值
  181. int standValue1 = (int)Math.Ceiling(standValue / LastUnit);
  182. int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
  183. //isEqual = (standValue1 == finalValue1);
  184. //判断如何按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
  185. //上面的值,也就规划为数字的整数
  186. isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
  187. return isEqual;
  188. }
  189. else if (MeterType == 2)
  190. {
  191. //全指针
  192. return (standValue * FaConstant.CUBE_VALUE) == finalValue;
  193. }
  194. else if (MeterType == 3)
  195. {
  196. //全数字
  197. return (standValue * FaConstant.CUBE_VALUE) == finalValue;
  198. }
  199. }
  200. return isEqual;
  201. }
  202. public int GetEqualFlag(double standValue, long finalValue)
  203. {
  204. bool isEqual = false;
  205. //比较结果值与标准值是否相等
  206. if (MeterType == ResultMeter)
  207. {
  208. if (MeterType == 1)
  209. {
  210. //数字+指针(只比较数字部分)
  211. //获取真正数据部分的值
  212. int standValue1 = (int)Math.Ceiling(standValue / LastUnit);
  213. int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
  214. //isEqual = (standValue1 == finalValue1);
  215. //判断如何按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
  216. //上面的值,也就规划为数字的整数
  217. isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
  218. return isEqual ? 1 : 0;
  219. }
  220. else if (MeterType == 2)
  221. {
  222. //全指针
  223. isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
  224. return isEqual ? 1 : 0;
  225. }
  226. else if (MeterType == 3)
  227. {
  228. //全数字
  229. //return (standValue * FaConstant.CUBE_VALUE) == finalValue;
  230. isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
  231. return isEqual ? 1 : 0;
  232. }
  233. else
  234. {
  235. return 2;
  236. }
  237. }
  238. else
  239. {
  240. return 2;
  241. }
  242. }
  243. //----------------------------------------------
  244. }
  245. ////////////////////////////////////////////////////////////
  246. }