using OrpaonVision.Core.LayerRecognition;
using OrpaonVision.Core.Results;
namespace OrpaonVision.Core.PartRecognition;
///
/// 部件识别服务接口。
///
public interface IPartRecognitionService
{
///
/// 映射推理结果到部件。
///
/// 推理结果。
/// 当前层级。
/// 取消令牌。
/// 部件映射结果。
Task> MapInferenceToPartsAsync(InferenceResultDto inference, int currentLayer, CancellationToken cancellationToken = default);
///
/// 校验部件识别精度。
///
/// 映射的部件列表。
/// 期望的部件列表。
/// 取消令牌。
/// 精度校验结果。
Task> ValidatePartAccuracyAsync(IReadOnlyList mappedParts, IReadOnlyList expectedParts, CancellationToken cancellationToken = default);
///
/// 获取部件类别映射配置。
///
/// 产品类型编码。
/// 层级编号。
/// 取消令牌。
/// 类别映射配置。
Task> GetPartClassMappingConfigAsync(string productTypeCode, int layerNumber, CancellationToken cancellationToken = default);
///
/// 更新部件类别映射配置。
///
/// 映射配置。
/// 取消令牌。
/// 更新结果。
Task UpdatePartClassMappingConfigAsync(PartClassMappingConfig config, CancellationToken cancellationToken = default);
///
/// 训练部件识别模型。
///
/// 训练数据。
/// 取消令牌。
/// 训练结果。
Task> TrainPartRecognitionModelAsync(IReadOnlyList trainingData, CancellationToken cancellationToken = default);
///
/// 优化部件识别参数。
///
/// 优化数据。
/// 取消令牌。
/// 优化结果。
Task> OptimizePartRecognitionAsync(IReadOnlyList optimizationData, CancellationToken cancellationToken = default);
///
/// 获取部件识别统计信息。
///
/// 开始时间。
/// 结束时间。
/// 取消令牌。
/// 统计信息。
Task> GetRecognitionStatisticsAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default);
///
/// 批量映射推理结果。
///
/// 推理结果列表。
/// 当前层级。
/// 取消令牌。
/// 批量映射结果。
Task> BatchMapInferenceToPartsAsync(IReadOnlyList inferences, int currentLayer, CancellationToken cancellationToken = default);
}
///
/// 部件映射结果。
///
public sealed class PartMappingResult
{
///
/// 映射的部件列表。
///
public IReadOnlyList MappedParts { get; init; } = Array.Empty();
///
/// 映射置信度。
///
public double MappingConfidence { get; init; }
///
/// 映射方法。
///
public PartMappingMethod MappingMethod { get; init; }
///
/// 映射时间。
///
public DateTime MappingTimeUtc { get; init; }
///
/// 详细信息。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 映射的部件。
///
public sealed class MappedPart
{
///
/// 部件ID。
///
public Guid PartId { get; init; }
///
/// 部件编码。
///
public string PartCode { get; init; } = string.Empty;
///
/// 部件名称。
///
public string PartName { get; init; } = string.Empty;
///
/// 部件类型。
///
public PartType PartType { get; init; }
///
/// 原始检测类别。
///
public string OriginalClass { get; init; } = string.Empty;
///
/// 映射置信度。
///
public double MappingConfidence { get; init; }
///
/// 检测置信度。
///
public double DetectionConfidence { get; init; }
///
/// 综合置信度。
///
public double OverallConfidence { get; init; }
///
/// 边界框。
///
public BoundingBox BoundingBox { get; init; } = new();
///
/// 部件属性。
///
public Dictionary PartAttributes { get; init; } = new();
///
/// 是否为有效部件。
///
public bool IsValid { get; init; }
///
/// 验证错误。
///
public List ValidationErrors { get; init; } = new();
///
/// 映射时间。
///
public DateTime MappingTimeUtc { get; init; }
}
///
/// 部件精度校验结果。
///
public sealed class PartAccuracyValidationResult
{
///
/// 总体精度。
///
public double OverallAccuracy { get; init; }
///
/// 精确率。
///
public double Precision { get; init; }
///
/// 召回率。
///
public double Recall { get; init; }
///
/// F1分数。
///
public double F1Score { get; init; }
///
/// 漏检部件列表。
///
public IReadOnlyList MissedParts { get; init; } = Array.Empty();
///
/// 误检部件列表。
///
public IReadOnlyList FalsePositiveParts { get; init; } = Array.Empty();
///
/// 正确识别的部件列表。
///
public IReadOnlyList CorrectMatches { get; init; } = Array.Empty();
///
/// 按部件类型的精度统计。
///
public Dictionary TypeAccuracy { get; init; } = new();
///
/// 校验时间。
///
public DateTime ValidationTimeUtc { get; init; }
///
/// 详细信息。
///
public string? Details { get; init; }
}
///
/// 部件匹配结果。
///
public sealed class PartMatch
{
///
/// 期望部件。
///
public ExpectedPart ExpectedPart { get; init; } = new();
///
/// 映射部件。
///
public MappedPart MappedPart { get; init; } = new();
///
/// 匹配置信度。
///
public double MatchConfidence { get; init; }
///
/// 位置偏差。
///
public double PositionDeviation { get; init; }
///
/// 大小偏差。
///
public double SizeDeviation { get; init; }
///
/// 匹配质量。
///
public MatchQuality MatchQuality { get; init; }
}
///
/// 部件类型精度。
///
public sealed class PartTypeAccuracy
{
///
/// 部件类型。
///
public PartType PartType { get; init; }
///
/// 总数。
///
public int TotalCount { get; init; }
///
/// 正确识别数。
///
public int CorrectCount { get; init; }
///
/// 精度。
///
public double Accuracy { get; init; }
///
/// 精确率。
///
public double Precision { get; init; }
///
/// 召回率。
///
public double Recall { get; init; }
}
///
/// 部件类别映射配置。
///
public sealed class PartClassMappingConfig
{
///
/// 配置ID。
///
public Guid ConfigId { get; init; }
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 层级编号。
///
public int LayerNumber { get; init; }
///
/// 类别映射规则。
///
public IReadOnlyList MappingRules { get; init; } = Array.Empty();
///
/// 默认映射规则。
///
public ClassMappingRule? DefaultRule { get; init; }
///
/// 置信度阈值。
///
public double ConfidenceThreshold { get; init; } = 0.5;
///
/// 是否启用模糊匹配。
///
public bool EnableFuzzyMatching { get; init; } = true;
///
/// 模糊匹配阈值。
///
public double FuzzyMatchingThreshold { get; init; } = 0.8;
///
/// 创建时间。
///
public DateTime CreatedAtUtc { get; init; }
///
/// 更新时间。
///
public DateTime UpdatedAtUtc { get; init; }
///
/// 版本号。
///
public string Version { get; init; } = "1.0";
///
/// 是否启用。
///
public bool IsEnabled { get; init; } = true;
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 类别映射规则。
///
public sealed class ClassMappingRule
{
///
/// 规则ID。
///
public Guid RuleId { get; init; }
///
/// 原始类别。
///
public string OriginalClass { get; init; } = string.Empty;
///
/// 目标部件编码。
///
public string TargetPartCode { get; init; } = string.Empty;
///
/// 目标部件名称。
///
public string TargetPartName { get; init; } = string.Empty;
///
/// 目标部件类型。
///
public PartType TargetPartType { get; init; }
///
/// 映射权重。
///
public double MappingWeight { get; init; } = 1.0;
///
/// 最小置信度要求。
///
public double MinConfidence { get; init; } = 0.5;
///
/// 条件表达式。
///
public string? ConditionExpression { get; init; }
///
/// 部件属性映射。
///
public Dictionary AttributeMapping { get; init; } = new();
///
/// 优先级。
///
public int Priority { get; init; } = 1;
///
/// 是否启用。
///
public bool IsEnabled { get; init; } = true;
}
///
/// 期望部件。
///
public sealed class ExpectedPart
{
///
/// 部件编码。
///
public string PartCode { get; init; } = string.Empty;
///
/// 部件名称。
///
public string PartName { get; init; } = string.Empty;
///
/// 部件类型。
///
public PartType PartType { get; init; }
///
/// 期望位置。
///
public BoundingBox ExpectedBoundingBox { get; init; } = new();
///
/// 位置容差。
///
public double PositionTolerance { get; init; } = 10.0;
///
/// 大小容差。
///
public double SizeTolerance { get; init; } = 0.1;
///
/// 是否为必需部件。
///
public bool IsRequired { get; init; } = true;
///
/// 最小数量。
///
public int MinCount { get; init; } = 1;
///
/// 最大数量。
///
public int MaxCount { get; init; } = 1;
///
/// 部件属性。
///
public Dictionary PartAttributes { get; init; } = new();
}
///
/// 部件训练数据。
///
public sealed class PartTrainingData
{
///
/// 数据ID。
///
public Guid DataId { get; init; }
///
/// 推理结果。
///
public InferenceResultDto Inference { get; init; } = new();
///
/// 正确的部件映射。
///
public IReadOnlyList CorrectMappings { get; init; } = Array.Empty();
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 层级编号。
///
public int LayerNumber { get; init; }
///
/// 数据标签。
///
public string Label { get; init; } = string.Empty;
///
/// 创建时间。
///
public DateTime CreatedAtUtc { get; init; }
///
/// 是否为验证数据。
///
public bool IsValidationData { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 部件模型训练结果。
///
public sealed class PartModelTrainingResult
{
///
/// 训练ID。
///
public Guid TrainingId { get; init; }
///
/// 模型准确率。
///
public double Accuracy { get; init; }
///
/// 模型精确率。
///
public double Precision { get; init; }
///
/// 模型召回率。
///
public double Recall { get; init; }
///
/// F1分数。
///
public double F1Score { get; init; }
///
/// 训练样本数量。
///
public int TrainingSampleCount { get; init; }
///
/// 验证样本数量。
///
public int ValidationSampleCount { get; init; }
///
/// 训练耗时(毫秒)。
///
public long TrainingElapsedMs { get; init; }
///
/// 模型版本。
///
public string ModelVersion { get; init; } = string.Empty;
///
/// 训练时间。
///
public DateTime TrainingTimeUtc { get; init; }
///
/// 详细信息。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 部件优化数据。
///
public sealed class PartOptimizationData
{
///
/// 数据ID。
///
public Guid DataId { get; init; }
///
/// 推理结果。
///
public InferenceResultDto Inference { get; init; } = new();
///
/// 当前映射结果。
///
public PartMappingResult CurrentMapping { get; init; } = new();
///
/// 期望映射结果。
///
public IReadOnlyList ExpectedMapping { get; init; } = Array.Empty();
///
/// 优化目标。
///
public OptimizationGoal OptimizationGoal { get; init; }
///
/// 创建时间。
///
public DateTime CreatedAtUtc { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 部件优化结果。
///
public sealed class PartOptimizationResult
{
///
/// 优化ID。
///
public Guid OptimizationId { get; init; }
///
/// 优化前的精度。
///
public double BeforeAccuracy { get; init; }
///
/// 优化后的精度。
///
public double AfterAccuracy { get; init; }
///
/// 精度提升。
///
public double AccuracyImprovement { get; init; }
///
/// 优化参数。
///
public Dictionary OptimizedParameters { get; init; } = new();
///
/// 优化耗时(毫秒)。
///
public long OptimizationElapsedMs { get; init; }
///
/// 优化时间。
///
public DateTime OptimizationTimeUtc { get; init; }
///
/// 详细信息。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 批量部件映射结果。
///
public sealed class BatchPartMappingResult
{
///
/// 映射结果列表。
///
public IReadOnlyList MappingResults { get; init; } = Array.Empty();
///
/// 总数量。
///
public int TotalCount { get; init; }
///
/// 成功数量。
///
public int SuccessCount { get; init; }
///
/// 失败数量。
///
public int FailureCount { get; init; }
///
/// 平均映射置信度。
///
public double AverageMappingConfidence { get; init; }
///
/// 总耗时(毫秒)。
///
public long TotalElapsedMs { get; init; }
///
/// 批量处理时间。
///
public DateTime BatchProcessingTimeUtc { get; init; }
///
/// 详细信息。
///
public string? Details { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 部件识别统计信息。
///
public sealed class PartRecognitionStatistics
{
///
/// 总识别次数。
///
public int TotalRecognitions { get; init; }
///
/// 成功识别次数。
///
public int SuccessfulRecognitions { get; init; }
///
/// 失败识别次数。
///
public int FailedRecognitions { get; init; }
///
/// 识别准确率。
///
public double Accuracy { get; init; }
///
/// 平均映射置信度。
///
public double AverageMappingConfidence { get; init; }
///
/// 总部件数量。
///
public int TotalParts { get; init; }
///
/// 正确识别的部件数量。
///
public int CorrectParts { get; init; }
///
/// 按部件类型的统计。
///
public Dictionary ByPartType { get; init; } = new();
///
/// 按产品类型的统计。
///
public Dictionary ByProductType { get; init; } = new();
///
/// 按层级的统计。
///
public Dictionary ByLayer { get; init; } = new();
///
/// 按映射方法的统计。
///
public Dictionary ByMappingMethod { get; init; } = new();
///
/// 统计开始时间。
///
public DateTime StartTimeUtc { get; init; }
///
/// 统计结束时间。
///
public DateTime EndTimeUtc { get; init; }
}
///
/// 部件统计。
///
public sealed class PartStatistics
{
///
/// 部件类型。
///
public PartType PartType { get; init; }
///
/// 识别次数。
///
public int RecognitionCount { get; init; }
///
/// 成功次数。
///
public int SuccessCount { get; init; }
///
/// 准确率。
///
public double Accuracy { get; init; }
///
/// 平均置信度。
///
public double AverageConfidence { get; init; }
}
///
/// 产品类型统计。
///
public sealed class ProductTypeStatistics
{
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 识别次数。
///
public int RecognitionCount { get; init; }
///
/// 成功次数。
///
public int SuccessCount { get; init; }
///
/// 准确率。
///
public double Accuracy { get; init; }
///
/// 平均部件数量。
///
public double AveragePartCount { get; init; }
}
///
/// 层级统计。
///
public sealed class LayerStatistics
{
///
/// 层级编号。
///
public int LayerNumber { get; init; }
///
/// 识别次数。
///
public int RecognitionCount { get; init; }
///
/// 成功次数。
///
public int SuccessCount { get; init; }
///
/// 准确率。
///
public double Accuracy { get; init; }
///
/// 平均部件数量。
///
public double AveragePartCount { get; init; }
}
///
/// 方法统计。
///
public sealed class MethodStatistics
{
///
/// 映射方法。
///
public PartMappingMethod MappingMethod { get; init; }
///
/// 使用次数。
///
public int UsageCount { get; init; }
///
/// 成功次数。
///
public int SuccessCount { get; init; }
///
/// 准确率。
///
public double Accuracy { get; init; }
///
/// 平均耗时(毫秒)。
///
public double AverageElapsedMs { get; init; }
}
///
/// 部件类型枚举。
///
public enum PartType
{
///
/// 未知。
///
Unknown = 0,
///
/// 必装件。
///
Required = 1,
///
/// 选装件。
///
Optional = 2,
///
/// 关键件。
///
Critical = 3,
///
/// 标准件。
///
Standard = 4,
///
/// 定制件。
///
Custom = 5,
///
/// 禁装件。
///
Forbidden = 6
}
///
/// 部件映射方法。
///
public enum PartMappingMethod
{
///
/// 基于规则。
///
RuleBased = 0,
///
/// 基于机器学习。
///
MachineLearning = 1,
///
/// 基于深度学习。
///
DeepLearning = 2,
///
/// 基于模板匹配。
///
TemplateMatching = 3,
///
/// 混合方法。
///
Hybrid = 4
}
///
/// 匹配质量。
///
public enum MatchQuality
{
///
/// 优秀。
///
Excellent = 0,
///
/// 良好。
///
Good = 1,
///
/// 一般。
///
Fair = 2,
///
/// 较差。
///
Poor = 3
}
///
/// 优化目标。
///
public enum OptimizationGoal
{
///
/// 提高准确率。
///
Accuracy = 0,
///
/// 提高精确率。
///
Precision = 1,
///
/// 提高召回率。
///
Recall = 2,
///
/// 平衡精度和召回率。
///
Balance = 3,
///
/// 提高速度。
///
Speed = 4
}