Refactored Run and Wafer classes for improved wafer retrieval logic

This commit is contained in:
2025-09-02 10:19:53 -07:00
parent e011bf8e37
commit f717c6cf91
3 changed files with 36 additions and 31 deletions

View File

@ -15,14 +15,36 @@ namespace Adaptation.FileHandlers.pcl;
internal class Run
{
public Header Header { get; }
public ReadOnlyCollection<Wafer> Wafers { get; }
public Run(Header header, ReadOnlyCollection<Wafer> wafers)
{
Header = header;
Wafers = wafers;
}
public Header Header { get; }
public ReadOnlyCollection<Wafer> Wafers { get; }
private static ReadOnlyCollection<Wafer> GetLastWaferForEachSlot(ReadOnlyDictionary<string, string> pages, Constant constant, string headerFileName, Header header)
{
List<Wafer> results = new();
string id;
Wafer wafer;
ReadOnlyCollection<Wafer>? wafers;
ReadOnlyDictionary<string, ReadOnlyCollection<Wafer>> keyValuePairs = Wafer.Get(pages, constant, headerFileName);
ReadOnlyCollection<string> waferIds = GetWaferIds(header);
for (int i = 0; i < waferIds.Count; i++)
{
id = waferIds[i];
if (!keyValuePairs.TryGetValue(id, out wafers) || wafers.Count == 0)
wafer = Wafer.Get(id);
else
wafer = (from l in wafers where l.Recipe == header.Recipe select l).Last();
if (wafer is null)
break;
results.Add(wafer);
}
return results.AsReadOnly();
}
private static void WriteJson(Logistics logistics, List<FileInfo> fileInfoCollection, Run result)
{
@ -107,9 +129,7 @@ internal class Run
result = null;
else
{
ReadOnlyCollection<string> waferIds = GetWaferIds(header);
ReadOnlyDictionary<string, Wafer> keyValuePairs = Wafer.Get(pages, constant, headerFileName, header);
ReadOnlyCollection<Wafer> wafers = Wafer.Get(waferIds, keyValuePairs);
ReadOnlyCollection<Wafer> wafers = GetLastWaferForEachSlot(pages, constant, headerFileName, header);
result = new(header, wafers);
WriteJson(logistics, fileInfoCollection, result);
WriteCommaSeparatedValues(logistics, result);

View File

@ -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;
@ -46,7 +47,7 @@ public class Wafer
Recipe = recipe;
}
private static Wafer? Get(string id) =>
internal static Wafer Get(string id) =>
new(date: string.Empty,
id: id,
comments: string.Empty,
@ -113,13 +114,14 @@ public class Wafer
public string Thruput { get; }
public string Recipe { get; }
internal static ReadOnlyDictionary<string, Wafer> Get(ReadOnlyDictionary<string, string> pages, Constant constant, string headerFileName, Header header)
internal static ReadOnlyDictionary<string, ReadOnlyCollection<Wafer>> Get(ReadOnlyDictionary<string, string> pages, Constant constant, string headerFileName)
{
Dictionary<string, Wafer> results = new();
Dictionary<string, ReadOnlyCollection<Wafer>> results = new();
Wafer wafer;
string? text;
List<string> stringList;
int[] i = new int[] { 0 };
Dictionary<string, List<Wafer>> keyValuePairs = new();
foreach (KeyValuePair<string, string> keyValuePair in pages)
{
if (keyValuePair.Key == headerFileName)
@ -139,8 +141,6 @@ public class Wafer
if (id.Length > 5)
id = string.Concat(id.Substring(0, 5), "... - ***");
id = id.Replace("*", "");
if (results.ContainsKey(id))
continue;
Header.ScanPast(text, i, "Comments:");
string comments = Header.GetToEOL(text, i);
Header.ScanPast(text, i, "Sort:");
@ -190,8 +190,6 @@ public class Wafer
string thruput = Header.GetToEOL(text, i);
Header.ScanPast(text, i, "Recipe ID:");
string recipe = Header.GetToEOL(text, i);
if (recipe != header.Recipe)
continue;
wafer = new(date: date,
id: id,
comments: comments,
@ -224,28 +222,15 @@ public class Wafer
hazeRng: hazeRng,
thruput: thruput,
recipe: recipe);
results.Add(id, wafer);
if (!keyValuePairs.ContainsKey(id))
keyValuePairs.Add(id, new List<Wafer>());
keyValuePairs[id].Add(wafer);
}
foreach (KeyValuePair<string, List<Wafer>> keyValuePair in keyValuePairs)
results.Add(keyValuePair.Key, keyValuePair.Value.AsReadOnly());
return new(results);
}
internal static ReadOnlyCollection<Wafer> Get(ReadOnlyCollection<string> waferIds, ReadOnlyDictionary<string, Wafer> keyValuePairs)
{
List<Wafer> results = new();
string id;
Wafer? wafer;
for (int i = 0; i < waferIds.Count; i++)
{
id = waferIds[i];
if (!keyValuePairs.TryGetValue(id, out wafer))
wafer = Get(id);
if (wafer is null)
break;
results.Add(wafer);
}
return results.AsReadOnly();
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]

View File

@ -903,7 +903,7 @@ internal class ProcessDataStandardFormat
}
foreach (KeyValuePair<string, List<string>> keyValuePair in results)
{
if (body.Count < 3)
if (body.Count < 2)
break;
if (keyValuePair.Value.Count != body.Count)
continue;