39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
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: "规则判定完成。");
|
||
}
|
||
}
|
||
}
|