From 59231ad9e25d1304ad64577f52f7f52b719f9944 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Tue, 24 Sep 2024 10:25:07 -0700 Subject: [PATCH] Sync to Distinct Max Iteration Path --- .vscode/launch.json | 16 ++++------ Day/Q32024/Helper-2024-08-28.cs | 52 ++++++++++++++++++++++++++------- Day/Q32024/Helper-2024-09-11.cs | 37 +++++++++++++++-------- File-Folder-Helper.csproj | 4 +-- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index da2d105..0536e3c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,16 +13,12 @@ "args": [ "s", "X", - "L:/Git/Linux-Ubuntu-Server/etc/nginx/include", - "Day-Helper-2024-09-16", - "*.conf", - "L:/Git/Linux-Ubuntu-Server/etc/nginx/sites-available/default", - "include /etc/nginx/include/", - "proxy_pass", - "666", - "777", - "888", - "999" + "D:/5-Other-Small/Kanban-messa010ec/Kanban/Work-Items", + "Day-Helper-2024-09-11", + "*.json", + ".kanbn", + "Epic|Feature|User Story", + "L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/tfs" ], "cwd": "${workspaceFolder}", "console": "integratedTerminal", diff --git a/Day/Q32024/Helper-2024-08-28.cs b/Day/Q32024/Helper-2024-08-28.cs index e097ee0..3d0d3f1 100644 --- a/Day/Q32024/Helper-2024-08-28.cs +++ b/Day/Q32024/Helper-2024-08-28.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using System.Collections.ObjectModel; using System.Globalization; +using System.Text.Json; using System.Text.RegularExpressions; namespace File_Folder_Helper.Day.Q32024; @@ -8,6 +9,17 @@ namespace File_Folder_Helper.Day.Q32024; internal static partial class Helper20240828 { + public record HeaderCommon(DateTime Date, + string? Employee, + string? Layer, + string? MesEntity, + string? PSN, + string? Quantity, + string? RDS, + string? Reactor, + string? Recipe, + string? Zone); + public record Record(string? CassetteId, ReadOnlyCollection? CassetteSegments, DateTime? Date, @@ -139,46 +151,64 @@ internal static partial class Helper20240828 internal static void MoveWaferCounterToArchive(ILogger logger, List args) { - Record record; + string json; string keyFile; + string? recipe; string[] lines; - int totalMinutes; string checkFile; - TimeSpan timeSpan; - string weekOfYear; + string directory; + string? quantity; + string runDataSheet; string checkDirectory; + HeaderCommon headerCommon; string logDateFormat = args[3]; string wcSearchPattern = args[5]; - string logSearchPattern = args[2]; - ReadOnlyCollection? records; + string logSearchPattern = $"SKIP---{args[2]}"; string logDirectory = Path.GetFullPath(args[0]); string sourceDirectory = Path.GetFullPath(args[4]); string archiveDirectory = Path.GetFullPath(args[6]); - Calendar calendar = new CultureInfo("en-US").Calendar; - Dictionary> keyValuePairs = GetKeyValuePairs(logSearchPattern, logDirectory); - logger.LogInformation("Mapped {keyValuePairs}(s)", keyValuePairs.Count); + JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true }; FileInfo[] collection = Directory.GetFiles(sourceDirectory, wcSearchPattern, SearchOption.AllDirectories).Select(l => new FileInfo(l)).ToArray(); logger.LogInformation("Found {collection}(s)", collection.Length); foreach (FileInfo fileInfo in collection) { if (fileInfo.DirectoryName is null || !fileInfo.DirectoryName.Contains('-')) continue; + lines = File.ReadAllLines(fileInfo.FullName); + recipe = lines.Length < 2 ? null : lines[1]; + quantity = lines.Length < 1 ? null : lines[0]; keyFile = $"{fileInfo.FullName}.txt"; if (!File.Exists(keyFile)) continue; lines = File.ReadAllLines(keyFile); if (lines.Length != 1) continue; - checkDirectory = Path.Combine(fileInfo.DirectoryName, lines[0].Replace('*', '.')); + runDataSheet = Regex.Replace(lines[0], @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", ".").Split('\r')[0].Split('\n')[0]; + directory = Path.Combine(fileInfo.DirectoryName, runDataSheet); + checkDirectory = Path.Combine(directory, fileInfo.LastWriteTime.Ticks.ToString()); if (!Directory.Exists(checkDirectory)) _ = Directory.CreateDirectory(checkDirectory); - checkFile = Path.Combine(checkDirectory, fileInfo.Name); + checkFile = Path.Combine(directory, fileInfo.Name); if (File.Exists(checkFile)) continue; + headerCommon = new(fileInfo.LastWriteTime, null, null, null, null, quantity, runDataSheet, null, recipe, null); + json = JsonSerializer.Serialize(headerCommon, jsonSerializerOptions); File.Move(fileInfo.FullName, checkFile); File.Delete(keyFile); + checkFile = Path.Combine(checkDirectory, $"{fileInfo.Name}.json"); + if (File.Exists(checkFile)) + continue; + File.WriteAllText(checkFile, json); Directory.SetLastWriteTime(checkDirectory, fileInfo.LastWriteTime); } + Record record; + int totalMinutes; + string weekOfYear; + TimeSpan timeSpan; + ReadOnlyCollection? records; + Calendar calendar = new CultureInfo("en-US").Calendar; + Dictionary> keyValuePairs = GetKeyValuePairs(logSearchPattern, logDirectory); + logger.LogInformation("Mapped {keyValuePairs}(s)", keyValuePairs.Count); foreach (FileInfo fileInfo in collection) { if (fileInfo.DirectoryName is null || fileInfo.DirectoryName.Contains('-')) diff --git a/Day/Q32024/Helper-2024-09-11.cs b/Day/Q32024/Helper-2024-09-11.cs index 11b5d95..d139ef9 100644 --- a/Day/Q32024/Helper-2024-09-11.cs +++ b/Day/Q32024/Helper-2024-09-11.cs @@ -120,8 +120,6 @@ internal static partial class Helper20240911 Dictionary keyValuePairs; foreach (KeyValuePair keyValuePair in workItems) { - // if (keyValuePair.Key != 119185) - // continue; keyValuePairs = GetKeyValuePairs(workItems, keyValuePair.Value); results.Add(keyValuePair.Key, new(keyValuePair.Value, new(keyValuePairs))); } @@ -157,29 +155,42 @@ internal static partial class Helper20240911 private static void AppendLines(List spaces, List lines, ReadOnlyDictionary workItemAndChildren, string workItemType) { WorkItem workItem; + string? maxIterationPath; List distinct = []; foreach (KeyValuePair keyValuePair in workItemAndChildren) { workItem = keyValuePair.Value.WorkItem; + // if (keyValuePair.Key != 109724) + // continue; if (workItem.WorkItemType != workItemType) continue; lines.Add($"## {workItem.AssignedTo} - {workItem.Id} - {workItem.Title}"); lines.Add(string.Empty); lines.Add($"- [{workItem.Id}](https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/{workItem.Id})"); - lines.Add(string.Empty); - if (keyValuePair.Value.Children.Count > 0) + if (keyValuePair.Value.Children.Count == 0) + lines.Add(string.Empty); + else { AppendLines(spaces, lines, keyValuePair.Value, condensed: true, sprintOnly: false); lines.Add(string.Empty); distinct.Clear(); - lines.Add($"## Distinct Iteration Path(s) - {workItem.WorkItemType} - {workItem.AssignedTo} - {workItem.Id} - {workItem.Title} - {workItem.IterationPath}"); - lines.Add(string.Empty); - lines.Add($"- [{workItem.Id}](https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/{workItem.Id})"); - lines.Add(string.Empty); AppendLines(spaces, distinct, keyValuePair.Value, condensed: false, sprintOnly: true); - distinct.Sort(); - lines.AddRange(distinct.Distinct()); - lines.Add(string.Empty); + if (distinct.Count > 1) + { + lines.Add($"## Distinct Iteration Path(s) - {workItem.WorkItemType} - {workItem.AssignedTo} - {workItem.Id} - {workItem.Title} - {workItem.IterationPath}"); + lines.Add(string.Empty); + lines.Add($"- [{workItem.Id}](https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/{workItem.Id})"); + distinct.Sort(); + distinct = (from l in distinct select l.Trim()).Distinct().ToList(); + lines.AddRange(distinct); + lines.Add(string.Empty); + maxIterationPath = distinct.Max(); + if (!string.IsNullOrEmpty(maxIterationPath) && maxIterationPath.Contains("] ") && maxIterationPath.Split(']')[1].Trim() != workItem.IterationPath) + { + lines.Add($"### Sync to Distinct Max Iteration Path => {maxIterationPath} - {workItem.Id} - {workItem.Title}"); + lines.Add(string.Empty); + } + } lines.Add($"## Extended - {workItem.Id} - {workItem.Title}"); lines.Add(string.Empty); AppendLines(spaces, lines, keyValuePair.Value, condensed: false, sprintOnly: false); @@ -195,10 +206,10 @@ internal static partial class Helper20240911 string text; string checkFile; List spaces = []; + List lines = []; string searchPattern = args[2]; string filterDirectory = args[3]; string[] workItemTypes = args[4].Split('|'); - List lines = ["# WorkItems", string.Empty]; string sourceDirectory = Path.GetFullPath(args[0]); string destinationDirectory = Path.GetFullPath(args[5]); if (!Directory.Exists(destinationDirectory)) @@ -216,6 +227,8 @@ internal static partial class Helper20240911 } foreach (string workItemType in workItemTypes) { + lines.Clear(); + lines.AddRange(["# WorkItems", string.Empty]); AppendLines(spaces, lines, workItemAndChildren, workItemType); checkFile = Path.Combine(destinationDirectory, $"{workItemType}.md"); text = string.Join(Environment.NewLine, lines); diff --git a/File-Folder-Helper.csproj b/File-Folder-Helper.csproj index aef7326..2b7c7a9 100644 --- a/File-Folder-Helper.csproj +++ b/File-Folder-Helper.csproj @@ -1,4 +1,4 @@ - + enable Exe @@ -22,6 +22,6 @@ - + \ No newline at end of file