Back to comma

This commit is contained in:
Mike Phares 2025-02-05 16:30:50 -07:00
parent ef4fdc1023
commit d710fcc195
2 changed files with 16 additions and 13 deletions

View File

@ -33,17 +33,22 @@ 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}\"");
string dateTimeFromSequence = logistics.DateTimeFromSequence.ToString("MM/dd/yyyy hh:mm:ss tt");
for (int i = 0; i < jsonElements?.Length;) for (int i = 0; i < jsonElements?.Length;)
{ {
_ = stringBuilder.Append('"').Append(nameof(logistics.DateTimeFromSequence)).Append('"').Append(',');
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;
} }
@ -53,14 +58,15 @@ internal class Run
for (int i = 0; i < jsonElements?.Length; i++) for (int i = 0; i < jsonElements?.Length; i++)
{ {
_ = stringBuilder.Clear(); _ = stringBuilder.Clear();
_ = stringBuilder.Append('"').Append(dateTimeFromSequence).Append('"').Append(',');
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());
@ -68,11 +74,10 @@ internal class Run
return results.AsReadOnly(); return results.AsReadOnly();
} }
private static void WriteTabSeparatedValues(Logistics logistics, List<FileInfo> fileInfoCollection, Run run) private static void WriteCommaSeparatedValues(Logistics logistics, 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.Wafers.Count; i++) for (int i = 0; i < run.Wafers.Count; i++)
{ {
row = new(run, i); row = new(run, i);
@ -80,10 +85,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 ReadOnlyCollection<string> GetWaferIds(Header header) private static ReadOnlyCollection<string> GetWaferIds(Header header)
@ -109,7 +112,7 @@ internal class Run
ReadOnlyCollection<Wafer> wafers = Wafer.Get(waferIds, keyValuePairs); ReadOnlyCollection<Wafer> wafers = Wafer.Get(waferIds, keyValuePairs);
result = new(header, wafers); result = new(header, wafers);
WriteJson(logistics, fileInfoCollection, result); WriteJson(logistics, fileInfoCollection, result);
WriteTabSeparatedValues(logistics, fileInfoCollection, result); WriteCommaSeparatedValues(logistics, result);
} }
return result; return result;
} }

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);