From d57be048e728e023aade8b2efd59737b5c244cfa Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Thu, 10 Jul 2025 13:07:42 -0700 Subject: [PATCH] SECS/GEM log-to-trace (Day-Helper-2025-07-10) java-script-object-notation-to-reactor (Day-Helper-2025-07-09) Dynamic extension for (Day-Helper-2025-07-01) --- .vscode/launch.json | 47 +++++-- ADO2025/PI6/Helper-2025-07-01.cs | 200 ++++++++++++++++++++------ ADO2025/PI6/Helper-2025-07-09.cs | 234 +++++++++++++++++++++++++++++++ ADO2025/PI6/Helper-2025-07-10.cs | 98 +++++++++++++ Day/HelperDay.cs | 4 + Day/Q42023/Helper-2023-11-30.cs | 9 +- 6 files changed, 532 insertions(+), 60 deletions(-) create mode 100644 ADO2025/PI6/Helper-2025-07-09.cs create mode 100644 ADO2025/PI6/Helper-2025-07-10.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 3e3e421..2354205 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,41 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "D:/ProgramData/EC_Characterization_Si/Dummy/DEP08CEPIEPSILON/Log", + "Day-Helper-2025-07-10", + "R*", + "EAF_INFO*", + "s", + "X", + "D:/ProgramData/EC_Characterization_Si/Dummy/DEP08CEPIEPSILON/JavaScriptObjectNotation", + "Day-Helper-2025-07-09", + "*.json", + "987654321", + ".agg", + "id93,vp93,ProcessState,id154,vp154,SystemState,id78,vp78,LL1State,id83,vp83,LL2State,id176,vp176,TotalWaferCount,id80,vp80,LL1Lotid,id85,vp85,LL2Lotid,id153,vp153,PPSTEPNAME,id221,vp221,LeftDefaultRecipe,id222,vp222,RightDefaultRecipe,id223,vp223,RecipeCompleteMsg", + "D:/ProgramData/EC_Characterization_Si/Dummy/DEP08CEPIEPSILON/Reactor", + "s", + "X", + "D:/ProgramData/EC_Characterization_Si/Dummy/DEP08CEPIEPSILON/PollPath", + "Day-Helper-2025-07-01", + "*.pdsf", + "987654321", + "Time", + ".json", + "id12~CenterTemp,id13~CenterSetpt,id15~FrontTemp,id153~PPSTEPNAME,id154~SystemState,id16~FrontSetpt,id172~LVC1Ratio,id173~LVC1Carrier,id176~TotalWaferCount,i-d-1-7-8~TIME,id18~SideTemp,id183~SCRDrive4,id19~SideSetpt,id193~SCRLOAD4,id21~RearTemp,id22~RearSetpt,id221~LeftDefaultRecipe,id222~RightDefaultRecipe,id223~RecipeCompleteMsg,id25~N2H2Setpt,id26~N2H2Flow,id27~HCLSetpt,id28~HCLFlow,id29~HCLHISetpt,id30~HCLHIFlow,id37~NSRCSetpt,id38~NSRCFlow,id39~NDILSetpt,id40~NDILFlow,id41~NINJSetpt,id42~NINJFlow,id57~LVC1Setpt,id58~LVC1Flow,id61~ROTSetpt,id62~ROTSpeed,id78~LL1State,id79~LL1Init,id80~LL1Lotid,id81~LL1WafersIn,id82~LL1WfrCnt,id83~LL2State,id84~LL2Init,id85~LL2Lotid,id86~LL2WafersIn,id87~LL2WfrCnt,id93~ProcessState,vp93~ProcessState,vp154~SystemState,vp78~LL1State,vp83~LL2State,vp176~TotalWaferCount,vp80~LL1Lotid,vp85~LL2Lotid,vp153~PPSTEPNAME,vp221~LeftDefaultRecipe,vp222~RightDefaultRecipe,vp223~RecipeCompleteMsg", + "D:/ProgramData/EC_Characterization_Si/Dummy/DEP08CEPIEPSILON/JavaScriptObjectNotation", + "D:/ProgramData/EC_Characterization_Si/Dummy/DEP08CEPIEPSILON/Markdown", + "D:/ProgramData/EC_Characterization_Si/Dummy/DEP08CEPIEPSILON/KeyValuePairs", + "654321", + "s", + "s", + "X", + "D:/ProgramData/EC_Characterization_Si/Dummy/DEP08CEPIEPSILON/R55", + "Day-Helper-2023-11-30", + "yyMMddhhmmssfff", + "\"vp154\"", "s", "X", "V:/Tmp/Phares/Pictures/2023 TI2023.6 Fall Samsung", @@ -21,18 +56,6 @@ "0.259594,0.460161,0.1642,0.279605~0.45477,0.489035,0.195175,0.32383~0.328993,0.446263,0.0379464,0.0459656", "9", "x-825511723~x-444522128~831410304", - "s", - "X", - "\\\\mesfs.infineon.com\\EC_APC\\Production\\Traces\\DEP08CEPIEPSILON\\PollPath", - "Day-Helper-2025-07-01", - "*.pdsf", - "654321", - "Time", - "id12~CenterTemp,id13~CenterSetpt,id15~FrontTemp,id153~PPSTEPNAME,id154~SystemState,id16~FrontSetpt,id172~LVC1Ratio,id173~LVC1Carrier,id176~TotalWaferCount,i-d-1-7-8~TIME,id18~SideTemp,id183~SCRDrive4,id19~SideSetpt,id193~SCRLOAD4,id21~RearTemp,id22~RearSetpt,id221~LeftDefaultRecipe,id222~RightDefaultRecipe,id223~RecipeCompleteMsg,id25~N2H2Setpt,id26~N2H2Flow,id27~HCLSetpt,id28~HCLFlow,id29~HCLHISetpt,id30~HCLHIFlow,id37~NSRCSetpt,id38~NSRCFlow,id39~NDILSetpt,id40~NDILFlow,id41~NINJSetpt,id42~NINJFlow,id57~LVC1Setpt,id58~LVC1Flow,id61~ROTSetpt,id62~ROTSpeed,id78~LL1State,id79~LL1Init,id80~LL1Lotid,id81~LL1WafersIn,id82~LL1WfrCnt,id83~LL2State,id84~LL2Init,id85~LL2Lotid,id86~LL2WafersIn,id87~LL2WfrCnt,id93~ProcessState", - "\\\\mesfs.infineon.com\\EC_APC\\Production\\Traces\\DEP08CEPIEPSILON\\Markdown", - "\\\\mesfs.infineon.com\\EC_APC\\Production\\Traces\\DEP08CEPIEPSILON\\KeyValuePairs", - "\\\\mesfs.infineon.com\\EC_APC\\Production\\Traces\\DEP08CEPIEPSILON\\JavaScriptObjectNotation", - "s", "X", "F:/0-ISO-A", "Day-Helper-2025-06-28", diff --git a/ADO2025/PI6/Helper-2025-07-01.cs b/ADO2025/PI6/Helper-2025-07-01.cs index a474eb2..abeb462 100644 --- a/ADO2025/PI6/Helper-2025-07-01.cs +++ b/ADO2025/PI6/Helper-2025-07-01.cs @@ -14,6 +14,11 @@ internal static partial class Helper20250701 { internal partial class JsonElementSourceGenerationContext : JsonSerializerContext { } + [JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] + [JsonSerializable(typeof(ReadOnlyDictionary>))] + internal partial class ReadOnlyDictionaryStringReadOnlyDictionaryStringStringSourceGenerationContext : JsonSerializerContext { + } + internal static void ProcessDataStandardFormatTo(ILogger logger, List args) { logger.LogInformation(args[0]); logger.LogInformation(args[1]); @@ -22,24 +27,27 @@ internal static partial class Helper20250701 { logger.LogInformation(args[4]); logger.LogInformation(args[5]); logger.LogInformation(args[6]); + logger.LogInformation(args[7]); string[] segments; + string extension = args[5]; string timeColumn = args[4]; string searchPattern = args[2]; int sizeFilter = int.Parse(args[3]); - string[] columns = args[5].Split(','); + string[] columns = args[6].Split(','); Dictionary columnMapping = []; string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]); - string destinationDirectory = Path.GetFullPath(args[6].Split('~')[0]); + string destinationDirectory = Path.GetFullPath(args[7].Split('~')[0]); foreach (string column in columns) { segments = column.Split('~'); columnMapping.Add(segments[0], segments[1]); } string[] directories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly); - ProcessDataStandardFormatTo(logger, sourceDirectory, searchPattern, sizeFilter, timeColumn, columnMapping, destinationDirectory, directories); + ProcessDataStandardFormatTo(logger, sourceDirectory, searchPattern, sizeFilter, timeColumn, extension, columnMapping.AsReadOnly(), destinationDirectory, directories.AsReadOnly()); Helpers.HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory); } - private static void ProcessDataStandardFormatTo(ILogger logger, string sourceDirectory, string searchPattern, int sizeFilter, string timeColumn, Dictionary columnMapping, string destinationDirectory, string[] directories) { + private static void ProcessDataStandardFormatTo(ILogger logger, string sourceDirectory, string searchPattern, int sizeFilter, string timeColumn, string extension, ReadOnlyDictionary columnMapping, string destinationDirectory, ReadOnlyCollection directories) { + string text; string? json; string[] files; string markdown; @@ -51,7 +59,7 @@ internal static partial class Helper20250701 { string directoryName; string checkDirectory; foreach (string directory in directories) { - if (Path.GetFileName(directory).Contains('-')) { + if (sizeFilter < 987654321 && Path.GetFileName(directory).Contains('-')) { continue; } files = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly); @@ -77,41 +85,49 @@ internal static partial class Helper20250701 { if (!Directory.Exists(checkDirectory)) { _ = Directory.CreateDirectory(checkDirectory); } - checkFile = Path.Combine(checkDirectory, $"{fileInfo.Name}.md"); + checkFile = Path.Combine(checkDirectory, $"{fileInfo.Name}{extension}"); if (File.Exists(checkFile)) { continue; } - collections = GetMarkdown(logger, timeColumn, columnMapping, file, fileInfo.Name); - if (string.IsNullOrEmpty(collections)) { - logger.LogWarning("collections is null"); + if (extension == ".md") { + collections = GetMarkdown(logger, timeColumn, columnMapping, file, fileInfo.Name); + if (string.IsNullOrEmpty(collections)) { + logger.LogWarning("collections is null"); + continue; + } + text = collections; + } else if (extension == ".pipe.md") { + json = GetJavaScriptObjectNotation(logger, file); + if (string.IsNullOrEmpty(json)) { + logger.LogWarning("json is null"); + continue; + } + pipeTable = GetPipeTable(logger, json); + if (string.IsNullOrEmpty(pipeTable)) { + logger.LogWarning("pipeTable is null"); + continue; + } + markdown = $"# {fileInfo.Name}{Environment.NewLine}{Environment.NewLine}{pipeTable}{Environment.NewLine}"; + text = markdown; + } else if (extension == ".json") { + json = GetJavaScriptObjectNotation(logger, file); + if (string.IsNullOrEmpty(json)) { + logger.LogWarning("json is null"); + continue; + } + text = json; + } else { + logger.LogWarning("{extension} is not mapped!", extension); continue; } - File.WriteAllText(checkFile, collections); - File.SetLastWriteTime(checkFile, fileInfo.LastAccessTime); - if (!string.IsNullOrEmpty(destinationDirectory)) { - continue; - } - json = GetJavaScriptObjectNotation(logger, file); - if (string.IsNullOrEmpty(json)) { - logger.LogWarning("json is null"); - continue; - } - File.WriteAllText($"{checkFile}.md", json); - File.SetLastWriteTime($"{checkFile}.md", fileInfo.LastAccessTime); - pipeTable = GetPipeTable(logger, json); - if (string.IsNullOrEmpty(pipeTable)) { - logger.LogWarning("pipeTable is null"); - continue; - } - markdown = $"# {fileInfo.Name}{Environment.NewLine}{Environment.NewLine}{pipeTable}{Environment.NewLine}"; - File.WriteAllText($"{checkFile}.md", markdown); - File.SetLastWriteTime($"{checkFile}.md", fileInfo.LastAccessTime); + File.WriteAllText(checkFile, text); + File.SetLastWriteTime(checkFile, fileInfo.LastWriteTime); logger.LogInformation("<{checkFile}> was written", checkFile); } } } - private static string? GetMarkdown(ILogger logger, string timeColumn, Dictionary columnMapping, string file, string name) { + private static string? GetMarkdown(ILogger logger, string timeColumn, ReadOnlyDictionary columnMapping, string file, string name) { string? result = null; string[] lines = File.ReadAllLines(file); int? columnTitlesLine = GetProcessDataStandardFormatColumnTitlesLine(lines); @@ -173,7 +189,7 @@ internal static partial class Helper20250701 { return results.AsReadOnly(); } - private static string? GetMarkdown(string timeColumn, Dictionary columnMapping, string name, string[] lines, int? columnTitlesLine) { + private static string? GetMarkdown(string timeColumn, ReadOnlyDictionary columnMapping, string name, string[] lines, int? columnTitlesLine) { string? result; List charts = []; List results = []; @@ -239,42 +255,139 @@ internal static partial class Helper20250701 { if (lines.Length < columnTitlesLine.Value + 1) { logger.LogWarning("<{lines}>(s)", lines.Length); } else { - result = GetJavaScriptObjectNotation(columnTitlesLine.Value, [], lines); + result = GetJavaScriptObjectNotation(columnTitlesLine.Value, lines); } } return result; } - private static string GetJavaScriptObjectNotation(int columnTitlesLine, string[] columns, string[] lines) { + private static string GetJavaScriptObjectNotation(int columnTitlesLine, string[] lines) { #pragma warning disable CA1845, IDE0057 - string result = "[\n"; - string line; + string result; + string record; string value; string[] segments; - if (columns.Length == 0) { - columns = lines[columnTitlesLine].Split('\t'); - } + string? json = null; + List records = []; + ReadOnlyCollection? footerLines = null; + string[] columns = lines[columnTitlesLine].Split('\t'); for (int i = columnTitlesLine + 1; i < lines.Length; i++) { if (lines[i].StartsWith("NUM_DATA_ROWS")) { + footerLines = GetFooterLines(lines, i); break; } - line = "{"; + record = "{"; segments = lines[i].Split('\t'); if (segments.Length > columns.Length) { continue; } for (int c = 0; c < segments.Length; c++) { value = segments[c].Replace("\\", "\\\\").Replace("\"", "\\\""); - line += '"' + columns[c].Trim('"') + '"' + ':' + '"' + value + '"' + ','; + record += string.Concat('"', columns[c].Trim('"'), '"', ':', '"', value, '"', ','); } - line = line.Substring(0, line.Length - 1) + '}' + ',' + '\n'; - result += line; + record = string.Concat(record.Substring(0, record.Length - 1), '}'); + records.Add(record); } - result = result.Substring(0, result.Length - 2) + ']'; + if (footerLines is not null && footerLines.Count > 0) { + ReadOnlyDictionary footerKeyValuePairs = GetFooterKeyValuePairs(footerLines); + ReadOnlyDictionary> logisticKeyValuePairs = GetLogisticKeyValuePairs(footerLines, footerKeyValuePairs); + json = JsonSerializer.Serialize(logisticKeyValuePairs, ReadOnlyDictionaryStringReadOnlyDictionaryStringStringSourceGenerationContext.Default.ReadOnlyDictionaryStringReadOnlyDictionaryStringString); + } + string footerText = string.IsNullOrEmpty(json) || json == "{}" ? string.Empty : $",{Environment.NewLine}\"ProcessDataStandardFormat\":{Environment.NewLine}{json}"; + result = string.Concat( + '{', + Environment.NewLine, + '"', + "Count", + '"', + ": ", + records.Count, + ',', + Environment.NewLine, + '"', + "Records", + '"', + ": ", + Environment.NewLine, + '[', + Environment.NewLine, + string.Join($",{Environment.NewLine}", records), + Environment.NewLine, + ']', + footerText, + '}'); return result; #pragma warning restore CA1845, IDE0057 } + private static ReadOnlyCollection GetFooterLines(string[] lines, int i) { + List results = []; + for (int j = i; j < lines.Length; j++) { + results.Add(lines[j]); + if (lines[j].StartsWith("END_HEADER")) + break; + } + return results.AsReadOnly(); + } + + private static ReadOnlyDictionary GetFooterKeyValuePairs(ReadOnlyCollection footerLines) { + Dictionary results = []; + string[] segments; + foreach (string footerLine in footerLines) { + segments = footerLine.Split('\t'); + if (segments.Length != 2 || string.IsNullOrEmpty(segments[1].Trim())) { + continue; + } + if (segments[1].Contains(';')) { + continue; + } else { + results.Add(segments[0], segments[1]); + } + } + return results.AsReadOnly(); + } + + private static ReadOnlyDictionary> GetLogisticKeyValuePairs(ReadOnlyCollection footerLines, ReadOnlyDictionary footerKeyValuePairs) { + Dictionary> results = []; + string[] segments; + string[] subSegments; + string[] subSubSegments; + Dictionary? keyValue; + results.Add("Footer", footerKeyValuePairs); + Dictionary> keyValuePairs = []; + foreach (string footerLine in footerLines) { + segments = footerLine.Split('\t'); + if (segments.Length != 2 || string.IsNullOrEmpty(segments[1].Trim())) { + continue; + } + if (!segments[1].Contains(';') || !segments[1].Contains('=')) { + continue; + } else { + subSegments = segments[1].Split(';'); + if (subSegments.Length < 1) { + continue; + } + if (!keyValuePairs.TryGetValue(segments[0], out keyValue)) { + keyValuePairs.Add(segments[0], []); + if (!keyValuePairs.TryGetValue(segments[0], out keyValue)) { + throw new Exception(); + } + } + foreach (string segment in subSegments) { + subSubSegments = segment.Split('='); + if (subSubSegments.Length != 2) { + continue; + } + keyValue.Add(subSubSegments[0], subSubSegments[1]); + } + } + } + foreach (KeyValuePair> keyValuePair in keyValuePairs) { + results.Add(keyValuePair.Key, keyValuePair.Value.AsReadOnly()); + } + return results.AsReadOnly(); + } + private static string? GetPipeTable(ILogger logger, string json) { string? result = null; string? value; @@ -310,4 +423,5 @@ internal static partial class Helper20250701 { } return result; } + } \ No newline at end of file diff --git a/ADO2025/PI6/Helper-2025-07-09.cs b/ADO2025/PI6/Helper-2025-07-09.cs new file mode 100644 index 0000000..336857a --- /dev/null +++ b/ADO2025/PI6/Helper-2025-07-09.cs @@ -0,0 +1,234 @@ +using System.Collections.ObjectModel; +using System.Text.Json; +using System.Text.Json.Serialization; + +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.ADO2025.PI6; + +internal static partial class Helper20250709 { + + // [JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] + // [JsonSerializable(typeof(JsonElement[]))] + // internal partial class Helper20250709JsonElementSourceGenerationContext : JsonSerializerContext { + // } + + [JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] + [JsonSerializable(typeof(Raw))] + private partial class RawSourceGenerationContext : JsonSerializerContext { + } + + private record Raw(int Count, JsonElement[] Records); + + // cspell::disable + private record Reactor([property: JsonPropertyName("id12")] double? Id12, + [property: JsonPropertyName("id13")] double? Id13, + [property: JsonPropertyName("id15")] double? Id15, + [property: JsonPropertyName("id153")] string? Id153, + [property: JsonPropertyName("id154")] long? Id154, + [property: JsonPropertyName("id16")] double? Id16, + [property: JsonPropertyName("id172")] double? Id172, + [property: JsonPropertyName("id173")] double? Id173, + [property: JsonPropertyName("id176")] double? Id176, + [property: JsonPropertyName("id178")] string? Id178, + [property: JsonPropertyName("id18")] double? Id18, + [property: JsonPropertyName("id183")] double? Id183, + [property: JsonPropertyName("id19")] double? Id19, + [property: JsonPropertyName("id193")] double? Id193, + [property: JsonPropertyName("id21")] double? Id21, + [property: JsonPropertyName("id22")] double? Id22, + [property: JsonPropertyName("id221")] string? Id221, + [property: JsonPropertyName("id222")] string? Id222, + [property: JsonPropertyName("id223")] string? Id223, + [property: JsonPropertyName("id25")] double? Id25, + [property: JsonPropertyName("id26")] double? Id26, + [property: JsonPropertyName("id27")] double? Id27, + [property: JsonPropertyName("id28")] double? Id28, + [property: JsonPropertyName("id29")] double? Id29, + [property: JsonPropertyName("id30")] double? Id30, + [property: JsonPropertyName("id37")] double? Id37, + [property: JsonPropertyName("id38")] double? Id38, + [property: JsonPropertyName("id39")] double? Id39, + [property: JsonPropertyName("id40")] double? Id40, + [property: JsonPropertyName("id41")] double? Id41, + [property: JsonPropertyName("id42")] double? Id42, + [property: JsonPropertyName("id57")] double? Id57, + [property: JsonPropertyName("id58")] double? Id58, + [property: JsonPropertyName("id61")] double? Id61, + [property: JsonPropertyName("id62")] double? Id62, + [property: JsonPropertyName("id78")] long? Id78, + [property: JsonPropertyName("id79")] long? Id79, + [property: JsonPropertyName("id80")] string? Id80, + [property: JsonPropertyName("id81")] long? Id81, + [property: JsonPropertyName("id82")] long? Id82, + [property: JsonPropertyName("id83")] long? Id83, + [property: JsonPropertyName("id84")] long? Id84, + [property: JsonPropertyName("id85")] string? Id85, + [property: JsonPropertyName("id86")] long? Id86, + [property: JsonPropertyName("id87")] long? Id87, + [property: JsonPropertyName("id93")] long? Id93, + [property: JsonPropertyName("vp93")] long? Vp93, + [property: JsonPropertyName("vp154")] long? Vp154, + [property: JsonPropertyName("vp78")] long? Vp78, + [property: JsonPropertyName("vp83")] long? Vp83, + [property: JsonPropertyName("vp176")] double? Vp176, + [property: JsonPropertyName("vp80")] string? Vp80, + [property: JsonPropertyName("vp85")] string? Vp85, + [property: JsonPropertyName("vp153")] string? Vp153, + [property: JsonPropertyName("vp221")] string? Vp221, + [property: JsonPropertyName("vp222")] string? Vp222, + [property: JsonPropertyName("vp223")] string? Vp223, + [property: JsonPropertyName("YYYYMMDDhhmmsscc")] string? YYYYMMDDhhmmsscc, + [property: JsonPropertyName("CenterTemp")] double? CenterTemp, + [property: JsonPropertyName("CenterSetpt")] double? CenterSetpt, + [property: JsonPropertyName("FrontTemp")] double? FrontTemp, + [property: JsonPropertyName("PPSTEPNAME")] string? PPSTEPNAME, + [property: JsonPropertyName("SystemState")] long? SystemState, + [property: JsonPropertyName("FrontSetpt")] double? FrontSetpt, + [property: JsonPropertyName("LVC1Ratio")] double? LVC1Ratio, + [property: JsonPropertyName("LVC1Carrier")] double? LVC1Carrier, + [property: JsonPropertyName("TotalWaferCount")] double? TotalWaferCount, + [property: JsonPropertyName("TIME")] string? TIME, + [property: JsonPropertyName("SideTemp")] double? SideTemp, + [property: JsonPropertyName("SCRDrive4")] double? SCRDrive4, + [property: JsonPropertyName("SideSetpt")] double? SideSetpt, + [property: JsonPropertyName("SCRLOAD4")] double? SCRLOAD4, + [property: JsonPropertyName("RearTemp")] double? RearTemp, + [property: JsonPropertyName("RearSetpt")] double? RearSetpt, + [property: JsonPropertyName("LeftDefaultRecipe")] string? LeftDefaultRecipe, + [property: JsonPropertyName("RightDefaultRecipe")] string? RightDefaultRecipe, + [property: JsonPropertyName("RecipeCompleteMsg")] string? RecipeCompleteMsg, + [property: JsonPropertyName("N2H2Setpt")] double? N2H2Setpt, + [property: JsonPropertyName("N2H2Flow")] double? N2H2Flow, + [property: JsonPropertyName("HCLSetpt")] double? HCLSetpt, + [property: JsonPropertyName("HCLFlow")] double? HCLFlow, + [property: JsonPropertyName("HCLHISetpt")] double? HCLHISetpt, + [property: JsonPropertyName("HCLHIFlow")] double? HCLHIFlow, + [property: JsonPropertyName("NSRCSetpt")] double? NSRCSetpt, + [property: JsonPropertyName("NSRCFlow")] double? NSRCFlow, + [property: JsonPropertyName("NDILSetpt")] double? NDILSetpt, + [property: JsonPropertyName("NDILFlow")] double? NDILFlow, + [property: JsonPropertyName("NINJSetpt")] double? NINJSetpt, + [property: JsonPropertyName("NINJFlow")] double? NINJFlow, + [property: JsonPropertyName("LVC1Setpt")] double? LVC1Setpt, + [property: JsonPropertyName("LVC1Flow")] double? LVC1Flow, + [property: JsonPropertyName("ROTSetpt")] double? ROTSetpt, + [property: JsonPropertyName("ROTSpeed")] double? ROTSpeed, + [property: JsonPropertyName("LL1State")] long? LL1State, + [property: JsonPropertyName("LL1Init")] long? LL1Init, + [property: JsonPropertyName("LL1Lotid")] string? LL1Lotid, + [property: JsonPropertyName("LL1WafersIn")] long? LL1WafersIn, + [property: JsonPropertyName("LL1WfrCnt")] long? LL1WfrCnt, + [property: JsonPropertyName("LL2State")] long? LL2State, + [property: JsonPropertyName("LL2Init")] long? LL2Init, + [property: JsonPropertyName("LL2Lotid")] string? LL2Lotid, + [property: JsonPropertyName("LL2WafersIn")] long? LL2WafersIn, + [property: JsonPropertyName("LL2WfrCnt")] long? LL2WfrCnt, + [property: JsonPropertyName("ProcessState")] long? ProcessState); + // [property: JsonPropertyName("A_BASIC_TYPE")] string? ABasicType, + // [property: JsonPropertyName("A_INFO")] string? AInfo, + // [property: JsonPropertyName("A_INFO2")] string? AInfo2, + // [property: JsonPropertyName("A_JOBID")] string? AJobid, + // [property: JsonPropertyName("A_LAYER")] string? ALayer, + // [property: JsonPropertyName("A_LAYER2")] string? ALayer2, + // [property: JsonPropertyName("A_MES_ENTITY")] string? AMesEntity, + // [property: JsonPropertyName("A_MID")] string? AMID, + // [property: JsonPropertyName("A_NULL_DATA")] string? ANullData, + // [property: JsonPropertyName("A_PPID")] string? APPID, + // [property: JsonPropertyName("A_PROCESS_JOBID")] string? AProcessJobid, + // [property: JsonPropertyName("A_PRODUCT")] string? AProduct, + // [property: JsonPropertyName("A_SEQUENCE")] string? ASequence, + // [property: JsonPropertyName("A_WAFER_ID")] string? AWaferId, + // [property: JsonPropertyName("A_WAFER_POS")] string? AWaferPos + // cspell::enable, + + [JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, NumberHandling = JsonNumberHandling.AllowReadingFromString)] + [JsonSerializable(typeof(Reactor))] + private partial class ReactorSourceGenerationContext : JsonSerializerContext { + } + + internal static void JavaScriptObjectNotationToReactor(ILogger logger, List args) { + logger.LogInformation(args[0]); + logger.LogInformation(args[1]); + logger.LogInformation(args[2]); + logger.LogInformation(args[3]); + logger.LogInformation(args[4]); + logger.LogInformation(args[5]); + string[] segments; + string extension = args[4]; + string searchPattern = args[2]; + int sizeFilter = int.Parse(args[3]); + string[] columns = args[5].Split(','); + string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]); + string destinationDirectory = Path.GetFullPath(args[6].Split('~')[0]); + string[] directories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly); + JavaScriptObjectNotationTo(logger, sourceDirectory, searchPattern, sizeFilter, extension, columns.AsReadOnly(), destinationDirectory, directories.AsReadOnly()); + Helpers.HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory); + } + + private static void JavaScriptObjectNotationTo(ILogger logger, string sourceDirectory, string searchPattern, int sizeFilter, string extension, ReadOnlyCollection columnMapping, string destinationDirectory, ReadOnlyCollection directories) { + Raw? raw; + string text; + string json; + string[] files; + string checkFile; + Reactor? reactor; + FileInfo fileInfo; + string directoryName; + string checkDirectory; + foreach (string directory in directories) { + if (sizeFilter < 987654321 && Path.GetFileName(directory).Contains('-')) { + continue; + } + files = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly); + foreach (string file in files) { + fileInfo = new(file); + if (fileInfo.LastWriteTime > DateTime.Now.AddSeconds(-5)) { + continue; + } + directoryName = Path.GetFileName(fileInfo.DirectoryName); + if (fileInfo.Length > sizeFilter && !directoryName.StartsWith('Z')) { + checkDirectory = Path.Combine(sourceDirectory, $"Z{directoryName}"); + if (!Directory.Exists(checkDirectory)) { + _ = Directory.CreateDirectory(checkDirectory); + } + checkFile = Path.Combine(checkDirectory, fileInfo.Name); + if (File.Exists(checkFile)) { + continue; + } + File.Move(file, checkFile); + continue; + } + checkDirectory = Path.Combine(destinationDirectory, directoryName); + if (!Directory.Exists(checkDirectory)) { + _ = Directory.CreateDirectory(checkDirectory); + } + checkFile = Path.Combine(checkDirectory, $"{fileInfo.Name}{extension}"); + if (File.Exists(checkFile)) { + continue; + } + if (extension == ".agg") { + json = File.ReadAllText(fileInfo.FullName); + raw = JsonSerializer.Deserialize(json, RawSourceGenerationContext.Default.Raw); + if (raw is null) { + continue; + } + foreach (JsonElement jsonElement in raw.Records) { + try { + reactor = JsonSerializer.Deserialize(jsonElement.ToString().Replace("\"\"", "null"), ReactorSourceGenerationContext.Default.Reactor); + } catch (Exception) { + reactor = null; + } + if (reactor is null) { + continue; + } + if (reactor is null) { + continue; + } + } + } + } + } + } + +} \ No newline at end of file diff --git a/ADO2025/PI6/Helper-2025-07-10.cs b/ADO2025/PI6/Helper-2025-07-10.cs new file mode 100644 index 0000000..a1d4233 --- /dev/null +++ b/ADO2025/PI6/Helper-2025-07-10.cs @@ -0,0 +1,98 @@ +using System.Collections.ObjectModel; +using System.Text.RegularExpressions; + +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.ADO2025.PI6; + +internal static partial class Helper20250710 { + + [GeneratedRegex(@"^(?S[0-9]{1,2})(?F[0-9]{1,2}) W-Bit=(?[01])")] + private static partial Regex StreamFunction(); + + internal static void StripLog(ILogger logger, List args) { + logger.LogInformation(args[0]); + logger.LogInformation(args[1]); + logger.LogInformation(args[2]); + logger.LogInformation(args[3]); + string[] segments; + string searchPattern = args[3]; + string directoryPattern = args[2]; + string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]); + string[] directories = Directory.GetDirectories(sourceDirectory, directoryPattern, SearchOption.TopDirectoryOnly); + LogToTrace(logger, sourceDirectory, searchPattern, directories.AsReadOnly()); + Helpers.HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory); + } + + private static void LogToTrace(ILogger logger, string sourceDirectory, string searchPattern, ReadOnlyCollection directories) { + string text; + string[] lines; + string[] files; + string checkFile; + FileInfo fileInfo; + string directoryName; + const string extension = ".trc"; + foreach (string directory in directories) { + files = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly); + foreach (string file in files) { + fileInfo = new(file); + if (fileInfo.LastWriteTime > DateTime.Now.AddSeconds(-5)) { + continue; + } + directoryName = Path.GetFileName(fileInfo.DirectoryName); + checkFile = Path.Combine(directoryName, $"{fileInfo.Name}{extension}"); + if (File.Exists(checkFile)) { + continue; + } + lines = File.ReadAllLines(fileInfo.FullName); + LogToTrace(logger, fileInfo, lines, checkFile); + } + } + } + + private static void LogToTrace(ILogger logger, FileInfo fileInfo, string[] lines, string checkFile) { + string line; + Match match; + string body; + string[] segments; + string previousLine; + List log = []; + for (int i = 1; i < lines.Length - 1; i++) { + line = lines[i]; + if (!line.StartsWith('S')) { + continue; + } + match = StreamFunction().Match(line); + if (!match.Success) { + continue; + } + segments = lines[i - 1].Split(" "); + if (segments.Length < 2) { + continue; + } + if (!segments[0].Contains(' ')) { + continue; + } + body = GetBody(lines, i, segments[0].Split(' ')); + log.Add($"{segments[0]} {line} ~ {body}"); + } + if (log.Count > 0) { + File.WriteAllText(checkFile, string.Join(Environment.NewLine, log)); + File.SetLastWriteTime(checkFile, fileInfo.LastWriteTime); + logger.LogInformation("<{checkFile}> was written", checkFile); + } + } + + private static string GetBody(string[] lines, int i, string[] segments) { + string result; + List results = []; + for (int j = i + 1; j < lines.Length; j++) { + if (lines[j].StartsWith(segments[0])) + break; + results.Add(lines[j].Trim()); + } + result = string.Join('_', results); + return result; + } + +} \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index 72874b3..fa6be2a 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -177,6 +177,10 @@ internal static class HelperDay ADO2025.PI6.Helper20250701.ProcessDataStandardFormatTo(logger, args); else if (args[1] == "Day-Helper-2025-07-05") ADO2025.PI6.Helper20250705.ExportFaces(logger, args); + else if (args[1] == "Day-Helper-2025-07-09") + ADO2025.PI6.Helper20250709.JavaScriptObjectNotationToReactor(logger, args); + else if (args[1] == "Day-Helper-2025-07-10") + ADO2025.PI6.Helper20250710.StripLog(logger, args); else throw new Exception(appSettings.Company); } diff --git a/Day/Q42023/Helper-2023-11-30.cs b/Day/Q42023/Helper-2023-11-30.cs index b71468e..f82072d 100644 --- a/Day/Q42023/Helper-2023-11-30.cs +++ b/Day/Q42023/Helper-2023-11-30.cs @@ -65,7 +65,7 @@ internal static class Helper20231130 return result; } - private static ReadOnlyCollection GetSystemStateValues(List lines, string[] columns, int keyColumnIndex, ReadOnlyDictionary systemStates) + private static ReadOnlyCollection GetSystemStateValues(List lines, string[] columns, int keyColumnIndex, ReadOnlyDictionary systemStateToNames) { List results = []; string[] values; @@ -79,7 +79,7 @@ internal static class Helper20231130 keyColumnValue = values[keyColumnIndex]; if (string.IsNullOrEmpty(keyColumnValue)) continue; - if (!systemStates.TryGetValue(keyColumnValue, out systemState)) + if (!systemStateToNames.TryGetValue(keyColumnValue, out systemState)) continue; if (results.Contains(systemState)) continue; @@ -106,7 +106,7 @@ internal static class Helper20231130 string missingKeyDirectory = Path.Combine(sourceDirectory, "Missing-Key"); if (!Directory.Exists(missingKeyDirectory)) _ = Directory.CreateDirectory(missingKeyDirectory); - ReadOnlyDictionary systemStates = GetSystemStates(); + ReadOnlyDictionary systemStateToNames = GetSystemStates(); ReadOnlyCollection records = GetRecords(sourceDirectory, timestampFormat); foreach (Record record in records) { @@ -132,7 +132,7 @@ internal static class Helper20231130 continue; } logger.LogInformation("{timestamp} triggered", record.TimeStamp); - systemStateValues = GetSystemStateValues(lines, columns, keyColumnIndex.Value, systemStates); + systemStateValues = GetSystemStateValues(lines, columns, keyColumnIndex.Value, systemStateToNames); if (systemStateValues.Count == 0) { File.Move(record.File, Path.Combine(sourceDirectory, missingKeyDirectory, record.FileName)); @@ -142,7 +142,6 @@ internal static class Helper20231130 systemState = string.Join('-', systemStateValues); checkFileName = Path.Combine(Path.GetDirectoryName(record.File) ?? throw new Exception(), $"{record.Equipment}-{record.TimeStamp}-{systemState}.pdsf"); File.WriteAllLines(checkFileName, lines); - File.Delete(record.File); if (DateTime.TryParseExact(record.TimeStamp, timestampFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) File.SetLastWriteTime(checkFileName, dateTime); }