Reqiure Complete

This commit is contained in:
2024-11-20 08:16:28 -07:00
parent 0f6308ace5
commit bd8552edea
8 changed files with 163 additions and 128 deletions

View File

@ -3,6 +3,7 @@ using Adaptation.Shared.Methods;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Diagnostics;
using System.IO;
@ -72,9 +73,8 @@ public class ProcessData : IProcessData
List<object> Shared.Properties.IProcessData.Details => _Details;
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName)
internal ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<string, string> pages, Complete complete)
{
fileInfoCollection.Clear();
_Details = new List<object>();
_I = 0;
_Data = string.Empty;
@ -82,7 +82,7 @@ public class ProcessData : IProcessData
Date = GetDateTime(logistics);
MesEntity = logistics.MesEntity;
_Log = LogManager.GetLogger(typeof(ProcessData));
Parse(fileRead, logistics, fileInfoCollection, ghostPCLFileName);
Parse(fileRead, logistics, fileInfoCollection, pages, complete);
}
private static DateTime GetDateTime(Logistics logistics) =>
@ -381,7 +381,7 @@ public class ProcessData : IProcessData
return result;
}
private void Set(ILogistics logistics)
private void Set(ILogistics logistics, Complete complete)
{
string lot;
string rds;
@ -390,14 +390,9 @@ public class ProcessData : IProcessData
string reactor;
string employee;
ScanPast("Recipe ID:");
recipe = GetBefore("LotID:");
recipe = recipe.Replace(";", "");
if (_Data.Contains("[]"))
lot = GetBefore("[]");
else if (_Data.Contains("[7]"))
lot = GetBefore("[7]");
else
lot = GetBefore("[");
_ = GetBefore("LotID:");
lot = complete.Header.Id;
recipe = complete.Header.Recipe;
Descriptor descriptor = GetDescriptor(lot);
lot = descriptor.Lot;
psn = descriptor.PSN;
@ -413,10 +408,8 @@ public class ProcessData : IProcessData
UniqueId = string.Format("{0}_{1}_{2}", logistics.JobID, lot, Path.GetFileNameWithoutExtension(logistics.ReportFullPath));
}
private void ParseLotSummary(IFileRead fileRead, ILogistics logistics, string headerFileName, Dictionary<string, string> pages, Dictionary<string, List<Detail>> slots)
private void ParseLotSummary(ILogistics logistics, ReadOnlyDictionary<string, string> pages, Complete complete, string headerFileName, Dictionary<string, List<Detail>> slots)
{
if (fileRead is null)
throw new ArgumentNullException(nameof(fileRead));
_I = 0;
ParseErrorText = string.Empty;
if (!pages.TryGetValue(headerFileName, out string value))
@ -425,7 +418,7 @@ public class ProcessData : IProcessData
_Data = value;
ScanPast("Date:");
_ = GetToEOL();
Set(logistics);
Set(logistics, complete);
// determine number of wafers and their slot numbers
_Log.Debug(_Data.Substring(_I));
string slot;
@ -501,7 +494,7 @@ public class ProcessData : IProcessData
HazeAverageStdDev = toEol4[8].Trim();
}
private Detail ParseWaferSummary(string waferFileName, Dictionary<string, string> pages)
private Detail ParseWaferSummary(string waferFileName, ReadOnlyDictionary<string, string> pages)
{
Detail result = new() { Data = "*Data*", i = -1, };
_I = 0;
@ -604,110 +597,19 @@ public class ProcessData : IProcessData
#nullable enable
private static Complete? GetComplete(string headerFileName, Dictionary<string, string> pages)
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<string, string> pages, Complete complete)
{
Complete? result;
Constant constant = new();
result = Complete.Get(headerFileName, pages, constant);
return result;
}
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName)
{
object item;
string pageText;
string pagePDFFile;
string pageTextFile;
if (!fileRead.IsEAFHosted)
fileInfoCollection.Clear();
List<string> sourceFiles = new();
List<string> missingSlots = new();
Dictionary<string, string> pages = new();
string sourceFileNamePdf = ConvertSourceFileToPdf(ghostPCLFileName, logistics);
sourceFiles.Add(sourceFileNamePdf);
Dictionary<string, List<Detail>> slots = new();
List<Tuple<string, string>> pageMapping = new();
_Log.Debug($"****ParseData - Parsing lot summary");
string headerFileName = pages.ElementAt(pages.Count - 1).Key;
ParseLotSummary(logistics, pages, complete, headerFileName, slots);
string sourcePath = Path.GetDirectoryName(logistics.ReportFullPath) ?? throw new Exception();
string sourceFileNameWithoutExtension = Path.GetFileNameWithoutExtension(logistics.ReportFullPath);
string[] txtFiles = Directory.GetFiles(sourcePath, $"{sourceFileNameWithoutExtension}_*.txt", SearchOption.TopDirectoryOnly);
if (txtFiles.Length != 0)
{
foreach (string txtFile in txtFiles)
{
sourceFiles.Add(txtFile);
pageText = File.ReadAllText(txtFile);
pagePDFFile = Path.ChangeExtension(txtFile, ".pdf");
if (!File.Exists(pagePDFFile))
continue;
pages.Add(pagePDFFile, pageText);
}
}
if (pages.Count == 0)
{
java.io.File file = new(sourceFileNamePdf);
org.apache.pdfbox.util.Splitter splitter = new();
org.apache.pdfbox.pdmodel.PDDocument pdDocument = org.apache.pdfbox.pdmodel.PDDocument.load(file);
java.util.List list = splitter.split(pdDocument);
java.util.ListIterator iterator = list.listIterator();
org.apache.pdfbox.util.PDFTextStripper dataStripper = new();
for (short i = 1; i < short.MaxValue; i++)
{
if (!iterator.hasNext())
break;
item = iterator.next();
pagePDFFile = string.Concat(sourcePath, @"\", sourceFileNameWithoutExtension, "_", i, ".pdf");
pageTextFile = Path.ChangeExtension(pagePDFFile, ".txt");
if (File.Exists(pageTextFile))
{
pageText = File.ReadAllText(pageTextFile);
sourceFiles.Add(pageTextFile);
if (item is not org.apache.pdfbox.pdmodel.PDDocument pd)
continue;
pd.close();
}
else if (File.Exists(pagePDFFile))
{
org.apache.pdfbox.pdmodel.PDDocument document = org.apache.pdfbox.pdmodel.PDDocument.load(pagePDFFile);
pageText = dataStripper.getText(document);
document.close();
sourceFiles.Add(pagePDFFile);
if (item is not org.apache.pdfbox.pdmodel.PDDocument pd)
continue;
pd.close();
}
else
{
if (item is not org.apache.pdfbox.pdmodel.PDDocument pd)
continue;
pageText = dataStripper.getText(pd);
pd.save(pagePDFFile);
sourceFiles.Add(pagePDFFile);
pd.close();
File.WriteAllText(pageTextFile, pageText);
sourceFiles.Add(pageTextFile);
}
pages.Add(pagePDFFile, pageText);
}
pdDocument.close();
}
_Log.Debug($"****ParseData - Parsing lot summary");
List<Tuple<string, string>> pageMapping = new();
string headerFileName = string.Concat(sourcePath, @"\", sourceFileNameWithoutExtension, "_", pages.Count, ".pdf");
try
{
Complete? complete = GetComplete(headerFileName, pages);
if (complete is null)
_Log.Warn($"Could not get Complete from {sourceFileNameWithoutExtension}");
else
{
FileInfo fileInfo = new($"{sourceFileNameWithoutExtension}.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);
}
Dictionary<string, List<Detail>> slots = new();
ParseLotSummary(fileRead, logistics, headerFileName, pages, slots);
foreach (KeyValuePair<string, string> keyValuePair in pages)
{
if (keyValuePair.Key == headerFileName)
@ -793,8 +695,6 @@ public class ProcessData : IProcessData
fileInfoCollection.Add(logistics.FileInfo);
}
#nullable enable
internal static List<Description> GetDescriptions(JsonElement[] jsonElements)
{
List<Description> results = new();