From e58fbc2d0636da9a97fabd17f3a0ece4d9462ba9 Mon Sep 17 00:00:00 2001 From: Simon Gruber Date: Mon, 20 Nov 2023 14:50:23 +0100 Subject: [PATCH] checkpoint alternate table layout --- Examples/ReportGenerator/Models/ImageStats.cs | 26 ++++++------------- .../ReportGenerator/Models/ProcessorStat.cs | 19 +++++++++----- Examples/ReportGenerator/Program.cs | 2 +- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Examples/ReportGenerator/Models/ImageStats.cs b/Examples/ReportGenerator/Models/ImageStats.cs index 2195731..709c6c4 100644 --- a/Examples/ReportGenerator/Models/ImageStats.cs +++ b/Examples/ReportGenerator/Models/ImageStats.cs @@ -24,29 +24,19 @@ internal readonly struct ImageStats public IEnumerable> ToTable() { // Title - yield return Stats.Select(s => s.ProcessorName).Prepend("Reference"); + yield return Reference + .Prepend("Processor") + .Append("WER") + .Append("CER (avg)") + .Append("CER (sum)"); // Spacer - yield return Stats.Select(s => "---").Prepend("---"); + yield return Enumerable.Range(0, Reference.Count + 4).Select(_ => "---"); // Content - foreach (var reference in Reference) + foreach (var stat in Stats) { - yield return Stats.SelectMany(s => s.ToRow(reference)).Prepend(reference); + yield return stat.ToRow(); } - - // Spacer - yield return Stats.Select(s => "---").Prepend("---"); - - // Summaries - yield return Stats - .Select(s => s.CharacterStats.Average(s => s.CharacterError).ToString("F2")) - .Prepend("CER (avg)"); - yield return Stats - .Select(s => s.CharacterStats.Sum(s => s.CharacterError).ToString("F2")) - .Prepend("CER (sum)"); - yield return Stats - .Select(s => s.WordError.ToString("F2")) - .Prepend("WER"); } } diff --git a/Examples/ReportGenerator/Models/ProcessorStat.cs b/Examples/ReportGenerator/Models/ProcessorStat.cs index be81390..c3807f4 100644 --- a/Examples/ReportGenerator/Models/ProcessorStat.cs +++ b/Examples/ReportGenerator/Models/ProcessorStat.cs @@ -25,9 +25,12 @@ internal readonly struct ProcessorStat ).ToArray(); } - public IEnumerable ToRow(string word) => CharacterStats - .Where(s => string.Equals(s.Reference, word)) - .Select(s => s.ToString()); + public IEnumerable ToRow() => CharacterStats + .Select(s => s.ToString()) + .Append(WordError.ToString("F2")) + .Append(CharacterStats.Average(s => s.CharacterError).ToString("F2")) + .Append(CharacterStats.Sum(s => s.CharacterError).ToString("F2")) + .Prepend(ProcessorName); /// /// Finds the smallest possible CER by calculating the levenshtein @@ -65,12 +68,14 @@ internal readonly struct ProcessorStat static double CalculateWer(ICollection expected, ICollection actual) { + if (!actual.Any()) + { + return double.PositiveInfinity; + } + // Amount of words that need to be substituted to match the original int substitutions = expected - .Zip( - actual, - (e, a) => string.Equals(e, a) ? 0 : 1 - ) + .Zip(actual, (e, a) => string.Equals(e, a) ? 0 : 1) .Sum(); // todo this isn't correct i think diff --git a/Examples/ReportGenerator/Program.cs b/Examples/ReportGenerator/Program.cs index 1c9782b..4cdcafb 100644 --- a/Examples/ReportGenerator/Program.cs +++ b/Examples/ReportGenerator/Program.cs @@ -42,7 +42,7 @@ internal static class Program var scanFileLookup = scanFileInfos.ToLookup(i => i.ImageName); return tagFileInfos.Select(i => new ImageStats( i.ImageName, - i.GetWords(), + i.GetWords().OrderBy(w => w).ToArray(), scanFileLookup[i.ImageName] )); }