Formatting fixes

This commit is contained in:
Simon
2024-01-15 00:05:04 +01:00
parent 22800639d0
commit b21afe6121
45 changed files with 434 additions and 4016 deletions
@@ -24,6 +24,9 @@ internal static class Program
using var document = new LatexIncludeDocumentGenerator(path, true);
using var report = new ReportGenerator("OCR Report", document, scans)
{
MaxDisplayRows = 8
}
.AddComparison("Processing summary (Average)", v =>
{
var result = v.Average(out var deviation);
@@ -1,11 +1,15 @@
using Ocr.Report.Models;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using Ocr.Report.Models;
using ReportGeneration.Abstract.Model;
using ReportGeneration.Interface;
using System;
namespace Ocr.Report;
public class ReportGenerator : IDisposable
{
public int? MaxDisplayRows { get; init; }
private IDocumentGenerator Document { get; }
private ICollection<ImageStats> Images { get; }
@@ -57,7 +61,7 @@ public class ReportGenerator : IDisposable
foreach (var (processor, images) in processors)
{
var ordered = images
IEnumerable<(ImageStats Stats, double Distance)> ordered = images
.Select(i => (Stats: i, Distance: i
.Processors
.Where(p => p.Name.Equals(processor))
@@ -66,10 +70,17 @@ public class ReportGenerator : IDisposable
))
.OrderBy(i => i.Distance)
.ToArray();
if (MaxDisplayRows.HasValue)
{
ordered = ordered
.Take(MaxDisplayRows.Value / 2)
.Concat(ordered.TakeLast(MaxDisplayRows.Value / 2));
}
Document
.AppendHeading(3, processor)
.AppendTable(2, table =>
.AppendTable(3, table =>
{
table.AppendHeader(new[] { "Image", "Preview", "Distance" });
@@ -79,7 +90,7 @@ public class ReportGenerator : IDisposable
table.AppendRow(new[]
{
$"<a href=\"#{stats.ImageName}\">{stats.ImageName}</a>",
Ellipsis(stats.ImageName.Replace("\\", "\\\\") + ".png", 25),
Document.FormatImage(imgPath, new Bounds(0, 150)),
distance.ToString("F2")
});
@@ -103,7 +114,7 @@ public class ReportGenerator : IDisposable
Document.FormatImage(Path.Combine("img", stat.ImageName), new Bounds(0, 350))
)
.AppendTable(
stat.Reference.Count + 5,
stat.Reference.Count + 6,
table =>
{
table.AppendHeader(stat
@@ -116,9 +127,17 @@ public class ReportGenerator : IDisposable
.Prepend("Processor")
);
var processors = stat.Processors
IEnumerable<ProcessorStat> processors = stat.Processors
.OrderBy(s => s.Distance)
.ThenBy(s => s.ProcessingTime);
.ThenBy(s => s.ProcessingTime)
.ToArray();
if (MaxDisplayRows.HasValue)
{
processors = processors
.Take(MaxDisplayRows.Value / 2)
.Concat(processors.TakeLast(MaxDisplayRows.Value / 2));
}
foreach (var processor in processors)
{
@@ -131,7 +150,7 @@ public class ReportGenerator : IDisposable
.Prepend(processor.Words.Average(s => s.Distance).ToString("F2"))
.Prepend($"{processor.Distance * 100:F1}%")
.Prepend($"{processor.ProcessingTime * 1000:F1}ms")
.Prepend(processor.Name)
.Prepend(Ellipsis(processor.Name, 25))
);
}
})
@@ -243,6 +262,20 @@ public class ReportGenerator : IDisposable
#endregion
private static string Ellipsis(string str, int maxLength, string ellipsis = "...")
{
if (str.Length <= maxLength)
{
return str;
}
int subStrLen = (maxLength - ellipsis.Length) / 2;
return string.Concat(
str.Substring(0, subStrLen),
ellipsis,
str.Substring(str.Length - subStrLen, subStrLen));
}
#region IDisposable
protected virtual void Dispose(bool disposing)
@@ -261,4 +294,4 @@ public class ReportGenerator : IDisposable
}
#endregion
}
}