Switch to csv to work with AUC EAF FileReader

This commit is contained in:
Mike Phares 2025-01-17 16:43:34 -07:00
parent 119e2bd535
commit 7b993aaa94
3 changed files with 16 additions and 29 deletions

View File

@ -9,6 +9,7 @@ internal class Row
public Row(Run run, int i) public Row(Run run, int i)
{ {
Index = i;
Operator = run.Header.Operator; Operator = run.Header.Operator;
StartVoltage = run.Header.StartVoltage; StartVoltage = run.Header.StartVoltage;
Wafer = run.Header.Wafer; Wafer = run.Header.Wafer;
@ -117,6 +118,8 @@ internal class Row
TopY = run.Points[i].TopY; TopY = run.Points[i].TopY;
} }
public int Index { get; }
//
public string Operator { get; } public string Operator { get; }
public string StartVoltage { get; } public string StartVoltage { get; }
public string Wafer { get; } public string Wafer { get; }

View File

@ -49,17 +49,20 @@ internal class Run
fileInfoCollection.Add(fileInfo); fileInfoCollection.Add(fileInfo);
} }
private static ReadOnlyCollection<string> GetLines(JsonElement[]? jsonElements) private static ReadOnlyCollection<string> GetLines(Logistics logistics, JsonElement[]? jsonElements)
{ {
List<string> results = new(); List<string> results = new();
int columns = 0; int columns = 0;
StringBuilder stringBuilder = new(); StringBuilder stringBuilder = new();
results.Add($"Count,{jsonElements?.Length}");
results.Add($"{nameof(logistics.Sequence)},{logistics.Sequence}");
results.Add($"{nameof(logistics.MesEntity)},\"{logistics.MesEntity}\"");
for (int i = 0; i < jsonElements?.Length;) for (int i = 0; i < jsonElements?.Length;)
{ {
foreach (JsonProperty jsonProperty in jsonElements[0].EnumerateObject()) foreach (JsonProperty jsonProperty in jsonElements[0].EnumerateObject())
{ {
columns += 1; columns += 1;
_ = stringBuilder.Append('"').Append(jsonProperty.Name).Append('"').Append('\t'); _ = stringBuilder.Append('"').Append(jsonProperty.Name).Append('"').Append(',');
} }
break; break;
} }
@ -72,11 +75,11 @@ internal class Run
foreach (JsonProperty jsonProperty in jsonElements[i].EnumerateObject()) foreach (JsonProperty jsonProperty in jsonElements[i].EnumerateObject())
{ {
if (jsonProperty.Value.ValueKind == JsonValueKind.Object) if (jsonProperty.Value.ValueKind == JsonValueKind.Object)
_ = stringBuilder.Append('\t'); _ = stringBuilder.Append(',');
else if (jsonProperty.Value.ValueKind != JsonValueKind.String) else if (jsonProperty.Value.ValueKind != JsonValueKind.String)
_ = stringBuilder.Append(jsonProperty.Value).Append('\t'); _ = stringBuilder.Append(jsonProperty.Value).Append(',');
else else
_ = stringBuilder.Append('"').Append(jsonProperty.Value).Append('"').Append('\t'); _ = stringBuilder.Append('"').Append(jsonProperty.Value).Append('"').Append(',');
} }
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1); _ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
results.Add(stringBuilder.ToString()); results.Add(stringBuilder.ToString());
@ -84,14 +87,10 @@ internal class Run
return results.AsReadOnly(); return results.AsReadOnly();
} }
private static ReadOnlyCollection<string> GetLines(JsonElement jsonElement) => private static void WriteCommaSeparatedValues(Logistics logistics, Run run)
GetLines(new JsonElement[] { jsonElement });
private static void WriteTabSeparatedValues(Logistics logistics, List<FileInfo> fileInfoCollection, Run run)
{ {
List<Row> results = new(); List<Row> results = new();
Row row; Row row;
FileInfo fileInfo = new($"{logistics.ReportFullPath}.tsv");
for (int i = 0; i < run.Points.Count; i++) for (int i = 0; i < run.Points.Count; i++)
{ {
row = new(run, i); row = new(run, i);
@ -99,16 +98,8 @@ internal class Run
} }
string json = JsonSerializer.Serialize(results); string json = JsonSerializer.Serialize(results);
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json); JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
ReadOnlyCollection<string> lines = GetLines(jsonElements); ReadOnlyCollection<string> lines = GetLines(logistics, jsonElements);
File.WriteAllText(fileInfo.FullName, string.Join(Environment.NewLine, lines)); File.WriteAllText($"{logistics.ReportFullPath}.csv", string.Join(Environment.NewLine, lines));
File.SetLastWriteTime(fileInfo.FullName, logistics.DateTimeFromSequence);
fileInfoCollection.Add(fileInfo);
}
private static void WriteException(Logistics logistics, Exception ex)
{
FileInfo fileInfo = new($"{logistics.ReportFullPath}.{nameof(Exception)}.txt");
File.WriteAllText(fileInfo.FullName, $"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
} }
public static Run? Get(Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyCollection<string> collection) public static Run? Get(Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyCollection<string> collection)
@ -137,14 +128,7 @@ internal class Run
{ {
result = new(header, summary, points); result = new(header, summary, points);
WriteJson(logistics, fileInfoCollection, result); WriteJson(logistics, fileInfoCollection, result);
try WriteCommaSeparatedValues(logistics, result);
{
WriteTabSeparatedValues(logistics, fileInfoCollection, result);
}
catch (Exception ex)
{
WriteException(logistics, ex);
}
} }
} }
} }

View File

@ -88,7 +88,7 @@ public partial class FileRead : FileReaderHandler, ISMTP
try try
{ {
extractResults = _FileRead.GetExtractResult(reportFullPath, eventName); extractResults = _FileRead.GetExtractResult(reportFullPath, eventName);
if (extractResults.Item3.Length == 0 && !string.IsNullOrEmpty(extractResults.Item1) && !extractResults.Item1.Contains(Environment.NewLine)) if (extractResults.Item3.Length == 0 && !string.IsNullOrEmpty(extractResults.Item1) && !extractResults.Item1.Contains("LOGISTICS_1"))
throw new Exception(extractResults.Item1); throw new Exception(extractResults.Item1);
TriggerEvents(extractResults); TriggerEvents(extractResults);
_FileRead.Move(extractResults); _FileRead.Move(extractResults);