This repository has been archived on 2024-06-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
thesis-src/Examples/ReportGenerator/Models/ImageStats.cs
T
Simon Gruber 9ac01e6b12 checkpoint
2023-11-20 14:26:00 +01:00

53 lines
1.4 KiB
C#

namespace ReportGenerator.Models;
internal readonly struct ImageStats
{
public string ImageName { get; } = string.Empty;
public ICollection<string> Reference { get; } = Array.Empty<string>();
public ICollection<ProcessorStat> Stats { get; } = Array.Empty<ProcessorStat>();
public ImageStats(
string imageName,
ICollection<string> taggedWords,
IEnumerable<ScannedResultInfo> scanResult
)
{
Reference = taggedWords;
ImageName = imageName;
Stats = scanResult
.Select(t => new ProcessorStat(t.ProcessorName, taggedWords, t.GetWords()))
.ToArray();
}
public IEnumerable<IEnumerable<string>> ToTable()
{
// Title
yield return Stats.Select(s => s.ProcessorName).Prepend("Reference");
// Spacer
yield return Stats.Select(s => "---").Prepend("---");
// Content
foreach (var reference in Reference)
{
yield return Stats.SelectMany(s => s.ToRow(reference)).Prepend(reference);
}
// 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");
}
}