This commit is contained in:
Simon Gruber
2023-11-22 07:46:10 +01:00
parent beb194c106
commit 8ada606fa6
141 changed files with 158 additions and 139 deletions
+46
View File
@@ -0,0 +1,46 @@
using System.Text;
namespace CLI.Monitor;
public class CliTaskMonitor : TaskMonitor
{
/// <inheritdoc />
public CliTaskMonitor(IEnumerable<(string? Name, Task Task)> tasks) : base(tasks) { }
/// <inheritdoc />
public CliTaskMonitor(IEnumerable<Task> tasks) : base(tasks) { }
#region Overrides of TaskMonitor
/// <inheritdoc />
protected override void OnUpdate(ICollection<(string? Name, Task Task)> tasks)
{
var sb = new StringBuilder(tasks.Count * 30);
foreach (var (name, task) in tasks)
{
sb.Append($"{StatusMap[task.Status],-5}");
if (name is not null)
{
sb.Append(": ")
.Append(name);
}
sb.AppendLine();
if (task.Exception is not null)
{
sb.Append("> EX: ")
.AppendLine(task.Exception.Message);
}
}
sb.AppendLine();
Console.Clear();
Console.Write(sb.ToString());
}
#endregion
}
+6
View File
@@ -0,0 +1,6 @@
namespace CLI.Monitor;
public interface ITaskMonitor
{
Task Run();
}
+39
View File
@@ -0,0 +1,39 @@
namespace CLI.Monitor;
public abstract class TaskMonitor : ITaskMonitor
{
protected static IReadOnlyDictionary<TaskStatus, string> StatusMap { get; } =
new Dictionary<TaskStatus, string>
{
{ TaskStatus.RanToCompletion, "DONE" },
{ TaskStatus.Faulted, "FAULT" },
{ TaskStatus.Canceled, "CANCL" },
{ TaskStatus.Created, "WAIT" },
{ TaskStatus.WaitingToRun, "WAIT" },
{ TaskStatus.WaitingForActivation, "WAIT" },
{ TaskStatus.Running, "RUN" },
{ TaskStatus.WaitingForChildrenToComplete, "RUN" },
};
private readonly ICollection<(string? Name, Task Task)> _tasks;
protected TaskMonitor(IEnumerable<(string? Name, Task Task)> tasks) => _tasks = tasks.ToArray();
protected TaskMonitor(IEnumerable<Task> tasks) :
this(tasks.Select(t => (t.Id.ToString(), t))!)
{ }
public Task Run()
{
var waitTask = Task.WhenAll(_tasks.Select(i => i.Task));
while (!waitTask.Wait(TimeSpan.FromSeconds(1)))
{
OnUpdate(_tasks);
}
return waitTask;
}
protected abstract void OnUpdate(ICollection<(string? Name, Task Task)> tasks);
}
@@ -10,49 +10,50 @@ using Process.Interface;
using System.Text.Json;
using System.Text.RegularExpressions;
namespace CLI.Processor;
internal class EvaluationProcessor
{
#region Configuration
/// <summary>
/// <see cref="Regex"/> expression for extracting whole words from scan results
/// </summary>
private static Regex WordRegex = new(
private static readonly Regex wordRegex = new(
@"[\w'\-]{2,}",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase
);
private static ITesseractConfiguration TesseractConfig = new TesseractScreenshotConfiguration()
{
DataPath = "tessdata",
Languages = new[] { "eng", "deu" }
};
private static readonly ITesseractConfiguration tesseractConfig =
new TesseractScreenshotConfiguration
{
DataPath = "tessdata",
Languages = new[] { "eng", "deu" }
};
private ScreenshotProcessorConfiguration ProcessorConfig = new ScreenshotProcessorConfiguration
{
Border = 0,
EnableResizing = false,
EnableThresholding = false,
FilterConnectedComponents = false,
ThresholdHeight = 0,
ThresholdWidth = 0
};
#endregion
private static readonly TesseractProcessor tesseractProcessor = new(TesseractConfig);
#region Processors
private static readonly IProcessorChain<ScanResult, ScanResult> postProcessor =
new ProcessorChainConfiguration<ScanResult, ScanResult>()
.Use(new ConfidenceFilter(50))
.Use(new ToLowerProcessor())
.Use(new DuplicateFilter())
.Complete(new RegexFilter(WordRegex));
.Complete(new RegexFilter(wordRegex));
private static readonly TesseractProcessor tesseractProcessor = new(tesseractConfig);
private readonly StopwatchProcessor<MagickImage, MagickImage> _thresholdProcessor;
#endregion
public string OutputFolder { get; init; } = "results";
public EvaluationProcessor(IProcessor<MagickImage, MagickImage> thresholdProcessor)
{
_thresholdProcessor = new StopwatchProcessor<MagickImage, MagickImage>(thresholdProcessor);
}
public EvaluationProcessor(
IProcessor<MagickImage, MagickImage> thresholdProcessor
) => _thresholdProcessor = new StopwatchProcessor<MagickImage, MagickImage>(thresholdProcessor);
/// <inheritdoc />
public Task Process(MagickImage image) => Task.Run(async () =>
@@ -108,4 +109,4 @@ internal class EvaluationProcessor
return tImages;
}
}
}
@@ -2,6 +2,8 @@
using Process.Interface;
using System.Diagnostics;
namespace CLI.Processor;
public class StopwatchProcessor<TInput, TOutput> : Processor<TInput, TOutput>
{
private readonly IProcessor<TInput, TOutput> _processor;
@@ -11,11 +13,7 @@ public class StopwatchProcessor<TInput, TOutput> : Processor<TInput, TOutput>
/// </summary>
public TimeSpan? Elapsed { get; private set; }
public StopwatchProcessor(IProcessor<TInput, TOutput> processor)
{
_processor = processor;
}
public StopwatchProcessor(IProcessor<TInput, TOutput> processor) => _processor = processor;
public override IEnumerable<TOutput> Process(IEnumerable<TInput> inputs)
{
@@ -26,7 +24,6 @@ public class StopwatchProcessor<TInput, TOutput> : Processor<TInput, TOutput>
return results;
}
/// <inheritdoc />
public override string? ToString() => _processor.ToString();
}
+14 -45
View File
@@ -1,25 +1,14 @@
using Common.Extensions;
using CLI.Monitor;
using CLI.Processor;
using Common.Extensions;
using ImageMagick;
using Ocr.Tesseract.Screenshots.Threshold;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace CLI;
public class Program
{
private readonly IDictionary<TaskStatus, string> _statusMap = new Dictionary<TaskStatus, string>()
{
{ TaskStatus.RanToCompletion, "DONE" },
{ TaskStatus.Faulted, "FAULT" },
{ TaskStatus.Canceled, "CANCL" },
{ TaskStatus.Created, "WAIT" },
{ TaskStatus.WaitingToRun, "WAIT" },
{ TaskStatus.WaitingForActivation, "WAIT" },
{ TaskStatus.Running, "RUN" },
{ TaskStatus.WaitingForChildrenToComplete, "RUN" },
};
public Task Run(string[] args)
{
var scans = (
@@ -28,42 +17,22 @@ public class Program
select (Key: path, Task: processor.Process(new MagickImage(path)))
).ToArray();
var waitTask = Task.WhenAll(scans.Select(i => i.Task));
while (!waitTask.Wait(TimeSpan.FromSeconds(1)))
{
var sb = new StringBuilder(scans.Length * 30);
foreach (var info in scans)
{
sb.AppendLine($"{_statusMap[info.Task.Status],-5}: {info.Key}");
if (info.Task.Exception is not null)
{
sb.AppendLine($"> EX: {info.Task.Exception?.Message}");
}
}
sb.AppendLine();
Console.Clear();
Console.Write(sb.ToString());
}
return waitTask;
return new CliTaskMonitor(scans).Run();
}
[SuppressMessage("ReSharper", "ArrangeObjectCreationWhenTypeNotEvident")]
private static IEnumerable<EvaluationProcessor> MakeThresholdVariations()
{
yield return new(new ThresholdAdaptiveProcessor(17));
yield return new(new ThresholdAdaptiveProcessor(5));
yield return new(new ThresholdAdaptiveProcessor(10));
yield return new(new ThresholdAdaptiveProcessor(15));
yield return new(new ThresholdProcessor(20));
yield return new(new ThresholdProcessor(40));
yield return new(new ThresholdProcessor(60));
yield return new(new ThresholdProcessor(80));
for (int i = 0; i <= 24; i += 2)
{
yield return new(new ThresholdAdaptiveProcessor(i));
}
for (int i = 0; i <= 100; i += 10)
{
yield return new(new ThresholdProcessor(i));
}
yield return new(new AutoThresholdProcessor(AutoThresholdMethod.Kapur));
yield return new(new AutoThresholdProcessor(AutoThresholdMethod.OTSU));
yield return new(new AutoThresholdProcessor(AutoThresholdMethod.Triangle));
-12
View File
@@ -17,16 +17,4 @@
<ProjectReference Include="..\..\Process\Process.Interface\Process.Interface.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="tessdata\deu.traineddata">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="tessdata\eng.traineddata">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="tessdata\osd.traineddata">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
+1 -2
View File
@@ -1,5 +1,4 @@
using ReportGenerator.Models;
using System.Collections;
using System.Collections;
namespace Common.Distance;
@@ -1,6 +1,6 @@
using System.Collections;
namespace ReportGenerator.Models;
namespace Common.Distance;
public interface IDistanceComparer
{
+2
View File
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=tesseract/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
-27
View File
@@ -15,31 +15,4 @@
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="img\command-processing_screentypes_controlgroup_005.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="img\editor_startpage_project-exist_001.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="img\editor_windows_position_006.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="img\historian_assistent_001.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="img\zrs_MetadataEditor_variables_001.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="img\zrs_REPORTS_EfficencyClass_009.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="img\zrs_ZAMS_3rd-connector_014.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="img\zrs_ZAMS_filter-alarmgroup_001.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

@@ -43,7 +43,6 @@ public struct ScanFileInfo
};
}
/// <inheritdoc />
public override string ToString() => ImageName;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Some files were not shown because too many files have changed in this diff Show More