|
@@ -154,49 +154,132 @@ namespace MeterVision.db
|
|
|
ResultType = 1;
|
|
|
|
|
|
//存储图像
|
|
|
- string dstImagPath = CfginiItem.GetConfigItem().DstImgPath;
|
|
|
- dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd());
|
|
|
- if (!Directory.Exists(dstImagPath))
|
|
|
+ if (apiResult.recognResult.data.image != null)
|
|
|
{
|
|
|
- Directory.CreateDirectory(dstImagPath);
|
|
|
+ string dstImagPath = CfginiItem.GetConfigItem().DstImgPath;
|
|
|
+ dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd());
|
|
|
+ if (!Directory.Exists(dstImagPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(dstImagPath);
|
|
|
+ }
|
|
|
+ dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg");
|
|
|
+ //SaveBigJpg(api, dstImagPath);
|
|
|
+ //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
|
|
|
+ bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
|
|
|
+ DstImage = blSaveImage ? dstImagPath : string.Empty;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DstImage = "";
|
|
|
}
|
|
|
- dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg");
|
|
|
- //SaveBigJpg(api, dstImagPath);
|
|
|
- //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
|
|
|
- bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
|
|
|
|
|
|
- DstImage = blSaveImage ? dstImagPath : string.Empty;
|
|
|
|
|
|
//存储日志
|
|
|
- string aiLogPath = CfginiItem.GetConfigItem().AiLogPath;
|
|
|
- aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd());
|
|
|
- if (!Directory.Exists(aiLogPath))
|
|
|
+ if (!string.IsNullOrEmpty(apiResult.recognResult.data.logs))
|
|
|
+ {
|
|
|
+ string aiLogPath = CfginiItem.GetConfigItem().AiLogPath;
|
|
|
+ aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd());
|
|
|
+ if (!Directory.Exists(aiLogPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(aiLogPath);
|
|
|
+ }
|
|
|
+ aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt");
|
|
|
+ bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath);
|
|
|
+
|
|
|
+ LogPath = blSaveLog ? aiLogPath : string.Empty;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- Directory.CreateDirectory(aiLogPath);
|
|
|
+ LogPath = "";
|
|
|
}
|
|
|
- aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt");
|
|
|
- bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath);
|
|
|
|
|
|
- LogPath = blSaveLog ? aiLogPath : string.Empty;
|
|
|
+ if (apiResult.recognResult.data != null)
|
|
|
+ {
|
|
|
+ if(apiResult.recognResult.data.reading == null)
|
|
|
+ {
|
|
|
+ FinalValue = long.MaxValue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FinalValue = (long)(apiResult.recognResult.data.reading * 10000);
|
|
|
+ }
|
|
|
+ //先借用配置的字段存放识别的数据
|
|
|
+ //空的时候保存最大值
|
|
|
+ if (apiResult.recognResult.data.meter_type == null)
|
|
|
+ {
|
|
|
+ MeterType = int.MaxValue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MeterType = (int)apiResult.recognResult.data.meter_type;
|
|
|
+ }
|
|
|
|
|
|
+ if (apiResult.recognResult.data.reading_unit == null)
|
|
|
+ {
|
|
|
+ LastUnit = double.MaxValue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LastUnit = (double)apiResult.recognResult.data.reading_unit;
|
|
|
+ }
|
|
|
|
|
|
- FinalValue = (long)(apiResult.recognResult.data.reading * 10000);
|
|
|
+ if (string.IsNullOrWhiteSpace(StandValue))
|
|
|
+ {
|
|
|
+ //EqualFlag = 2;
|
|
|
+ EqualFlag = 2; //无标准值可供比较(理论上不会出现这种情况)
|
|
|
+ }
|
|
|
+ else if (MeterType == int.MaxValue || LastUnit == double.MaxValue || FinalValue == long.MaxValue)
|
|
|
+ {
|
|
|
+ EqualFlag = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (MeterType == 0 || MeterType == 88 || MeterType == 90)
|
|
|
+ {
|
|
|
+ EqualFlag = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (double.TryParse(StandValue, out double dStandValue))
|
|
|
+ {
|
|
|
+ //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
|
|
|
+ //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
|
|
|
+ EqualFlag = GetEqualFlag_http(dStandValue, FinalValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // if (double.TryParse(StandValue, out double dStandValue))
|
|
|
+ // {
|
|
|
+ // //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
|
|
|
+ // //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
|
|
|
+ // EqualFlag = (long)(dStandValue * 10000) == FinalValue ? 1 : 0;
|
|
|
+
|
|
|
+ // }//if
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FinalValue = long.MaxValue;
|
|
|
+ LastUnit = double.MaxValue;
|
|
|
+ MeterType = int.MaxValue;
|
|
|
+ EqualFlag = 2;
|
|
|
+ }
|
|
|
|
|
|
- if (string.IsNullOrWhiteSpace(StandValue))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //等于0说明调用成功,但是AI服务未识别成功
|
|
|
+ if (apiResult.recognResult.result == 0)
|
|
|
{
|
|
|
- //EqualFlag = 2;
|
|
|
- EqualFlag = 3; //无标准值可供比较(理论上不会出现这种情况)
|
|
|
+ Memo = apiResult.recognResult.message;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (double.TryParse(StandValue, out double dStandValue))
|
|
|
- {
|
|
|
- //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
|
|
|
- //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
|
|
|
- EqualFlag = (long)(dStandValue * 10000) == FinalValue ? 1 : 0;
|
|
|
-
|
|
|
- }//if
|
|
|
+ Memo = "";
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -244,48 +327,119 @@ namespace MeterVision.db
|
|
|
ResultType = 1;
|
|
|
|
|
|
//存储图像
|
|
|
- string dstImagPath = CfginiItem.GetConfigItem().DstImgPath;
|
|
|
- dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd());
|
|
|
- if (!Directory.Exists(dstImagPath))
|
|
|
+ if (apiResult.recognResult.data.image != null)
|
|
|
{
|
|
|
- Directory.CreateDirectory(dstImagPath);
|
|
|
+ string dstImagPath = CfginiItem.GetConfigItem().DstImgPath;
|
|
|
+ dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd());
|
|
|
+ if (!Directory.Exists(dstImagPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(dstImagPath);
|
|
|
+ }
|
|
|
+ dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg");
|
|
|
+ //SaveBigJpg(api, dstImagPath);
|
|
|
+ //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
|
|
|
+ bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
|
|
|
+ DstImage = blSaveImage ? dstImagPath : string.Empty;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DstImage = "";
|
|
|
}
|
|
|
- dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg");
|
|
|
- //SaveBigJpg(api, dstImagPath);
|
|
|
- //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
|
|
|
- bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
|
|
|
|
|
|
- DstImage = blSaveImage ? dstImagPath : string.Empty;
|
|
|
|
|
|
//存储日志
|
|
|
- string aiLogPath = CfginiItem.GetConfigItem().AiLogPath;
|
|
|
- aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd());
|
|
|
- if (!Directory.Exists(aiLogPath))
|
|
|
+ if (!string.IsNullOrEmpty(apiResult.recognResult.data.logs))
|
|
|
{
|
|
|
- Directory.CreateDirectory(aiLogPath);
|
|
|
+ string aiLogPath = CfginiItem.GetConfigItem().AiLogPath;
|
|
|
+ aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd());
|
|
|
+ if (!Directory.Exists(aiLogPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(aiLogPath);
|
|
|
+ }
|
|
|
+ aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt");
|
|
|
+ bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath);
|
|
|
+ LogPath = blSaveLog ? aiLogPath : string.Empty;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogPath = "";
|
|
|
}
|
|
|
- aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt");
|
|
|
- bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath);
|
|
|
|
|
|
- LogPath = blSaveLog ? aiLogPath : string.Empty;
|
|
|
+ if (apiResult.recognResult.data.reading != null)
|
|
|
+ {
|
|
|
+ if (apiResult.recognResult.data.reading == null)
|
|
|
+ {
|
|
|
+ FinalValue = long.MaxValue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FinalValue = (long)(apiResult.recognResult.data.reading * 10000);
|
|
|
+ }
|
|
|
+ //先借用配置的字段存放识别的数据
|
|
|
+ //空的时候保存最大值
|
|
|
+ if (apiResult.recognResult.data.meter_type == null)
|
|
|
+ {
|
|
|
+ MeterType = int.MaxValue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MeterType = (int)apiResult.recognResult.data.meter_type;
|
|
|
+ }
|
|
|
|
|
|
+ if (apiResult.recognResult.data.reading_unit == null)
|
|
|
+ {
|
|
|
+ LastUnit = double.MaxValue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LastUnit = (double)apiResult.recognResult.data.reading_unit;
|
|
|
+ }
|
|
|
|
|
|
- FinalValue = (long)(apiResult.recognResult.data.reading * 10000);
|
|
|
|
|
|
- if (string.IsNullOrWhiteSpace(StandValue))
|
|
|
- {
|
|
|
- //EqualFlag = 2;
|
|
|
- EqualFlag = 3; //无标准值可供比较(理论上不会出现这种情况)
|
|
|
+
|
|
|
+ if (string.IsNullOrWhiteSpace(StandValue))
|
|
|
+ {
|
|
|
+ //EqualFlag = 2;
|
|
|
+ EqualFlag = 2; //无标准值可供比较(理论上不会出现这种情况)
|
|
|
+ }
|
|
|
+ else if (MeterType == int.MaxValue || LastUnit == double.MaxValue || FinalValue == long.MaxValue)
|
|
|
+ {
|
|
|
+ EqualFlag = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (MeterType == 0 || MeterType == 88 || MeterType == 90)
|
|
|
+ {
|
|
|
+ EqualFlag = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (double.TryParse(StandValue, out double dStandValue))
|
|
|
+ {
|
|
|
+ //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
|
|
|
+ //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
|
|
|
+ //EqualFlag = (long)(dStandValue * 10000) == FinalValue ? 1 : 0;
|
|
|
+ EqualFlag = GetEqualFlag_http(dStandValue, FinalValue);
|
|
|
+ }//if
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (double.TryParse(StandValue, out double dStandValue))
|
|
|
- {
|
|
|
- //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
|
|
|
- //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
|
|
|
- EqualFlag = (long)(dStandValue * 10000) == FinalValue ? 1 : 0;
|
|
|
+ FinalValue = long.MaxValue;
|
|
|
+ LastUnit = double.MaxValue;
|
|
|
+ MeterType = int.MaxValue;
|
|
|
+ EqualFlag = 2;
|
|
|
+ }
|
|
|
|
|
|
- }//if
|
|
|
+ //等于0说明调用成功,但是服务并未AI识别成功
|
|
|
+ if(apiResult.recognResult.result == 0)
|
|
|
+ {
|
|
|
+ Memo = apiResult.recognResult.message;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Memo = "";
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -422,7 +576,6 @@ namespace MeterVision.db
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public int GetEqualFlag(double standValue, long finalValue)
|
|
|
{
|
|
|
bool isEqual = false;
|
|
@@ -433,9 +586,14 @@ namespace MeterVision.db
|
|
|
{
|
|
|
//数字+指针(只比较数字部分)
|
|
|
//获取真正数据部分的值
|
|
|
- int standValue1 = (int)(standValue / LastUnit);
|
|
|
+ //int standValue1 = (int)(standValue / LastUnit);
|
|
|
+ //int standValue1 = (int)((long)(standValue * 10000) / (long)(LastUnit * 10000));
|
|
|
+ int standValue1 = (int)Math.Round(standValue / LastUnit);
|
|
|
+
|
|
|
//(int)Math.Ceiling(standValue / LastUnit);
|
|
|
- int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
|
|
|
+ //int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
|
|
|
+ int finalValue1 = (int)Math.Round(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
|
|
|
+
|
|
|
//isEqual = (standValue1 == finalValue1);
|
|
|
|
|
|
//判断如果按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
|
|
@@ -466,6 +624,52 @@ namespace MeterVision.db
|
|
|
return 2;
|
|
|
}
|
|
|
|
|
|
+ public int GetEqualFlag_http(double standValue, long finalValue)
|
|
|
+ {
|
|
|
+ bool isEqual = false;
|
|
|
+
|
|
|
+ //if (MeterType == 1 || MeterType == 3)
|
|
|
+ //{
|
|
|
+ //数字+指针(只比较数字部分)
|
|
|
+ //获取真正数据部分的值
|
|
|
+ //int standValue1 = (int)(standValue / LastUnit);
|
|
|
+ //int standValue1 = (int)((long)(standValue * 10000) / (long)(LastUnit * 10000));
|
|
|
+ int standValue1 = (int)Math.Round(standValue / LastUnit);
|
|
|
+
|
|
|
+ //(int)Math.Ceiling(standValue / LastUnit);
|
|
|
+ //int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
|
|
|
+ int finalValue1 = (int)Math.Round(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
|
|
|
+
|
|
|
+ //isEqual = (standValue1 == finalValue1);
|
|
|
+
|
|
|
+ //判断如果按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
|
|
|
+
|
|
|
+ isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
|
|
|
+
|
|
|
+ if (isEqual == false && JudgeLastnumFlag == 0)
|
|
|
+ {
|
|
|
+ int standValue1_lastnum = standValue1 % 10;
|
|
|
+ int finalValue1_lastnum = finalValue1 % 10;
|
|
|
+ //上面的值,也就规划为数字的整数
|
|
|
+ int standValue2 = standValue1 - standValue1_lastnum;
|
|
|
+ int finalValue2 = finalValue1 - finalValue1_lastnum;
|
|
|
+ isEqual = standValue2 == finalValue2;
|
|
|
+ }
|
|
|
+ return isEqual ? 1 : 0;
|
|
|
+ //}
|
|
|
+ //else if (MeterType == 2)
|
|
|
+ //{
|
|
|
+ // int standValue1 = (int)standValue;
|
|
|
+ // int finalValue1 = (int)(finalValue / FaConstant.CUBE_VALUE);
|
|
|
+
|
|
|
+ // isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
|
|
|
+
|
|
|
+ // return isEqual ? 1 : 0;
|
|
|
+ //}
|
|
|
+ //return 2;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//恢复运行时的默认值
|
|
|
public void ResetRunValue()
|