Archived
Checkpoint
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using ReportGenerator.Generator.Abstract;
|
||||
using Common.Extensions;
|
||||
using ReportGenerator.Generator;
|
||||
using ReportGenerator.Generator.Abstract;
|
||||
using ReportGenerator.Generator.Interface;
|
||||
using ReportGenerator.Generator.Model;
|
||||
using ReportGenerator.Models;
|
||||
@@ -7,19 +9,35 @@ namespace ReportGenerator;
|
||||
|
||||
public class ReportGenerator : FileSerializableBase
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string FileExtension => Document.FileExtension;
|
||||
|
||||
private IDocumentGenerator Document { get; }
|
||||
|
||||
private ICollection<ImageStats> Images { get; }
|
||||
|
||||
public ReportGenerator(IEnumerable<ImageStats> stats, IDocumentGenerator document)
|
||||
public ReportGenerator(
|
||||
IDocumentGenerator document,
|
||||
IEnumerable<ImageStats> data
|
||||
)
|
||||
{
|
||||
Images = stats.ToArray();
|
||||
Document = document;
|
||||
Images = data.ToArray();
|
||||
}
|
||||
|
||||
public ReportGenerator(
|
||||
string title,
|
||||
IDocumentGenerator document,
|
||||
IEnumerable<ImageStats> data
|
||||
) : this(document, data)
|
||||
{
|
||||
WithTitle(title);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => Document.ToString();
|
||||
|
||||
#region Fluent definition
|
||||
#region Report content generation
|
||||
|
||||
public ReportGenerator WithTitle(string text)
|
||||
{
|
||||
@@ -27,7 +45,7 @@ public class ReportGenerator : FileSerializableBase
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReportGenerator WithFullStatistic(string title)
|
||||
public ReportGenerator AddImageStatsFull(string title)
|
||||
{
|
||||
Document.AppendHeading(2, title);
|
||||
|
||||
@@ -77,73 +95,125 @@ public class ReportGenerator : FileSerializableBase
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ReportGenerator WithBestOf(string title, int context = 5)
|
||||
public ReportGenerator AddImageStats(string title)
|
||||
{
|
||||
Document.AppendHeading(2, title);
|
||||
|
||||
foreach (var image in Images)
|
||||
{
|
||||
Document
|
||||
.AppendHeading(3, image.ImageName)
|
||||
.AppendLine(HtmlTools.FormatImage(
|
||||
Path.Combine("img", image.ImageName),
|
||||
new Bounds(0, 300)
|
||||
));
|
||||
|
||||
var byWer = image
|
||||
.Processors
|
||||
.Select(p => (p.Name, p.Distance))
|
||||
.OrderBy(t => t.Item2);
|
||||
Document.AppendHeading(4, "WER");
|
||||
AppendComparison(("Error", "%"), byWer);
|
||||
|
||||
var byCerAvg = image
|
||||
.Processors
|
||||
.Select(p => (p.Name, p.Words.Average(w => w.Distance)))
|
||||
.OrderBy(t => t.Item2);
|
||||
Document.AppendHeading(4, "CER (Average)");
|
||||
AppendComparison(("Changes", string.Empty), byCerAvg);
|
||||
|
||||
var byCerMedian = image
|
||||
.Processors
|
||||
.Select(p => (p.Name, p.Words.Median(w => w.Distance)))
|
||||
.OrderBy(t => t.Item2);
|
||||
Document.AppendHeading(4, "CER (Median)");
|
||||
AppendComparison(("Changes", string.Empty), byCerMedian);
|
||||
|
||||
var byTime = image
|
||||
.Processors
|
||||
.Select(p => (p.Name, p.ProcessingTime))
|
||||
.OrderBy(t => t.Item2);
|
||||
Document.AppendHeading(4, "Time");
|
||||
AppendComparison(("Time", "ms"), byTime);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ReportGenerator AddComparison(
|
||||
string title,
|
||||
Func<IEnumerable<double>, double> evaluationFunc
|
||||
)
|
||||
{
|
||||
var lookup = Images
|
||||
.SelectMany(s => s.Processors)
|
||||
.ToLookup(p => p.Name);
|
||||
|
||||
// Compare time across all images
|
||||
var byTime = lookup
|
||||
.Select(g => (Name: g.Key, Value: g.Average(p => p.ProcessingTime) * 1000))
|
||||
.OrderBy(g => g.Value);
|
||||
Document.AppendHeading(2, title);
|
||||
|
||||
// Compare WER across all images
|
||||
var byWer = lookup
|
||||
.Select(g => (Name: g.Key, Value: g.Average(p => p.Distance) * 100))
|
||||
.Select(g => (
|
||||
Name: g.Key,
|
||||
Value: evaluationFunc(g.Select(p => p.Distance)) * 100
|
||||
))
|
||||
.OrderBy(g => g.Value);
|
||||
Document.AppendHeading(3, "WER");
|
||||
AppendComparison(("Error", "%"), byWer);
|
||||
|
||||
// Compare CER across all images
|
||||
var byCer = lookup
|
||||
.Select(g => (Name: g.Key, Value: g.Average(p => p.Words.Average(w => w.Distance))))
|
||||
.Select(g => (
|
||||
Name: g.Key,
|
||||
Value: evaluationFunc(g.SelectMany(p => p.Words, (_, word) => word.Distance))
|
||||
))
|
||||
.OrderBy(g => g.Value);
|
||||
Document.AppendHeading(3, "CER");
|
||||
AppendComparison(("Changes", string.Empty), byCer);
|
||||
|
||||
// Print
|
||||
AppendComparison(3, "Time", byTime, " ms");
|
||||
AppendComparison(3, "WER", byWer, " %");
|
||||
AppendComparison(3, "CER", byCer, " changes");
|
||||
var byTime = lookup
|
||||
.Select(g => (
|
||||
Name: g.Key,
|
||||
Value: evaluationFunc(g.Select(p => p.ProcessingTime)) * 1000
|
||||
))
|
||||
.OrderBy(g => g.Value);
|
||||
Document.AppendHeading(3, "Time");
|
||||
AppendComparison(("Time", "ms"), byTime);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void AppendComparison(
|
||||
int level,
|
||||
string title,
|
||||
IEnumerable<(string, double)> values,
|
||||
string valueUnit = ""
|
||||
)
|
||||
|
||||
private void AppendComparison(
|
||||
(string name, string unit)? valueInfo,
|
||||
IEnumerable<(string, double)> values
|
||||
)
|
||||
{
|
||||
const int context = 5;
|
||||
|
||||
var tValues = values.ToArray();
|
||||
var tContext = Math.Min(tValues.Length / 2, context);
|
||||
|
||||
Document.AppendTable(2, table =>
|
||||
{
|
||||
var tValues = values.ToArray();
|
||||
var tContext = Math.Min(tValues.Length / 2, context);
|
||||
|
||||
Document
|
||||
.AppendHeading(level, title)
|
||||
.AppendTable(2, table => table
|
||||
.AppendHeader(new[] { "Processor", "Average" })
|
||||
.AppendRows(tValues
|
||||
.Take(tContext).Select(v => new[]
|
||||
{
|
||||
v.Item1,
|
||||
v.Item2.ToString("F2") + valueUnit
|
||||
}))
|
||||
.AppendRow("...")
|
||||
.AppendRows(tValues.TakeLast(tContext).Select(v => new[]
|
||||
{
|
||||
v.Item1,
|
||||
v.Item2.ToString("F2") + valueUnit
|
||||
}))
|
||||
table
|
||||
.AppendHeader(new[] { "Processor", valueInfo?.name ?? "Value" })
|
||||
.AppendRows(tValues
|
||||
.Take(tContext)
|
||||
.Select(MakeRow))
|
||||
.AppendRow("...")
|
||||
.AppendRows(
|
||||
tValues
|
||||
.TakeLast(tContext)
|
||||
.Select(MakeRow)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
string[] MakeRow((string, double) v) =>
|
||||
new[] { v.Item1, v.Item2.ToString("F2") + valueInfo?.unit };
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides of FileSerializableBase
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FileExtension => Document.FileExtension;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user