using OrpaonVision.Core.LayerRecognition;
using OrpaonVision.Core.PartRecognition;
using OrpaonVision.Core.PlacementJudgment;
using OrpaonVision.Core.QuantityValidation;
using OrpaonVision.Core.PositionValidation;
using OrpaonVision.Core.Results;
namespace OrpaonVision.Core.LayerCompletion;
///
/// 层完成判定服务接口。
///
public interface ILayerCompletionService
{
///
/// 判定层级完成状态。
///
/// 层级上下文。
/// 完成判定规则列表。
/// 取消令牌。
/// 层级完成判定结果。
Task> JudgeLayerCompletionAsync(LayerContext layerContext, IReadOnlyList completionRules, CancellationToken cancellationToken = default);
///
/// 判定必装部件完成状态。
///
/// 部件列表。
/// 必装部件列表。
/// 取消令牌。
/// 必装部件完成结果。
Task> JudgeRequiredPartsAsync(IReadOnlyList parts, IReadOnlyList requiredParts, CancellationToken cancellationToken = default);
///
/// 判定关键部件完成状态。
///
/// 部件列表。
/// 关键部件列表。
/// 取消令牌。
/// 关键部件完成结果。
Task> JudgeCriticalPartsAsync(IReadOnlyList parts, IReadOnlyList criticalParts, CancellationToken cancellationToken = default);
///
/// 判定稳定性完成状态。
///
/// 帧历史记录。
/// 稳定性要求。
/// 取消令牌。
/// 稳定性完成结果。
Task> JudgeStabilityAsync(IReadOnlyList frameHistory, StabilityRequirements stabilityRequirements, CancellationToken cancellationToken = default);
///
/// 判定禁装部件检查状态。
///
/// 部件列表。
/// 禁装部件列表。
/// 取消令牌。
/// 禁装部件检查结果。
Task> CheckForbiddenPartsAsync(IReadOnlyList parts, IReadOnlyList forbiddenParts, CancellationToken cancellationToken = default);
///
/// 批量层级完成判定。
///
/// 层级上下文列表。
/// 完成判定规则列表。
/// 取消令牌。
/// 批量完成判定结果。
Task> BatchJudgeLayerCompletionAsync(IReadOnlyList layerContexts, IReadOnlyList completionRules, CancellationToken cancellationToken = default);
///
/// 获取层级完成统计信息。
///
/// 开始时间。
/// 结束时间。
/// 取消令牌。
/// 统计信息。
Task> GetCompletionStatisticsAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default);
///
/// 创建层级完成规则。
///
/// 完成规则。
/// 取消令牌。
/// 创建结果。
Task> CreateCompletionRuleAsync(LayerCompletionRule rule, CancellationToken cancellationToken = default);
///
/// 更新层级完成规则。
///
/// 完成规则。
/// 取消令牌。
/// 更新结果。
Task UpdateCompletionRuleAsync(LayerCompletionRule rule, CancellationToken cancellationToken = default);
///
/// 删除层级完成规则。
///
/// 规则ID。
/// 取消令牌。
/// 删除结果。
Task DeleteCompletionRuleAsync(Guid ruleId, CancellationToken cancellationToken = default);
///
/// 获取层级完成规则列表。
///
/// 产品类型编码(可选)。
/// 层级编号(可选)。
/// 完成类型(可选)。
/// 取消令牌。
/// 规则列表。
Task>> GetCompletionRulesAsync(string? productTypeCode = null, int? layerNumber = null, LayerCompletionType? completionType = null, CancellationToken cancellationToken = default);
}
///
/// 层级上下文。
///
public sealed class LayerContext
{
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 层级编号。
///
public int LayerNumber { get; init; }
///
/// 层级名称。
///
public string LayerName { get; init; } = string.Empty;
///
/// 当前检测到的部件。
///
public IReadOnlyList DetectedParts { get; init; } = Array.Empty();
///
/// 帧历史记录。
///
public IReadOnlyList FrameHistory { get; init; } = Array.Empty();
///
/// 数量校验结果。
///
public BatchQuantityValidationResult? QuantityValidationResult { get; init; }
///
/// 位置校验结果。
///
public BatchPositionValidationResult? PositionValidationResult { get; init; }
///
/// 到位判定结果。
///
public BatchJudgmentResult? PlacementJudgmentResult { get; init; }
///
/// 层级开始时间。
///
public DateTime LayerStartTimeUtc { get; init; }
///
/// 层级当前时间。
///
public DateTime LayerCurrentTimeUtc { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 层级完成判定结果。
///
public sealed class LayerCompletionResult
{
///
/// 是否完成。
///
public bool IsCompleted { get; init; }
///
/// 完成度百分比。
///
public double CompletionPercentage { get; init; }
///
/// 总体置信度。
///
public double OverallConfidence { get; init; }
///
/// 判定时间。
///
public DateTime JudgmentTimeUtc { get; init; }
///
/// 必装部件完成结果。
///
public RequiredPartsCompletionResult? RequiredPartsResult { get; init; }
///
/// 关键部件完成结果。
///
public CriticalPartsCompletionResult? CriticalPartsResult { get; init; }
///
/// 稳定性完成结果。
///
public StabilityCompletionResult? StabilityResult { get; init; }
///
/// 禁装部件检查结果。
///
public ForbiddenPartsCheckResult? ForbiddenPartsResult { get; init; }
///
/// 未满足的硬条件列表。
///
public IReadOnlyList UnmetHardConditions { get; init; } = Array.Empty();
///
/// 完成质量。
///
public CompletionQuality CompletionQuality { get; init; }
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 必装部件完成结果。
///
public sealed class RequiredPartsCompletionResult
{
///
/// 是否满足必装要求。
///
public bool IsRequiredSatisfied { get; init; }
///
/// 必装部件总数。
///
public int TotalRequiredParts { get; init; }
///
/// 已安装必装部件数量。
///
public int InstalledRequiredParts { get; init; }
///
/// 缺失必装部件列表。
///
public IReadOnlyList MissingRequiredParts { get; init; } = Array.Empty();
///
/// 必装完成率。
///
public double RequiredCompletionRate => TotalRequiredParts > 0 ? (double)InstalledRequiredParts / TotalRequiredParts * 100 : 0.0;
///
/// 判定时间。
///
public DateTime JudgmentTimeUtc { get; init; }
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 关键部件完成结果。
///
public sealed class CriticalPartsCompletionResult
{
///
/// 是否满足关键件要求。
///
public bool IsCriticalSatisfied { get; init; }
///
/// 关键部件总数。
///
public int TotalCriticalParts { get; init; }
///
/// 已安装关键部件数量。
///
public int InstalledCriticalParts { get; init; }
///
/// 缺失关键部件列表。
///
public IReadOnlyList MissingCriticalParts { get; init; } = Array.Empty();
///
/// 关键件完成率。
///
public double CriticalCompletionRate => TotalCriticalParts > 0 ? (double)InstalledCriticalParts / TotalCriticalParts * 100 : 0.0;
///
/// 判定时间。
///
public DateTime JudgmentTimeUtc { get; init; }
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 稳定性完成结果。
///
public sealed class StabilityCompletionResult
{
///
/// 是否满足稳定性要求。
///
public bool IsStabilitySatisfied { get; init; }
///
/// 总体稳定性分数。
///
public double OverallStabilityScore { get; init; }
///
/// 稳定性阈值。
///
public double StabilityThreshold { get; init; }
///
/// 稳定帧数量。
///
public int StableFrameCount { get; init; }
///
/// 总帧数量。
///
public int TotalFrameCount { get; init; }
///
/// 稳定性通过率。
///
public double StabilityPassRate => TotalFrameCount > 0 ? (double)StableFrameCount / TotalFrameCount * 100 : 0.0;
///
/// 判定时间。
///
public DateTime JudgmentTimeUtc { get; init; }
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 禁装部件检查结果。
///
public sealed class ForbiddenPartsCheckResult
{
///
/// 是否通过禁装检查(无禁装部件)。
///
public bool IsForbiddenCheckPassed { get; init; }
///
/// 检测到的禁装部件列表。
///
public IReadOnlyList DetectedForbiddenParts { get; init; } = Array.Empty();
///
/// 禁装部件总数。
///
public int TotalForbiddenParts { get; init; }
///
/// 违规严重程度。
///
public ViolationSeverity ViolationSeverity { get; init; }
///
/// 判定时间。
///
public DateTime JudgmentTimeUtc { get; init; }
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 批量层级完成判定结果。
///
public sealed class BatchLayerCompletionResult
{
///
/// 层级完成判定结果列表。
///
public IReadOnlyList CompletionResults { get; init; } = Array.Empty();
///
/// 总层级数量。
///
public int TotalLayers { get; init; }
///
/// 完成的层级数量。
///
public int CompletedLayers { get; init; }
///
/// 失败的层级数量。
///
public int FailedLayers { get; init; }
///
/// 总体完成率。
///
public double OverallCompletionRate => TotalLayers > 0 ? (double)CompletedLayers / TotalLayers * 100 : 0.0;
///
/// 批量处理时间。
///
public DateTime BatchProcessingTimeUtc { get; init; }
///
/// 总耗时(毫秒)。
///
public long TotalElapsedMs { get; init; }
///
/// 判定详情。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 层级完成统计信息。
///
public sealed class LayerCompletionStatistics
{
///
/// 总完成判定次数。
///
public int TotalCompletions { get; init; }
///
/// 成功完成次数。
///
public int SuccessfulCompletions { get; init; }
///
/// 失败完成次数。
///
public int FailedCompletions { get; init; }
///
/// 总体完成率。
///
public double OverallCompletionRate => TotalCompletions > 0 ? (double)SuccessfulCompletions / TotalCompletions * 100 : 0.0;
///
/// 按完成类型分组的统计。
///
public Dictionary ByCompletionType { get; init; } = new();
///
/// 按产品类型分组的统计。
///
public Dictionary ByProductType { get; init; } = new();
///
/// 按层级分组的统计。
///
public Dictionary ByLayer { get; init; } = new();
///
/// 统计开始时间。
///
public DateTime StartTimeUtc { get; init; }
///
/// 统计结束时间。
///
public DateTime EndTimeUtc { get; init; }
}
///
/// 完成类型统计。
///
public sealed class CompletionTypeStatistics
{
///
/// 完成类型。
///
public LayerCompletionType CompletionType { get; init; }
///
/// 判定次数。
///
public int JudgmentCount { get; init; }
///
/// 成功次数。
///
public int SuccessCount { get; init; }
///
/// 成功率。
///
public double SuccessRate => JudgmentCount > 0 ? (double)SuccessCount / JudgmentCount * 100 : 0.0;
///
/// 平均耗时(毫秒)。
///
public double AverageElapsedMs { get; init; }
}
///
/// 产品类型完成统计。
///
public sealed class ProductTypeCompletionStatistics
{
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 判定次数。
///
public int JudgmentCount { get; init; }
///
/// 成功次数。
///
public int SuccessCount { get; init; }
///
/// 成功率。
///
public double SuccessRate => JudgmentCount > 0 ? (double)SuccessCount / JudgmentCount * 100 : 0.0;
///
/// 平均完成度。
///
public double AverageCompletionPercentage { get; init; }
}
///
/// 按层级分组的完成统计。
///
public sealed class LayerCompletionStatisticsByLayer
{
///
/// 层级编号。
///
public int LayerNumber { get; init; }
///
/// 判定次数。
///
public int JudgmentCount { get; init; }
///
/// 成功次数。
///
public int SuccessCount { get; init; }
///
/// 成功率。
///
public double SuccessRate => JudgmentCount > 0 ? (double)SuccessCount / JudgmentCount * 100 : 0.0;
///
/// 平均完成度。
///
public double AverageCompletionPercentage { get; init; }
}
///
/// 层级完成规则。
///
public sealed class LayerCompletionRule
{
///
/// 规则ID。
///
public Guid RuleId { get; init; }
///
/// 规则名称。
///
public string RuleName { get; init; } = string.Empty;
///
/// 规则描述。
///
public string RuleDescription { get; init; } = string.Empty;
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 层级编号。
///
public int LayerNumber { get; init; }
///
/// 完成类型。
///
public LayerCompletionType CompletionType { get; init; }
///
/// 硬条件列表。
///
public IReadOnlyList HardConditions { get; init; } = Array.Empty();
///
/// 是否启用。
///
public bool IsEnabled { get; init; } = true;
///
/// 优先级。
///
public int Priority { get; init; } = 1;
///
/// 创建时间。
///
public DateTime CreatedAtUtc { get; init; }
///
/// 更新时间。
///
public DateTime UpdatedAtUtc { get; init; }
///
/// 版本号。
///
public string Version { get; init; } = "1.0";
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 硬条件。
///
public sealed class HardCondition
{
///
/// 条件ID。
///
public Guid ConditionId { get; init; }
///
/// 条件名称。
///
public string ConditionName { get; init; } = string.Empty;
///
/// 条件类型。
///
public HardConditionType ConditionType { get; init; }
///
/// 是否为必须满足的硬条件。
///
public bool IsMandatory { get; init; } = true;
///
/// 条件权重。
///
public double Weight { get; init; } = 1.0;
///
/// 条件阈值。
///
public double Threshold { get; init; }
///
/// 条件描述。
///
public string? Description { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 必装部件。
///
public sealed class RequiredPart
{
///
/// 部件ID。
///
public Guid PartId { get; init; }
///
/// 部件编码。
///
public string PartCode { get; init; } = string.Empty;
///
/// 部件类型。
///
public PartType PartType { get; init; }
///
/// 部件名称。
///
public string PartName { get; init; } = string.Empty;
///
/// 必装数量。
///
public int RequiredQuantity { get; init; } = 1;
///
/// 部件权重。
///
public double Weight { get; init; } = 1.0;
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 关键部件。
///
public sealed class CriticalPart
{
///
/// 部件ID。
///
public Guid PartId { get; init; }
///
/// 部件编码。
///
public string PartCode { get; init; } = string.Empty;
///
/// 部件类型。
///
public PartType PartType { get; init; }
///
/// 部件名称。
///
public string PartName { get; init; } = string.Empty;
///
/// 关键程度。
///
public CriticalityLevel CriticalityLevel { get; init; }
///
/// 必装数量。
///
public int RequiredQuantity { get; init; } = 1;
///
/// 部件权重。
///
public double Weight { get; init; } = 1.0;
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 禁装部件。
///
public sealed class ForbiddenPart
{
///
/// 部件ID。
///
public Guid PartId { get; init; }
///
/// 部件编码。
///
public string PartCode { get; init; } = string.Empty;
///
/// 部件类型。
///
public PartType PartType { get; init; }
///
/// 部件名称。
///
public string PartName { get; init; } = string.Empty;
///
/// 违规严重程度。
///
public ViolationSeverity ViolationSeverity { get; init; }
///
/// 禁装原因。
///
public string? ForbiddenReason { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 禁装部件违规。
///
public sealed class ForbiddenPartViolation
{
///
/// 违规部件信息。
///
public MappedPart ViolatingPart { get; init; } = new();
///
/// 禁装部件定义。
///
public ForbiddenPart ForbiddenPart { get; init; } = new();
///
/// 违规严重程度。
///
public ViolationSeverity ViolationSeverity { get; init; }
///
/// 违规时间。
///
public DateTime ViolationTimeUtc { get; init; }
///
/// 违规描述。
///
public string? ViolationDescription { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 稳定性要求。
///
public sealed class StabilityRequirements
{
///
/// 稳定性阈值。
///
public double StabilityThreshold { get; init; } = 0.8;
///
/// 最小稳定帧数。
///
public int MinimumStableFrames { get; init; } = 10;
///
/// 位置变化阈值。
///
public double PositionChangeThreshold { get; init; } = 5.0;
///
/// 面积变化阈值。
///
public double AreaChangeThreshold { get; init; } = 0.1;
///
/// 置信度变化阈值。
///
public double ConfidenceChangeThreshold { get; init; } = 0.1;
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 层级完成类型枚举。
///
public enum LayerCompletionType
{
///
/// 必装部件完成。
///
RequiredParts = 0,
///
/// 关键部件完成。
///
CriticalParts = 1,
///
/// 稳定性完成。
///
Stability = 2,
///
/// 禁装检查。
///
ForbiddenCheck = 3,
///
/// 综合完成。
///
Comprehensive = 4
}
///
/// 硬条件类型枚举。
///
public enum HardConditionType
{
///
/// 必装部件条件。
///
RequiredParts = 0,
///
/// 关键部件条件。
///
CriticalParts = 1,
///
/// 稳定性条件。
///
Stability = 2,
///
/// 禁装检查条件。
///
ForbiddenCheck = 3
}
///
/// 完成质量枚举。
///
public enum CompletionQuality
{
///
/// 优秀。
///
Excellent = 0,
///
/// 良好。
///
Good = 1,
///
/// 一般。
///
Fair = 2,
///
/// 较差。
///
Poor = 3
}
///
/// 关键程度枚举。
///
public enum CriticalityLevel
{
///
/// 一般关键。
///
Normal = 0,
///
/// 重要关键。
///
Important = 1,
///
/// 严重关键。
///
Critical = 2
}
///
/// 违规严重程度枚举。
///
public enum ViolationSeverity
{
///
/// 轻微违规。
///
Minor = 0,
///
/// 一般违规。
///
Normal = 1,
///
/// 严重违规。
///
Serious = 2,
///
/// 致命违规。
///
Fatal = 3
}