Complete Class

This commit is contained in:
2024-10-31 09:53:26 -07:00
parent bb1552d210
commit 2b16357d44
18 changed files with 671 additions and 82 deletions

View File

@ -9,6 +9,7 @@ using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Adaptation.FileHandlers.InterceptIQS;
@ -111,8 +112,17 @@ public class FileRead : Shared.FileRead, IFileRead
private void ReWriteFile(string reportFullPath, DateTime dateTime)
{
string text = File.ReadAllText(reportFullPath);
List<string> segments = text.Split(new string[] { "," }, StringSplitOptions.None).ToList();
string text;
List<string> segments = new();
for (int i = 0; i < _FileConnectorConfiguration.ConnectionRetryInterval; i++)
{
segments.Clear();
text = File.ReadAllText(reportFullPath);
segments.AddRange(text.Split(new string[] { "," }, StringSplitOptions.None));
if (segments.Count == 22)
break;
Thread.Sleep(500);
}
if (segments.Count == 22)
{
string rds = segments[2];

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.pcl;
#nullable enable
internal class Complete
{
public Complete(Header header, Summary summary, ReadOnlyCollection<Point> points)
{
Header = header;
Summary = summary;
Points = points;
}
public Header Header { get; }
public Summary Summary { get; }
public ReadOnlyCollection<Point> Points { get; }
public static Complete? Get(int take, string site, string multiple, string summaryLine, string lastUnits, string[] lines)
{
Complete? result;
Header? header = Header.Get(lines, site, summaryLine);
if (header is null)
result = null;
else
{
Summary? summary = SummarySegment.Get(lines, site, summaryLine);
if (summary is null)
result = null;
else
{
ReadOnlyCollection<Point> points = Point.GetCollection(lines, take, site, multiple, summaryLine, lastUnits) ?? throw new NullReferenceException(nameof(summary));
if (points.Count == 0)
result = null;
else
result = new(header, summary, points);
}
}
return result;
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Complete))]
internal partial class CompleteSourceGenerationContext : JsonSerializerContext
{
}

View File

@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.pcl;
#nullable enable
internal class Header
// internal record Header([property: JsonPropertyName("Operator")] string Operator,
// [property: JsonPropertyName("Start Voltage")] string StartVoltage,
// [property: JsonPropertyName("Wafer")] string Wafer,
// [property: JsonPropertyName("Stop Voltage")] string StopVoltage,
// [property: JsonPropertyName("Lot")] string Lot,
// [property: JsonPropertyName("Ramp Rate")] string RampRate,
// [property: JsonPropertyName("Plan")] string Plan,
// [property: JsonPropertyName("G limit")] string GLimit,
// [property: JsonPropertyName("Date")] string Date,
// [property: JsonPropertyName("Time")] string Time,
// [property: JsonPropertyName("Setup File")] string SetupFile,
// [property: JsonPropertyName("Wafer size")] string WaferSize,
// [property: JsonPropertyName("Folder")] string Folder,
// [property: JsonPropertyName("Ccomp")] string Ccomp,
// [property: JsonPropertyName("Pattern")] string Pattern,
// [property: JsonPropertyName("Area")] string Area,
// [property: JsonPropertyName("Cond Type")] string CondType,
// [property: JsonPropertyName("Rho Method")] string RhoMethod,
// [property: JsonPropertyName("Model")] string Model)
{
[JsonConstructor]
public Header(string @operator, string startVoltage, string wafer, string stopVoltage, string lot, string rampRate, string plan, string gLimit, string date, string time, string setupFile, string waferSize, string folder, string ccomp, string pattern, string area, string condType, string rhoMethod, string model)
{
Operator = @operator;
StartVoltage = startVoltage;
Wafer = wafer;
StopVoltage = stopVoltage;
Lot = lot;
RampRate = rampRate;
Plan = plan;
GLimit = gLimit;
Date = date;
Time = time;
SetupFile = setupFile;
WaferSize = waferSize;
Folder = folder;
Ccomp = ccomp;
Pattern = pattern;
Area = area;
CondType = condType;
RhoMethod = rhoMethod;
Model = model;
}
[JsonPropertyName("Operator")] public string Operator { get; }
[JsonPropertyName("Start Voltage")] public string StartVoltage { get; }
[JsonPropertyName("Wafer")] public string Wafer { get; }
[JsonPropertyName("Stop Voltage")] public string StopVoltage { get; }
[JsonPropertyName("Lot")] public string Lot { get; }
[JsonPropertyName("Ramp Rate")] public string RampRate { get; }
[JsonPropertyName("Plan")] public string Plan { get; }
[JsonPropertyName("G limit")] public string GLimit { get; }
[JsonPropertyName("Date")] public string Date { get; }
[JsonPropertyName("Time")] public string Time { get; }
[JsonPropertyName("Setup File")] public string SetupFile { get; }
[JsonPropertyName("Wafer size")] public string WaferSize { get; }
[JsonPropertyName("Folder")] public string Folder { get; }
[JsonPropertyName("Ccomp")] public string Ccomp { get; }
[JsonPropertyName("Pattern")] public string Pattern { get; }
[JsonPropertyName("Area")] public string Area { get; }
[JsonPropertyName("Cond Type")] public string CondType { get; }
[JsonPropertyName("Rho Method")] public string RhoMethod { get; }
[JsonPropertyName("Model")] public string Model { get; }
private static string[] GetRemove() =>
new string[]
{
" L L",
" O O",
" G G",
" C C",
" O O",
" N N",
" C C",
" E E",
" N N",
" T T",
" R R",
" A A",
" T T",
" I I",
" O O",
" N N"
};
public static Header Get() =>
new(string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty);
private static ReadOnlyCollection<JsonProperty> GetJsonProperties()
{
JsonProperty[] results;
string json;
Header header = Get();
json = JsonSerializer.Serialize(header);
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
results = jsonElement.EnumerateObject().ToArray();
return new(results);
}
public static Header? Get(string[] lines, string site, string summaryLine)
{
Header? result;
string json;
string check;
string[] segments;
string[] segmentsB;
string[] segmentsC;
bool found = false;
string[] remove = GetRemove();
Dictionary<string, string> keyValuePairs = new();
ReadOnlyCollection<JsonProperty> jsonProperties = GetJsonProperties();
foreach (string line in lines)
{
if (line.Contains(site))
found = true;
if (!found)
continue;
if (line == summaryLine)
break;
foreach (JsonProperty jsonProperty in jsonProperties)
{
segments = line.Split(new string[] { $"{jsonProperty.Name}:", $"{jsonProperty.Name} :" }, StringSplitOptions.None);
if (segments.Length < 2)
continue;
check = segments[1].Trim();
foreach (JsonProperty jsonPropertyB in jsonProperties)
{
segmentsB = check.Split(new string[] { $"{jsonPropertyB.Name}:", $"{jsonPropertyB.Name} :" }, StringSplitOptions.None);
if (segmentsB.Length > 1)
check = segmentsB[0].Trim();
}
foreach (string r in remove)
{
segmentsC = check.Split(new string[] { r }, StringSplitOptions.None);
if (segmentsC.Length > 1)
check = segmentsC[0].Trim();
}
keyValuePairs.Add(jsonProperty.Name, check);
}
}
if (keyValuePairs.Count != jsonProperties.Count)
result = null;
else
{
json = JsonSerializer.Serialize(keyValuePairs);
result = JsonSerializer.Deserialize(json, HeaderSourceGenerationContext.Default.Header) ?? throw new NullReferenceException(nameof(result));
}
return result;
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Header))]
internal partial class HeaderSourceGenerationContext : JsonSerializerContext
{
}

View File

@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.pcl;
#nullable enable
internal class Point
// internal record Point([property: JsonPropertyName("Site")] string Site,
// [property: JsonPropertyName("X")] string X,
// [property: JsonPropertyName("Y")] string Y,
// [property: JsonPropertyName("Navg")] string NAvg,
// [property: JsonPropertyName("Rhoavg")] string RhoAvg,
// [property: JsonPropertyName("Nsl")] string Nsl,
// [property: JsonPropertyName("Rhosl")] string Rhosl,
// [property: JsonPropertyName("Vd")] string Vd,
// [property: JsonPropertyName("Phase")] string Phase,
// [property: JsonPropertyName("Flat Z")] string FlatZ,
// [property: JsonPropertyName("Grade")] string Grade,
// [property: JsonPropertyName("X Left")] string XLeft,
// [property: JsonPropertyName("X Right")] string XRight,
// [property: JsonPropertyName("Bottom Y")] string BottomY,
// [property: JsonPropertyName("Top Y")] string TopY)
{
public Point(string site, string x, string y, string nAvg, string rhoAvg, string nsl, string rhosl, string vd, string phase, string flatZ, string grade, string xLeft, string xRight, string bottomY, string topY)
{
Site = site;
X = x;
Y = y;
NAvg = nAvg;
RhoAvg = rhoAvg;
Nsl = nsl;
Rhosl = rhosl;
Vd = vd;
Phase = phase;
FlatZ = flatZ;
Grade = grade;
XLeft = xLeft;
XRight = xRight;
BottomY = bottomY;
TopY = topY;
}
[JsonPropertyName("Site")] public string Site { get; }
[JsonPropertyName("X")] public string X { get; }
[JsonPropertyName("Y")] public string Y { get; }
[JsonPropertyName("Navg")] public string NAvg { get; }
[JsonPropertyName("Rhoavg")] public string RhoAvg { get; }
[JsonPropertyName("Nsl")] public string Nsl { get; }
[JsonPropertyName("Rhosl")] public string Rhosl { get; }
[JsonPropertyName("Vd")] public string Vd { get; }
[JsonPropertyName("Phase")] public string Phase { get; }
[JsonPropertyName("Flat Z")] public string FlatZ { get; }
[JsonPropertyName("Grade")] public string Grade { get; }
[JsonPropertyName("X Left")] public string XLeft { get; }
[JsonPropertyName("X Right")] public string XRight { get; }
[JsonPropertyName("Bottom Y")] public string BottomY { get; }
[JsonPropertyName("Top Y")] public string TopY { get; }
public static Point Get() =>
new(string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty);
public static ReadOnlyCollection<Point> GetCollection(string[] lines, int take, string site, string multiple, string summaryLine, string lastUnits)
{
List<Point> results = new();
string s;
string line;
Point point;
string[] segments;
string[] segmentsB;
bool found = false;
bool foundB = false;
string[] segmentsC;
List<string> sites = new();
for (int i = 0; i < lines.Length; i++)
{
line = lines[i];
segmentsC = line.Split(new string[] { site }, StringSplitOptions.RemoveEmptyEntries);
if (segmentsC.Length > 1)
{
foreach (string segment in segmentsC)
sites.Add(segment.Trim());
}
if (line == summaryLine)
{
sites.RemoveAt(0);
found = true;
}
if (!found)
continue;
if (!foundB && line.Contains(multiple))
foundB = true;
if (line != lastUnits)
continue;
if (foundB)
{
foundB = false;
continue;
}
for (int j = 0; j < sites.Count; j++)
{
s = sites[j];
if (i + take > lines.Length)
break;
segments = s.Split(new string[] { "(", ",", ")" }, StringSplitOptions.None);
if (segments.Length < 2)
break;
segmentsB = lines[i + 10].Split(' ');
if (segmentsB.Length < 2)
break;
point = new(segments[0].Trim(),
segments[1].Trim(),
segments[2].Trim(),
nAvg: lines[i + 2].Trim(),
nsl: lines[i + 3].Trim(),
vd: lines[i + 4].Trim(),
flatZ: lines[i + 5].Trim(),
rhoAvg: lines[i + 6].Trim(),
rhosl: lines[i + 7].Trim(),
phase: lines[i + 8].Trim(),
grade: lines[i + 9].Trim(),
xLeft: segmentsB[0],
xRight: segmentsB[1],
bottomY: lines[i + 11].Trim(),
topY: lines[i + 12].Trim());
results.Add(point);
i += take;
}
sites.Clear();
}
return new(results);
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Point))]
internal partial class PointSourceGenerationContext : JsonSerializerContext
{
}

View File

@ -530,6 +530,27 @@ public class ProcessData : IProcessData
}
}
#nullable enable
private Complete? GetComplete(string altHeaderFileName)
{
Complete? result;
const int take = 12;
const string site = "Site: ";
const string multiple = "MULTIPLE";
const string summaryLine = "SUMMARY A A";
const string lastUnits = "Flat Z: Grade : % Flat Z: Grade : % Flat Z: Grade : %";
string[] lines = File.ReadAllLines(altHeaderFileName);
if (lines.Length > take)
result = Complete.Get(take, site, multiple, summaryLine, lastUnits, lines);
else
{
result = null;
_Log.Warn($"File {altHeaderFileName} has less than 5 lines");
}
return result;
}
#pragma warning disable IDE0060
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName, string pdfTextStripperFileName)
#pragma warning restore IDE0060
@ -673,10 +694,25 @@ public class ProcessData : IProcessData
detail.UniqueId = string.Concat(detail, detail.UniqueId);
}
fileInfoCollection.Add(logistics.FileInfo);
try
{
Complete? complete = GetComplete(altHeaderFileName);
if (complete is null)
_Log.Warn($"Could not get Complete from {altHeaderFileName}");
else
{
FileInfo fileInfo = new($"{altHeaderFileName}.json");
string json = JsonSerializer.Serialize(complete, CompleteSourceGenerationContext.Default.Complete);
File.WriteAllText(fileInfo.FullName, json);
fileInfoCollection.Add(fileInfo);
}
}
catch (Exception ex)
{
_Log.Error($"Error in {nameof(GetComplete)}", ex);
}
}
#nullable enable
internal static List<Description> GetDescriptions(JsonElement[] jsonElements)
{
List<Description> results = new();

View File

@ -0,0 +1,19 @@
namespace Adaptation.FileHandlers.pcl;
#nullable enable
internal class Summary
{
public Summary(SummarySegment? mean, SummarySegment? standardDeviationPercentage, SummarySegment? radialGradient)
{
Mean = mean;
StandardDeviationPercentage = standardDeviationPercentage;
RadialGradient = radialGradient;
}
public SummarySegment? Mean { get; }
public SummarySegment? StandardDeviationPercentage { get; }
public SummarySegment? RadialGradient { get; }
}

View File

@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.pcl;
#nullable enable
internal class SummarySegment
// internal record SummarySegment([property: JsonPropertyName("Navg")] string NAvg,
// [property: JsonPropertyName("Nsl")] string Nsl,
// [property: JsonPropertyName("Vd")] string Vd,
// [property: JsonPropertyName("@ Flat Z")] string FlatZ,
// [property: JsonPropertyName("Rhoavg")] string RhoAvg,
// [property: JsonPropertyName("Rhosl")] string Rhosl,
// [property: JsonPropertyName("Phase")] string Phase,
// [property: JsonPropertyName("Grade")] string Grade,
// [property: JsonPropertyName("@ Rs")] string Rs)
{
public SummarySegment(string nAvg, string nsl, string vd, string flatZ, string rhoAvg, string rhosl, string phase, string grade, string rs)
{
NAvg = nAvg;
Nsl = nsl;
Vd = vd;
FlatZ = flatZ;
RhoAvg = rhoAvg;
Rhosl = rhosl;
Phase = phase;
Grade = grade;
Rs = rs;
}
[JsonPropertyName("Navg")] public string NAvg { get; }
[JsonPropertyName("Nsl")] public string Nsl { get; }
[JsonPropertyName("Vd")] public string Vd { get; }
[JsonPropertyName("@ Flat Z")] public string FlatZ { get; }
[JsonPropertyName("Rhoavg")] public string RhoAvg { get; }
[JsonPropertyName("Rhosl")] public string Rhosl { get; }
[JsonPropertyName("Phase")] public string Phase { get; }
[JsonPropertyName("Grade")] public string Grade { get; }
[JsonPropertyName("@ Rs")] public string Rs { get; }
public static SummarySegment Get() =>
new(string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty);
private static ReadOnlyCollection<JsonProperty> GetJsonProperties()
{
JsonProperty[] results;
string json;
SummarySegment summarySegment = Get();
json = JsonSerializer.Serialize(summarySegment);
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
results = jsonElement.EnumerateObject().ToArray();
return new(results);
}
public static Summary? Get(string[] lines, string site, string summaryLine)
{
Summary? result;
string json;
string[] segments;
bool found = false;
string[] segmentsB;
Dictionary<string, string> keyValuePairs = new();
Dictionary<string, string> keyValuePairsB = new();
Dictionary<string, string> keyValuePairsC = new();
ReadOnlyCollection<JsonProperty> jsonProperties = GetJsonProperties();
foreach (string line in lines)
{
if (line == summaryLine)
found = true;
if (!found)
continue;
if (line.Contains(site))
break;
foreach (JsonProperty jsonProperty in jsonProperties)
{
segments = line.Split(new string[] { $"{jsonProperty.Name}:", $"{jsonProperty.Name} :" }, StringSplitOptions.None);
if (segments.Length < 2 || !line.StartsWith(jsonProperty.Name))
continue;
segmentsB = segments[1].Trim().Split(' ');
if (segmentsB.Length < 3)
continue;
keyValuePairs.Add(jsonProperty.Name, segmentsB[0]);
keyValuePairsB.Add(jsonProperty.Name, segmentsB[1]);
keyValuePairsC.Add(jsonProperty.Name, segmentsB[2]);
}
}
if (keyValuePairs.Count != jsonProperties.Count || keyValuePairsB.Count != jsonProperties.Count || keyValuePairsC.Count != jsonProperties.Count)
result = null;
else
{
json = JsonSerializer.Serialize(keyValuePairs);
SummarySegment? mean = JsonSerializer.Deserialize(json, SummarySegmentSourceGenerationContext.Default.SummarySegment);
json = JsonSerializer.Serialize(keyValuePairsB);
SummarySegment? standardDeviationPercentage = JsonSerializer.Deserialize(json, SummarySegmentSourceGenerationContext.Default.SummarySegment);
json = JsonSerializer.Serialize(keyValuePairsC);
SummarySegment? radialGradient = JsonSerializer.Deserialize(json, SummarySegmentSourceGenerationContext.Default.SummarySegment);
result = new(mean, standardDeviationPercentage, radialGradient);
}
return result;
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(SummarySegment))]
internal partial class SummarySegmentSourceGenerationContext : JsonSerializerContext
{
}