MoveWaferCounterToArchive

ParseKanbn
This commit is contained in:
Mike Phares 2024-08-29 08:03:46 -07:00
parent f87c5a9aa6
commit 23eacb54c1
5 changed files with 414 additions and 15 deletions

22
.vscode/launch.json vendored
View File

@ -13,18 +13,16 @@
"args": [ "args": [
"s", "s",
"X", "X",
"T:/MESAFIBACKLOG/06_SourceCode/MESAFIBACKLOG/Adaptation/.vscode/helper", "D:/5-Other-Small/Kanban-mestsa003/ART-SPS/113724/.vscode/LogFiles/WaferCounter",
"Day-Helper-2024-08-09", "Day-Helper-2024-08-28",
"MES", "*Wafer Counter Verify Log.csv",
"https://tfs.intra.infineon.com", "yyyy-MM-dd",
"/tfs/FactoryIntegration", "D:/5-Other-Small/Kanban-mestsa003/ART-SPS/113724/.vscode/WaferCounter",
"ART SPS", "*.wc",
"/0d06e969-e1f5-4835-a359-620d557c7595/_apis/wit", "666",
"/wiql/3373b300-8de3-4301-9795-e990c3b226f9", "777",
"4n7d2jcql6bkq32f66tohddonfxajkypq66lm5y3zqemtlohawsa", "888",
"FI Backlog Mesa - Request List.json", "999"
"Chase|infineon\\TuckerC,Dakota(SRP)|infineon\\Mitchem,Daniel|infineon\\StieberD,Jonathan|infineon\\Ouellette,Mike|infineon\\Phares",
"Chad B|infineon\\cbecker1,Debra Q|infineon\\Quinones,Jeanne M|infineon\\jmcinty2,Jessica F|infineon\\jfuente1,Jonathon S|infineon\\jsperli1,Justin H|infineon\\jhollan2,Kelly C|infineon\\kclark1,Mark C|infineon\\mcouste1,Marti J|infineon\\mjarsey1,Nik C|infineon\\nclark1,Peyton M|infineon\\McChesne,Ron O|infineon\\HendersS,Susan H|infineon\\HendersS,Tiffany M|infineon\\tmunoz1,Todd C|infineon\\tcarrie1"
], ],
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"console": "integratedTerminal", "console": "integratedTerminal",

View File

@ -93,6 +93,10 @@ internal static class HelperDay
Day.Q32024.Helper20240809.CreateWorkItems(logger, args); Day.Q32024.Helper20240809.CreateWorkItems(logger, args);
else if (args[1] == "Day-Helper-2024-08-20") else if (args[1] == "Day-Helper-2024-08-20")
Day.Q32024.Helper20240820.MoveFilesWithSleep(logger, args); Day.Q32024.Helper20240820.MoveFilesWithSleep(logger, args);
else if (args[1] == "Day-Helper-2024-08-22")
Day.Q32024.Helper20240822.ParseKanbn(logger, args);
else if (args[1] == "Day-Helper-2024-08-28")
Day.Q32024.Helper20240828.MoveWaferCounterToArchive(logger, args);
else else
throw new Exception(appSettings.Company); throw new Exception(appSettings.Company);
} }

View File

@ -0,0 +1,228 @@
using Microsoft.Extensions.Logging;
using System.Collections.ObjectModel;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Day.Q32024;
internal static partial class Helper20240822
{
public record Record(string? Title, ReadOnlyCollection<string> Tags, string? Completed);
public record Root([property: JsonPropertyName("headings")] Heading[] Headings,
[property: JsonPropertyName("lanes")] Lane[] Lanes);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Root))]
internal partial class Helper20240822RootSourceGenerationContext : JsonSerializerContext
{
}
public record Welcome2([property: JsonPropertyName("headings")] Heading[] Headings,
[property: JsonPropertyName("lanes")] Lane[] Lanes);
public record Heading([property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("heading")] string HeadingHeading);
public record Lane([property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("columns")] Column[][] Columns);
public record Column([property: JsonPropertyName("id")] string Id,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("description")] string Description,
[property: JsonPropertyName("metadata")] Metadata? Metadata,
[property: JsonPropertyName("subTasks")] SubTask[]? SubTasks,
[property: JsonPropertyName("relations")] object[] Relations,
[property: JsonPropertyName("comments")] Comment[] Comments,
[property: JsonPropertyName("column")] string ColumnColumn,
[property: JsonPropertyName("workload")] long Workload,
[property: JsonPropertyName("progress")] long Progress,
[property: JsonPropertyName("remainingWorkload")] long RemainingWorkload,
[property: JsonPropertyName("dueData")] DueData DueData);
public record Comment([property: JsonPropertyName("text")] string Text,
[property: JsonPropertyName("date")] DateTimeOffset Date);
public record DueData([property: JsonPropertyName("completed")] bool Completed,
[property: JsonPropertyName("completedDate")] object CompletedDate,
[property: JsonPropertyName("dueDate")] DateTimeOffset DueDate,
[property: JsonPropertyName("overdue")] bool Overdue,
[property: JsonPropertyName("dueDelta")] long DueDelta,
[property: JsonPropertyName("dueMessage")] string DueMessage);
public record Metadata([property: JsonPropertyName("assigned")] string Assigned,
[property: JsonPropertyName("created")] DateTimeOffset Created,
[property: JsonPropertyName("progress")] long? Progress,
[property: JsonPropertyName("started")] DateTimeOffset? Started,
[property: JsonPropertyName("status")] string? Status,
[property: JsonPropertyName("tags")] string[]? Tags,
[property: JsonPropertyName("type")] string? Type,
[property: JsonPropertyName("updated")] DateTimeOffset Updated,
[property: JsonPropertyName("due")] DateTimeOffset? Due,
[property: JsonPropertyName("completed")] DateTimeOffset? Completed);
public record SubTask([property: JsonPropertyName("text")] string Text,
[property: JsonPropertyName("completed")] bool Completed);
private static ReadOnlyCollection<ReadOnlyCollection<Record>> GetRecords(Column[][] columnCollection)
{
List<ReadOnlyCollection<Record>> results = [];
bool check;
int subTasks;
Column column;
int completed;
List<Record> row;
string? subtasks;
List<string> tags;
for (int i = 0; i < int.MaxValue; i++)
{
row = [];
check = false;
foreach (Column[] columns in columnCollection)
{
if (columns.Length <= i)
row.Add(new(null, new([]), null));
else
{
tags = [];
subTasks = 0;
completed = 0;
column = columns[i];
if (!check)
check = true;
if (column.Metadata?.Tags is not null && column.Metadata.Tags.Length != 0)
{
foreach (string tag in column.Metadata.Tags)
tags.Add(tag);
}
if (column.SubTasks is not null && column.SubTasks.Length != 0)
{
foreach (SubTask subTask in column.SubTasks)
{
subTasks += 1;
if (subTask.Completed)
completed += 1;
}
}
subtasks = subTasks == 0 ? subtasks = null : $"{completed} / {subTasks}";
row.Add(new(column.Name, new(tags), subtasks));
}
}
if (!check)
break;
if (results.Count > 0)
{
if (results[0].Count != row.Count)
throw new Exception("Rows must match!");
}
results.Add(new(row));
}
return new(results);
}
private static void WriteFile(string destinationFile, Heading[] headings, ReadOnlyCollection<ReadOnlyCollection<Record>> recordCollection)
{
string title;
string completed;
List<string> lines =
[
"<html>",
"<head>",
"<style>",
":root {",
"color-scheme: light dark;",
"}",
"body {",
"color: light-dark(#333b3c, #efedea);",
"background-color: light-dark(#efedea, #333b3c);",
"}",
"td {",
"vertical-align: top;",
"}",
".title {",
"font-weight: bold;",
"}",
".complete {",
"font-size: small;",
"}",
".speech-bubble {",
"position: relative;",
"background: darkCyan;",
"border-radius: .4em;",
"}",
".speech-bubble:after {",
"content: '';",
"position: absolute;",
"bottom: 0;",
"left: 50%;",
"width: 0;",
"height: 0;",
"border: 2px solid transparent;",
"border-top-color: #00aabb;",
"border-bottom: 0;",
"margin-left: -2px;",
"margin-bottom: -2px;",
"}",
"</style>",
"</head>",
"<table border=\"1\">",
"<tr>"
];
foreach (Heading heading in headings)
lines.Add($"<th>{heading.Name}</th>");
lines.Add("</tr>");
foreach (ReadOnlyCollection<Record> records in recordCollection)
{
lines.Add("<tr>");
foreach (Record record in records)
{
lines.Add("<td>");
title = record.Title is null ? "&nbsp;" : record.Title;
completed = record.Completed is null ? "&nbsp;" : record.Completed;
lines.Add($"<div class=\"title\">{title}</div>");
lines.Add("<div>");
foreach (string tag in record.Tags)
lines.Add($"<span class=\"speech-bubble\">{tag}</span>");
lines.Add("</div>");
lines.Add($"<div class=\"completed\">{completed}</div>");
lines.Add("</td>");
}
lines.Add("</tr>");
}
lines.Add("</table>");
lines.Add("</html>");
File.WriteAllLines(destinationFile, lines);
}
private static void ParseKanbn(ILogger<Worker> logger, string destinationFile, string json)
{
Root? root = JsonSerializer.Deserialize(json, Helper20240822RootSourceGenerationContext.Default.Root);
if (root is null)
logger.LogInformation("<{root}> is null!", root);
else if (root.Lanes.Length != 1)
logger.LogInformation("{root.Lanes} != 1", root.Lanes.Length);
else if (root.Lanes[0].Columns.Length != root.Headings.Length)
logger.LogInformation("{root[0].Columns.Lanes} != {root.Headings}", root.Lanes[0].Columns.Length, root.Headings.Length);
else
{
ReadOnlyCollection<ReadOnlyCollection<Record>> recordCollection = GetRecords(root.Lanes[0].Columns);
WriteFile(destinationFile, root.Headings, recordCollection);
}
}
internal static void ParseKanbn(ILogger<Worker> logger, List<string> args)
{
string sourceDirectory = Path.GetFullPath(args[0]);
string sourceFile = Path.Combine(sourceDirectory, args[2]);
string destinationFile = Path.Combine(sourceDirectory, $"{DateTime.Now.Ticks}-{args[3]}");
if (!File.Exists(sourceFile))
logger.LogInformation("<{sourceFile}> doesn't exist!", sourceFile);
else
{
string json = File.ReadAllText(sourceFile);
ParseKanbn(logger, destinationFile, json);
}
}
}

View File

@ -0,0 +1,169 @@
using Microsoft.Extensions.Logging;
using System.Collections.ObjectModel;
namespace File_Folder_Helper.Day.Q32024;
internal static partial class Helper20240828
{
public record Record(string? CassetteId,
ReadOnlyCollection<string>? CassetteSegments,
DateTime? Date,
string? Employee,
ReadOnlyCollection<string>? EquipmentSegments,
int I,
string? LastDate,
ReadOnlyCollection<ReadOnlyCollection<string>>? Matches);
private static Record GetRecord(int i, string? lastDate, ReadOnlyCollection<ReadOnlyCollection<string>> matches)
{
Record result;
if (matches.Count != 4 || matches[0].Count != 3 || matches[3].Count != 3)
result = new Record(null, null, null, null, null, i, null, null);
else
{
string[] equipmentSegments = matches[1][2].Split('|');
if (equipmentSegments.Length != 2)
result = new Record(null, null, null, null, null, i, null, null);
else
{
string[] cassetteIdSegments = matches[3][2].Split('|');
if (cassetteIdSegments.Length <= 3)
result = new Record(null, null, null, null, null, i, null, null);
else
result = new Record(cassetteIdSegments[2],
new(cassetteIdSegments),
DateTime.Parse(matches[0][0]),
matches[0][1],
new(equipmentSegments),
i,
lastDate,
new(matches));
}
}
return result;
}
private static Record GetRecord(string[] lines, int i)
{
Record result;
int ii = i;
string line;
string[] segments;
string? lastDate = null;
List<ReadOnlyCollection<string>> matches = [];
for (int j = i; j >= 0; j--)
{
ii = j;
line = lines[j];
segments = line.Split(',');
if (segments.Length < 2)
continue;
lastDate ??= segments[0];
if (segments[0] != lastDate)
{
lastDate = segments[0];
break;
}
matches.Add(new(segments));
}
result = GetRecord(ii + 1, lastDate, new(matches));
return result;
}
private static ReadOnlyCollection<Record> GetRecords(string logDirectory, string logSearchPattern)
{
List<Record> results = [];
Record record;
string[] lines;
string[] logFiles = Directory.GetFiles(logDirectory, logSearchPattern, SearchOption.TopDirectoryOnly);
foreach (string logFile in logFiles)
{
lines = File.ReadAllLines(logFile);
for (int i = lines.Length - 1; i >= 0; i--)
{
record = GetRecord(lines, i);
i = record.I;
if (record.CassetteId is null || record.CassetteSegments is null || record.Date is null || record.Employee is null || record.EquipmentSegments is null)
{
if (i < 4)
break;
continue;
}
results.Add(record);
}
}
return new(results);
}
private static Dictionary<int, ReadOnlyCollection<Record>> GetKeyValuePairs(Dictionary<int, List<Record>> keyValuePairs)
{
Dictionary<int, ReadOnlyCollection<Record>> results = [];
foreach (KeyValuePair<int, List<Record>> keyValuePair in keyValuePairs)
results.Add(keyValuePair.Key, new(keyValuePair.Value));
return new(results);
}
private static Dictionary<int, ReadOnlyCollection<Record>> GetKeyValuePairs(string logSearchPattern, string logDirectory)
{
Dictionary<int, ReadOnlyCollection<Record>> results;
int totalMinutes;
TimeSpan timeSpan;
List<Record>? collection;
Dictionary<int, List<Record>> keyValuePairs = [];
ReadOnlyCollection<Record> records = GetRecords(logDirectory, logSearchPattern);
foreach (Record record in records)
{
if (record.CassetteId is null || record.CassetteSegments is null || record.Date is null || record.Employee is null || record.EquipmentSegments is null)
continue;
timeSpan = TimeSpan.FromTicks(record.Date.Value.Ticks);
totalMinutes = (int)Math.Floor(timeSpan.TotalMinutes);
if (!keyValuePairs.TryGetValue(totalMinutes, out collection))
{
keyValuePairs.Add(totalMinutes, []);
if (!keyValuePairs.TryGetValue(totalMinutes, out collection))
throw new Exception();
}
collection.Add(record);
}
results = GetKeyValuePairs(keyValuePairs);
return results;
}
internal static void MoveWaferCounterToArchive(ILogger<Worker> logger, List<string> args)
{
int totalMinutes;
string checkFile;
TimeSpan timeSpan;
string? checkDirectory;
string logDateFormat = args[3];
string wcSearchPattern = args[5];
string logSearchPattern = args[2];
ReadOnlyCollection<Record>? records;
string logDirectory = Path.GetFullPath(args[0]);
string sourceDirectory = Path.GetFullPath(args[4]);
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();
logger.LogInformation("Found {collection}(s)", collection.Length);
foreach (FileInfo fileInfo in collection)
{
timeSpan = TimeSpan.FromTicks(fileInfo.LastWriteTime.Ticks);
totalMinutes = (int)Math.Floor(timeSpan.TotalMinutes);
if (!keyValuePairs.TryGetValue(totalMinutes, out records))
continue;
if (records.Count != 1)
continue;
checkDirectory = Path.Combine(logDirectory, timeSpan.ToString(logDateFormat));
if (string.IsNullOrEmpty(checkDirectory))
continue;
if (!Directory.Exists(checkDirectory))
_ = Directory.CreateDirectory(checkDirectory);
checkFile = Path.Combine(checkDirectory, fileInfo.Name);
if (File.Exists(checkFile))
continue;
File.Move(fileInfo.FullName, checkFile);
}
}
}

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>
@ -16,8 +16,8 @@
<PackageReference Include="DiscUtils.Iso9660" Version="0.16.13" /> <PackageReference Include="DiscUtils.Iso9660" Version="0.16.13" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.205.1" /> <PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="19.225.1" />
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.7" /> <PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.8" />
<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" />