Sync to Distinct Max Iteration Path

This commit is contained in:
Mike Phares 2024-09-24 10:25:07 -07:00
parent dc5a369e55
commit 59231ad9e2
4 changed files with 74 additions and 35 deletions

16
.vscode/launch.json vendored
View File

@ -13,16 +13,12 @@
"args": [ "args": [
"s", "s",
"X", "X",
"L:/Git/Linux-Ubuntu-Server/etc/nginx/include", "D:/5-Other-Small/Kanban-messa010ec/Kanban/Work-Items",
"Day-Helper-2024-09-16", "Day-Helper-2024-09-11",
"*.conf", "*.json",
"L:/Git/Linux-Ubuntu-Server/etc/nginx/sites-available/default", ".kanbn",
"include /etc/nginx/include/", "Epic|Feature|User Story",
"proxy_pass", "L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/tfs"
"666",
"777",
"888",
"999"
], ],
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"console": "integratedTerminal", "console": "integratedTerminal",

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Globalization; using System.Globalization;
using System.Text.Json;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace File_Folder_Helper.Day.Q32024; namespace File_Folder_Helper.Day.Q32024;
@ -8,6 +9,17 @@ namespace File_Folder_Helper.Day.Q32024;
internal static partial class Helper20240828 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, public record Record(string? CassetteId,
ReadOnlyCollection<string>? CassetteSegments, ReadOnlyCollection<string>? CassetteSegments,
DateTime? Date, DateTime? Date,
@ -139,46 +151,64 @@ internal static partial class Helper20240828
internal static void MoveWaferCounterToArchive(ILogger<Worker> logger, List<string> args) internal static void MoveWaferCounterToArchive(ILogger<Worker> logger, List<string> args)
{ {
Record record; string json;
string keyFile; string keyFile;
string? recipe;
string[] lines; string[] lines;
int totalMinutes;
string checkFile; string checkFile;
TimeSpan timeSpan; string directory;
string weekOfYear; string? quantity;
string runDataSheet;
string checkDirectory; string checkDirectory;
HeaderCommon headerCommon;
string logDateFormat = args[3]; string logDateFormat = args[3];
string wcSearchPattern = args[5]; string wcSearchPattern = args[5];
string logSearchPattern = args[2]; string logSearchPattern = $"SKIP---{args[2]}";
ReadOnlyCollection<Record>? records;
string logDirectory = Path.GetFullPath(args[0]); string logDirectory = Path.GetFullPath(args[0]);
string sourceDirectory = Path.GetFullPath(args[4]); string sourceDirectory = Path.GetFullPath(args[4]);
string archiveDirectory = Path.GetFullPath(args[6]); string archiveDirectory = Path.GetFullPath(args[6]);
Calendar calendar = new CultureInfo("en-US").Calendar; JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
Dictionary<int, ReadOnlyCollection<Record>> keyValuePairs = GetKeyValuePairs(logSearchPattern, logDirectory);
logger.LogInformation("Mapped {keyValuePairs}(s)", keyValuePairs.Count);
FileInfo[] collection = Directory.GetFiles(sourceDirectory, wcSearchPattern, SearchOption.AllDirectories).Select(l => new FileInfo(l)).ToArray(); FileInfo[] collection = Directory.GetFiles(sourceDirectory, wcSearchPattern, SearchOption.AllDirectories).Select(l => new FileInfo(l)).ToArray();
logger.LogInformation("Found {collection}(s)", collection.Length); logger.LogInformation("Found {collection}(s)", collection.Length);
foreach (FileInfo fileInfo in collection) foreach (FileInfo fileInfo in collection)
{ {
if (fileInfo.DirectoryName is null || !fileInfo.DirectoryName.Contains('-')) if (fileInfo.DirectoryName is null || !fileInfo.DirectoryName.Contains('-'))
continue; continue;
lines = File.ReadAllLines(fileInfo.FullName);
recipe = lines.Length < 2 ? null : lines[1];
quantity = lines.Length < 1 ? null : lines[0];
keyFile = $"{fileInfo.FullName}.txt"; keyFile = $"{fileInfo.FullName}.txt";
if (!File.Exists(keyFile)) if (!File.Exists(keyFile))
continue; continue;
lines = File.ReadAllLines(keyFile); lines = File.ReadAllLines(keyFile);
if (lines.Length != 1) if (lines.Length != 1)
continue; 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)) if (!Directory.Exists(checkDirectory))
_ = Directory.CreateDirectory(checkDirectory); _ = Directory.CreateDirectory(checkDirectory);
checkFile = Path.Combine(checkDirectory, fileInfo.Name); checkFile = Path.Combine(directory, fileInfo.Name);
if (File.Exists(checkFile)) if (File.Exists(checkFile))
continue; 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.Move(fileInfo.FullName, checkFile);
File.Delete(keyFile); File.Delete(keyFile);
checkFile = Path.Combine(checkDirectory, $"{fileInfo.Name}.json");
if (File.Exists(checkFile))
continue;
File.WriteAllText(checkFile, json);
Directory.SetLastWriteTime(checkDirectory, fileInfo.LastWriteTime); Directory.SetLastWriteTime(checkDirectory, fileInfo.LastWriteTime);
} }
Record record;
int totalMinutes;
string weekOfYear;
TimeSpan timeSpan;
ReadOnlyCollection<Record>? records;
Calendar calendar = new CultureInfo("en-US").Calendar;
Dictionary<int, ReadOnlyCollection<Record>> keyValuePairs = GetKeyValuePairs(logSearchPattern, logDirectory);
logger.LogInformation("Mapped {keyValuePairs}(s)", keyValuePairs.Count);
foreach (FileInfo fileInfo in collection) foreach (FileInfo fileInfo in collection)
{ {
if (fileInfo.DirectoryName is null || fileInfo.DirectoryName.Contains('-')) if (fileInfo.DirectoryName is null || fileInfo.DirectoryName.Contains('-'))

View File

@ -120,8 +120,6 @@ internal static partial class Helper20240911
Dictionary<int, Record> keyValuePairs; Dictionary<int, Record> keyValuePairs;
foreach (KeyValuePair<int, WorkItem> keyValuePair in workItems) foreach (KeyValuePair<int, WorkItem> keyValuePair in workItems)
{ {
// if (keyValuePair.Key != 119185)
// continue;
keyValuePairs = GetKeyValuePairs(workItems, keyValuePair.Value); keyValuePairs = GetKeyValuePairs(workItems, keyValuePair.Value);
results.Add(keyValuePair.Key, new(keyValuePair.Value, new(keyValuePairs))); results.Add(keyValuePair.Key, new(keyValuePair.Value, new(keyValuePairs)));
} }
@ -157,29 +155,42 @@ internal static partial class Helper20240911
private static void AppendLines(List<char> spaces, List<string> lines, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType) private static void AppendLines(List<char> spaces, List<string> lines, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType)
{ {
WorkItem workItem; WorkItem workItem;
string? maxIterationPath;
List<string> distinct = []; List<string> distinct = [];
foreach (KeyValuePair<int, Record> keyValuePair in workItemAndChildren) foreach (KeyValuePair<int, Record> keyValuePair in workItemAndChildren)
{ {
workItem = keyValuePair.Value.WorkItem; workItem = keyValuePair.Value.WorkItem;
// if (keyValuePair.Key != 109724)
// continue;
if (workItem.WorkItemType != workItemType) if (workItem.WorkItemType != workItemType)
continue; continue;
lines.Add($"## {workItem.AssignedTo} - {workItem.Id} - {workItem.Title}"); lines.Add($"## {workItem.AssignedTo} - {workItem.Id} - {workItem.Title}");
lines.Add(string.Empty); lines.Add(string.Empty);
lines.Add($"- [{workItem.Id}](https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/{workItem.Id})"); lines.Add($"- [{workItem.Id}](https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/{workItem.Id})");
if (keyValuePair.Value.Children.Count == 0)
lines.Add(string.Empty); lines.Add(string.Empty);
if (keyValuePair.Value.Children.Count > 0) else
{ {
AppendLines(spaces, lines, keyValuePair.Value, condensed: true, sprintOnly: false); AppendLines(spaces, lines, keyValuePair.Value, condensed: true, sprintOnly: false);
lines.Add(string.Empty); lines.Add(string.Empty);
distinct.Clear(); distinct.Clear();
AppendLines(spaces, distinct, keyValuePair.Value, condensed: false, sprintOnly: true);
if (distinct.Count > 1)
{
lines.Add($"## Distinct Iteration Path(s) - {workItem.WorkItemType} - {workItem.AssignedTo} - {workItem.Id} - {workItem.Title} - {workItem.IterationPath}"); lines.Add($"## Distinct Iteration Path(s) - {workItem.WorkItemType} - {workItem.AssignedTo} - {workItem.Id} - {workItem.Title} - {workItem.IterationPath}");
lines.Add(string.Empty); lines.Add(string.Empty);
lines.Add($"- [{workItem.Id}](https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/{workItem.Id})"); 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(); distinct.Sort();
lines.AddRange(distinct.Distinct()); distinct = (from l in distinct select l.Trim()).Distinct().ToList();
lines.AddRange(distinct);
lines.Add(string.Empty); 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($"## Extended - {workItem.Id} - {workItem.Title}");
lines.Add(string.Empty); lines.Add(string.Empty);
AppendLines(spaces, lines, keyValuePair.Value, condensed: false, sprintOnly: false); AppendLines(spaces, lines, keyValuePair.Value, condensed: false, sprintOnly: false);
@ -195,10 +206,10 @@ internal static partial class Helper20240911
string text; string text;
string checkFile; string checkFile;
List<char> spaces = []; List<char> spaces = [];
List<string> lines = [];
string searchPattern = args[2]; string searchPattern = args[2];
string filterDirectory = args[3]; string filterDirectory = args[3];
string[] workItemTypes = args[4].Split('|'); string[] workItemTypes = args[4].Split('|');
List<string> lines = ["# WorkItems", string.Empty];
string sourceDirectory = Path.GetFullPath(args[0]); string sourceDirectory = Path.GetFullPath(args[0]);
string destinationDirectory = Path.GetFullPath(args[5]); string destinationDirectory = Path.GetFullPath(args[5]);
if (!Directory.Exists(destinationDirectory)) if (!Directory.Exists(destinationDirectory))
@ -216,6 +227,8 @@ internal static partial class Helper20240911
} }
foreach (string workItemType in workItemTypes) foreach (string workItemType in workItemTypes)
{ {
lines.Clear();
lines.AddRange(["# WorkItems", string.Empty]);
AppendLines(spaces, lines, workItemAndChildren, workItemType); AppendLines(spaces, lines, workItemAndChildren, workItemType);
checkFile = Path.Combine(destinationDirectory, $"{workItemType}.md"); checkFile = Path.Combine(destinationDirectory, $"{workItemType}.md");
text = string.Join(Environment.NewLine, lines); text = string.Join(Environment.NewLine, lines);

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
@ -22,6 +22,6 @@
<PackageReference Include="System.Text.Json" Version="8.0.4" /> <PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="TextCopy" Version="6.2.1" /> <PackageReference Include="TextCopy" Version="6.2.1" />
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" /> <PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
<PackageReference Include="YamlDotNet" Version="16.0.0" /> <PackageReference Include="YamlDotNet" Version="16.1.2" />
</ItemGroup> </ItemGroup>
</Project> </Project>