fix: play images optimize

master
Tongg 3 months ago
parent e5e1498e17
commit aa54652617
  1. 5
      App.config
  2. 13
      Model/Helper/ConfigurationHelper.cs
  3. 21
      Model/Services/SOCClientService.cs
  4. 4
      ViewModel/Grading/DiamondSelectVM.cs
  5. 7
      ViewModel/Grading/GradingLoadingVM.cs

@ -8,6 +8,8 @@
<add key="ImageFileBasePath" value="D:\diamond_images"/> <add key="ImageFileBasePath" value="D:\diamond_images"/>
<!-- 算法失败时,历史图片保存文件夹路径 --> <!-- 算法失败时,历史图片保存文件夹路径 -->
<add key="ImageHistoryPath" value="D:\ImageHistory"/> <add key="ImageHistoryPath" value="D:\ImageHistory"/>
<!-- 检测图片的总数 默认100 务必于SOC实际拍摄数量一致!!! -->
<add key="DetectImageTotal" value="100"/>
<!-- 安全空间保留 GB --> <!-- 安全空间保留 GB -->
<add key="SafeSpaceReservation" value="10"/> <add key="SafeSpaceReservation" value="10"/>
<!-- 打印机名称 --> <!-- 打印机名称 -->
@ -18,8 +20,9 @@
<add key="InternetCheckCycle" value="300000" /> <add key="InternetCheckCycle" value="300000" />
<!--网络质量检测阈值 Mbps--> <!--网络质量检测阈值 Mbps-->
<add key="InternetCheckMbps" value="866" /> <add key="InternetCheckMbps" value="866" />
<!--检测模式 0:json 1:Image Ohter:algorithm -->
<add key="RunModel" value="101" /> <add key="RunModel" value="101" />
<!-- 客户端版本 -->
<add key="AppVersion" value="Nlsqq/kAPIXFHKk9dFcfqw==" /> <add key="AppVersion" value="Nlsqq/kAPIXFHKk9dFcfqw==" />
</appSettings> </appSettings>
<connectionStrings> <connectionStrings>

@ -24,6 +24,19 @@ public class ConfigurationHelper
return ""; return "";
} }
} }
public static int ReadConfigValueToInteger(string key, int defaultV = 0)
{
if (int.TryParse(ReadConfigValue(key), out int i))
{
return i;
}
else
{
return defaultV;
}
}
/// <summary> /// <summary>
/// 写入配置 /// 写入配置
/// </summary> /// </summary>

@ -96,9 +96,12 @@ namespace SparkClient.Model.Services
}; };
} }
} }
private async Task<HttpResponseMessage> SendGetRequestImageAsync(string url) private async Task<HttpResponseMessage> SendGetRequestImageAsync(string url, string sendCode = "")
{ {
string sendCode = url.GenerateSign(); if (sendCode.IsNullOrEmpty())
{
sendCode = url.GenerateSign();
}
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
Logger.Info($"[SendCode={sendCode}]Request Image Download URL: {url}"); Logger.Info($"[SendCode={sendCode}]Request Image Download URL: {url}");
@ -249,12 +252,14 @@ namespace SparkClient.Model.Services
List<string> imageNames = new List<string>(); List<string> imageNames = new List<string>();
// 读取图片接口 // 读取图片接口
int imageIndex = 0; int imageIndex = 0;
int imageTotal = ConfigurationHelper.ReadConfigValueToInteger("DetectImageTotal", 100);
while (true) while (true)
{ {
string url = $"{_baseUrl}/retrieve_image/{imageIndex}"; string url = $"{_baseUrl}/retrieve_image/{imageIndex}";
string sendCode = url.GenerateSign();
try try
{ {
var response = await SendGetRequestImageAsync(url); var response = await SendGetRequestImageAsync(url,sendCode);
int status = (int)response.StatusCode; int status = (int)response.StatusCode;
if(token.IsCancellationRequested) if(token.IsCancellationRequested)
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
@ -285,10 +290,12 @@ namespace SparkClient.Model.Services
case 404: case 404:
// 资源未找到,结束循环 // 资源未找到,结束循环
return imageNames; Logger.Info($"[SendCode={sendCode}] Image Not Found]");
break;
//return imageNames;
default: default:
// 其他状态码,记录警告并继续 // 其他状态码,记录警告并继续
Logger.Warn($"Unexpected status code: {status} for URL: {url}"); Logger.Warn($"[SendCode={sendCode}]Unexpected status code: {status} for URL: {url}");
imageIndex++; imageIndex++;
break; break;
} }
@ -296,13 +303,13 @@ namespace SparkClient.Model.Services
catch (HttpRequestException ex) catch (HttpRequestException ex)
{ {
// 捕获HTTP请求异常并记录错误信息 // 捕获HTTP请求异常并记录错误信息
Logger.Error($"HTTP request failed for URL: {url}, Exception: {ex.Message}"); Logger.Error($"[SendCode={sendCode}]HTTP request failed for URL: {url}, Exception: {ex.Message}");
return imageNames; return imageNames;
} }
catch (Exception ex) catch (Exception ex)
{ {
// 捕获其他异常并记录错误信息,结束循环 // 捕获其他异常并记录错误信息,结束循环
Logger.Error($"An unexpected error occurred for URL: {url}, Exception: {ex.Message}"); Logger.Error($"[SendCode={sendCode}]An unexpected error occurred for URL: {url}, Exception: {ex.Message}");
return imageNames; return imageNames;
} }
} }

@ -569,7 +569,7 @@ public class DiamondSelectVM : BaseViewModel
/// ///
private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer)); private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer));
[Log] [Log]
public static void HandleAlgorithmFailure(string[] image_files, string dCode = "") public static void HandleAlgorithmFailure(string[] image_files, string dCode = "", string dType = "")
{ {
// 从配置文件中读取 imageHistoryPath // 从配置文件中读取 imageHistoryPath
@ -584,7 +584,7 @@ public class DiamondSelectVM : BaseViewModel
// 生成时间戳,格式为 yyyyMMddHHmmss // 生成时间戳,格式为 yyyyMMddHHmmss
string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmmss"); string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmmss");
// 组合新的文件夹路径 // 组合新的文件夹路径
string newFolderPath = Path.Combine(imageHistoryPath, string.IsNullOrWhiteSpace(dCode) ? $"image-{timestamp}" : $"image-{dCode}-{timestamp}" ); string newFolderPath = Path.Combine(imageHistoryPath, string.IsNullOrWhiteSpace(dCode) ? $"image-{timestamp}-{dType}" : $"image-{dCode}-{timestamp}-{dType}" );
// 检查 D 盘内存空间 // 检查 D 盘内存空间
string strSafeSpace = ConfigurationHelper.ReadConfigValue("SafeSpaceReservation"); string strSafeSpace = ConfigurationHelper.ReadConfigValue("SafeSpaceReservation");

@ -424,7 +424,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
string strSafeSpace = ConfigurationHelper.ReadConfigValue("SafeSpaceReservation"); string strSafeSpace = ConfigurationHelper.ReadConfigValue("SafeSpaceReservation");
if (hasErr || "0".Equals(strSafeSpace)) if (hasErr || "0".Equals(strSafeSpace))
{ {
DiamondSelectVM.HandleAlgorithmFailure(ImagePaths, _diamondCode); DiamondSelectVM.HandleAlgorithmFailure(ImagePaths, _diamondCode, _diamnondType);
} }
} }
} }
@ -554,8 +554,9 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
public void LoadDefaultImages() public void LoadDefaultImages()
{ {
List<string> imagePaths = new List<string>(); List<string> imagePaths = new List<string>();
string? savePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; string? savePath = ConfigurationHelper.ReadConfigValue("ImageFileBasePath");
for (int i = 0; i < 100; i++) int imageTotal = ConfigurationHelper.ReadConfigValueToInteger("DetectImageTotal", 100);
for (int i = 0; i < imageTotal; i++)
{ {
imagePaths.Add($"image_{i}.bmp"); imagePaths.Add($"image_{i}.bmp");
} }

Loading…
Cancel
Save