using Common.Distance; namespace Ocr.Report.Models; public readonly struct ProcessorStat : IDistanceComparer> { /// /// The name of the processor /// public string Name { get; } /// /// The total milliseconds it took the processor to process the data /// public double ProcessingTime { get; } /// public IEnumerable Reference { get; } /// public IEnumerable? Hypothesis { get; } /// public double Distance { get; } /// /// Information about the processed values /// public ICollection> Words { get; } public ProcessorStat( string name, double processingTime, ICollection reference, ICollection hypothesis ) { Name = name; ProcessingTime = processingTime; Reference = reference; Hypothesis = hypothesis; Distance = Calculator.GetDistance( reference.OrderBy(s => s).ToArray(), hypothesis.OrderBy(s => s).ToArray() ) / reference.Count; Words = GetDistanceInfos(reference, hypothesis).ToArray(); } /// /// Compares the with all given values in the /// , determining the /// with the lowest error /// private static IEnumerable> GetDistanceInfos( ICollection referenceCollection, ICollection hypothesisCollection ) { var results = new List>(); foreach (var reference in referenceCollection) { var tResults = hypothesisCollection .Select(hypothesis => (IDistanceComparer)new DistanceComparer(reference, hypothesis)) .ToList(); results.AddRange(tResults); } var lookup = results .OrderBy(result => result.Distance) .ToLookup(result => result.Reference); foreach (var reference in referenceCollection) { yield return lookup[reference].FirstOrDefault() ?? new DistanceComparer(reference); } } }