diff --git a/Adaptation/FileHandlers/pcl/Constant.cs b/Adaptation/FileHandlers/pcl/Constant.cs index c8fa9f2..7bdb5c7 100644 --- a/Adaptation/FileHandlers/pcl/Constant.cs +++ b/Adaptation/FileHandlers/pcl/Constant.cs @@ -9,5 +9,7 @@ internal class Constant public string Date { get; } = "Date:"; public string StdDev { get; } = "Std Dev:"; public string Average { get; } = "Average:"; + public string Statistics { get; } = "Statistics:"; + public string DatabaseId { get; } = "Database ID:"; } \ No newline at end of file diff --git a/Adaptation/FileHandlers/pcl/Header.cs b/Adaptation/FileHandlers/pcl/Header.cs index 66cc5b9..e4ee321 100644 --- a/Adaptation/FileHandlers/pcl/Header.cs +++ b/Adaptation/FileHandlers/pcl/Header.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Text.Json.Serialization; namespace Adaptation.FileHandlers.pcl; @@ -215,17 +216,35 @@ public class Header return GetBefore(text, i, "\n", false); } - internal static Header Get(ReadOnlyDictionary pages, Constant constant, string headerFileName) + private static string? GetText(ReadOnlyDictionary pages, Constant constant) + { + string? text; + string? headerFileName = null; + foreach (KeyValuePair keyValuePair in pages) + { + if (!pages.TryGetValue(keyValuePair.Key, out text)) + throw new Exception(); + if (!text.Contains(constant.Statistics)) + continue; + headerFileName = keyValuePair.Key; + } + headerFileName ??= pages.Count == 0 ? string.Empty : pages.ElementAt(pages.Count - 1).Key; + if (pages.Count == 0 || !pages.TryGetValue(headerFileName, out text)) + text = null; + return text; + } + + internal static Header Get(ReadOnlyDictionary pages, Constant constant) { Header? result; string id; - string? text; string[] segmentsB; string[] segmentsC; int[] i = new int[] { 0 }; WaferSummary waferSummary; List collection = new(); - if (!pages.TryGetValue(headerFileName, out text)) + string? text = GetText(pages, constant); + if (string.IsNullOrEmpty(text)) throw new Exception(); ScanPast(text, i, constant.Date); string date = GetToEOL(text, i); diff --git a/Adaptation/FileHandlers/pcl/Run.cs b/Adaptation/FileHandlers/pcl/Run.cs index f132a51..8935a3d 100644 --- a/Adaptation/FileHandlers/pcl/Run.cs +++ b/Adaptation/FileHandlers/pcl/Run.cs @@ -24,13 +24,13 @@ internal class Run Wafers = wafers; } - private static ReadOnlyCollection GetLastWaferForEachSlot(ReadOnlyDictionary pages, Constant constant, string headerFileName, Header header) + private static ReadOnlyCollection GetLastWaferForEachSlot(ReadOnlyDictionary pages, Constant constant, Header header) { List results = new(); string id; Wafer wafer; ReadOnlyCollection? wafers; - ReadOnlyDictionary> keyValuePairs = Wafer.Get(pages, constant, headerFileName); + ReadOnlyDictionary> keyValuePairs = Wafer.Get(pages, constant); ReadOnlyCollection waferIds = GetWaferIds(header); for (int i = 0; i < waferIds.Count; i++) { @@ -123,13 +123,12 @@ internal class Run { Run? result; Constant constant = new(); - string headerFileName = pages.ElementAt(pages.Count - 1).Key; - Header? header = Header.Get(pages, constant, headerFileName); + Header? header = Header.Get(pages, constant); if (header is null) result = null; else { - ReadOnlyCollection wafers = GetLastWaferForEachSlot(pages, constant, headerFileName, header); + ReadOnlyCollection wafers = GetLastWaferForEachSlot(pages, constant, header); result = new(header, wafers); WriteJson(logistics, fileInfoCollection, result); WriteCommaSeparatedValues(logistics, result); diff --git a/Adaptation/FileHandlers/pcl/Wafer.cs b/Adaptation/FileHandlers/pcl/Wafer.cs index 87a422d..91758db 100644 --- a/Adaptation/FileHandlers/pcl/Wafer.cs +++ b/Adaptation/FileHandlers/pcl/Wafer.cs @@ -114,7 +114,7 @@ public class Wafer public string Thruput { get; } public string Recipe { get; } - internal static ReadOnlyDictionary> Get(ReadOnlyDictionary pages, Constant constant, string headerFileName) + internal static ReadOnlyDictionary> Get(ReadOnlyDictionary pages, Constant constant) { Dictionary> results = new(); Wafer wafer; @@ -124,15 +124,11 @@ public class Wafer Dictionary> keyValuePairs = new(); foreach (KeyValuePair keyValuePair in pages) { - if (keyValuePair.Key == headerFileName) - continue; - if (!pages.ContainsKey(keyValuePair.Key)) - throw new Exception(); i[0] = 0; stringList = new(); if (!pages.TryGetValue(keyValuePair.Key, out text)) throw new Exception(); - if (string.IsNullOrEmpty(text) || !text.Contains(constant.Id)) + if (string.IsNullOrEmpty(text) || !text.Contains(constant.Id) || text.Contains(constant.Statistics) || text.Contains(constant.DatabaseId)) continue; Header.ScanPast(text, i, constant.Date); string date = Header.GetToEOL(text, i); diff --git a/Adaptation/FileHandlers/pdsf/Constant.cs b/Adaptation/FileHandlers/pdsf/Constant.cs index 714e506..269d6df 100644 --- a/Adaptation/FileHandlers/pdsf/Constant.cs +++ b/Adaptation/FileHandlers/pdsf/Constant.cs @@ -9,5 +9,7 @@ internal class Constant public string Date { get; } = "Date:"; public string StdDev { get; } = "Std Dev:"; public string Average { get; } = "Average:"; + public string Statistics { get; } = "Statistics:"; + public string DatabaseId { get; } = "Database ID:"; } \ No newline at end of file diff --git a/Adaptation/FileHandlers/pdsf/Header.cs b/Adaptation/FileHandlers/pdsf/Header.cs index 42c4783..9c29e44 100644 --- a/Adaptation/FileHandlers/pdsf/Header.cs +++ b/Adaptation/FileHandlers/pdsf/Header.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Text.Json.Serialization; namespace Adaptation.FileHandlers.pdsf; @@ -215,17 +216,35 @@ public class Header return GetBefore(text, i, "\n", false); } - internal static Header Get(ReadOnlyDictionary pages, Constant constant, string headerFileName) + private static string? GetText(ReadOnlyDictionary pages, Constant constant) + { + string? text; + string? headerFileName = null; + foreach (KeyValuePair keyValuePair in pages) + { + if (!pages.TryGetValue(keyValuePair.Key, out text)) + throw new Exception(); + if (!text.Contains(constant.Statistics)) + continue; + headerFileName = keyValuePair.Key; + } + headerFileName ??= pages.Count == 0 ? string.Empty : pages.ElementAt(pages.Count - 1).Key; + if (pages.Count == 0 || !pages.TryGetValue(headerFileName, out text)) + text = null; + return text; + } + + internal static Header Get(ReadOnlyDictionary pages, Constant constant) { Header? result; string id; - string? text; string[] segmentsB; string[] segmentsC; int[] i = new int[] { 0 }; WaferSummary waferSummary; List collection = new(); - if (!pages.TryGetValue(headerFileName, out text)) + string? text = GetText(pages, constant); + if (string.IsNullOrEmpty(text)) throw new Exception(); ScanPast(text, i, constant.Date); string date = GetToEOL(text, i); diff --git a/Adaptation/FileHandlers/pdsf/Run.cs b/Adaptation/FileHandlers/pdsf/Run.cs index b346a48..286d2c0 100644 --- a/Adaptation/FileHandlers/pdsf/Run.cs +++ b/Adaptation/FileHandlers/pdsf/Run.cs @@ -24,13 +24,13 @@ internal class Run Wafers = wafers; } - private static ReadOnlyCollection GetLastWaferForEachSlot(ReadOnlyDictionary pages, Constant constant, string headerFileName, Header header) + private static ReadOnlyCollection GetLastWaferForEachSlot(ReadOnlyDictionary pages, Constant constant, Header header) { List results = new(); string id; Wafer wafer; ReadOnlyCollection? wafers; - ReadOnlyDictionary> keyValuePairs = Wafer.Get(pages, constant, headerFileName); + ReadOnlyDictionary> keyValuePairs = Wafer.Get(pages, constant); ReadOnlyCollection waferIds = GetWaferIds(header); for (int i = 0; i < waferIds.Count; i++) { @@ -123,13 +123,12 @@ internal class Run { Run? result; Constant constant = new(); - string headerFileName = pages.ElementAt(pages.Count - 1).Key; - Header? header = Header.Get(pages, constant, headerFileName); + Header? header = Header.Get(pages, constant); if (header is null) result = null; else { - ReadOnlyCollection wafers = GetLastWaferForEachSlot(pages, constant, headerFileName, header); + ReadOnlyCollection wafers = GetLastWaferForEachSlot(pages, constant, header); result = new(header, wafers); WriteJson(logistics, fileInfoCollection, result); WriteCommaSeparatedValues(logistics, result); diff --git a/Adaptation/FileHandlers/pdsf/Wafer.cs b/Adaptation/FileHandlers/pdsf/Wafer.cs index a192182..d6100a7 100644 --- a/Adaptation/FileHandlers/pdsf/Wafer.cs +++ b/Adaptation/FileHandlers/pdsf/Wafer.cs @@ -114,7 +114,7 @@ public class Wafer public string Thruput { get; } public string Recipe { get; } - internal static ReadOnlyDictionary> Get(ReadOnlyDictionary pages, Constant constant, string headerFileName) + internal static ReadOnlyDictionary> Get(ReadOnlyDictionary pages, Constant constant) { Dictionary> results = new(); Wafer wafer; @@ -124,10 +124,12 @@ public class Wafer Dictionary> keyValuePairs = new(); foreach (KeyValuePair keyValuePair in pages) { - if (keyValuePair.Key == headerFileName) - continue; - if (!pages.ContainsKey(keyValuePair.Key)) + i[0] = 0; + stringList = new(); + if (!pages.TryGetValue(keyValuePair.Key, out text)) throw new Exception(); + if (string.IsNullOrEmpty(text) || !text.Contains(constant.Id) || text.Contains(constant.Statistics) || text.Contains(constant.DatabaseId)) + continue; i[0] = 0; stringList = new(); if (!pages.TryGetValue(keyValuePair.Key, out text))