Files
OrpaonVision/OrpaonVision.SiteApp/Runtime/Services/SimpleRuleEngineService.cs
2026-04-06 22:04:05 +08:00

39 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using OrpaonVision.Core.Results;
using OrpaonVision.SiteApp.Runtime.Contracts;
using OrpaonVision.SiteApp.Runtime.Options;
namespace OrpaonVision.SiteApp.Runtime.Services
{
/// <summary>
/// 规则引擎简化实现MVP 阶段)。
/// </summary>
public sealed class SimpleRuleEngineService : IRuleEngineService
{
private readonly RuntimeOptions _options;
/// <summary>
/// 构造函数。
/// </summary>
public SimpleRuleEngineService(RuntimeOptions options)
{
_options = options;
}
/// <inheritdoc />
public Result<RuntimeDecisionDto> Evaluate(int currentLayer, InferenceResultDto inference)
{
var isPass = inference.Label == "OK" || inference.Confidence < _options.NgConfidenceThreshold;
var decision = new RuntimeDecisionDto
{
IsPass = isPass,
Code = isPass ? "RULE_PASS" : "RULE_NG",
Message = isPass
? $"第 {currentLayer} 层判定通过。"
: $"第 {currentLayer} 层判定 NG{inference.Label}"
};
return Result<RuntimeDecisionDto>.Success(decision, message: "规则判定完成。");
}
}
}