Second round of MoveWaferCounterToArchive
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -19,7 +19,7 @@
|
|||||||
"yyyy-MM-dd",
|
"yyyy-MM-dd",
|
||||||
"D:/5-Other-Small/Kanban-mestsa003/ART-SPS/113724/.vscode/WaferCounter",
|
"D:/5-Other-Small/Kanban-mestsa003/ART-SPS/113724/.vscode/WaferCounter",
|
||||||
"*.wc",
|
"*.wc",
|
||||||
"666",
|
"D:/5-Other-Small/Kanban-mestsa003/ART-SPS/113724/.vscode/Archive",
|
||||||
"777",
|
"777",
|
||||||
"888",
|
"888",
|
||||||
"999"
|
"999"
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace File_Folder_Helper.Day.Q32024;
|
namespace File_Folder_Helper.Day.Q32024;
|
||||||
|
|
||||||
@ -31,7 +33,9 @@ internal static partial class Helper20240828
|
|||||||
if (cassetteIdSegments.Length <= 3)
|
if (cassetteIdSegments.Length <= 3)
|
||||||
result = new Record(null, null, null, null, null, i, null, null);
|
result = new Record(null, null, null, null, null, i, null, null);
|
||||||
else
|
else
|
||||||
result = new Record(cassetteIdSegments[2],
|
{
|
||||||
|
string cassetteId = Regex.Replace(cassetteIdSegments[2], @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
|
||||||
|
result = new Record(cassetteId,
|
||||||
new(cassetteIdSegments),
|
new(cassetteIdSegments),
|
||||||
DateTime.Parse(matches[0][0]),
|
DateTime.Parse(matches[0][0]),
|
||||||
matches[0][1],
|
matches[0][1],
|
||||||
@ -41,6 +45,7 @@ internal static partial class Helper20240828
|
|||||||
new(matches));
|
new(matches));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,14 +82,16 @@ internal static partial class Helper20240828
|
|||||||
Record record;
|
Record record;
|
||||||
string[] lines;
|
string[] lines;
|
||||||
string[] logFiles = Directory.GetFiles(logDirectory, logSearchPattern, SearchOption.TopDirectoryOnly);
|
string[] logFiles = Directory.GetFiles(logDirectory, logSearchPattern, SearchOption.TopDirectoryOnly);
|
||||||
foreach (string logFile in logFiles)
|
if (logFiles.Length > 0)
|
||||||
|
{ }
|
||||||
|
foreach (string logFile in new List<string>()) // logFiles)
|
||||||
{
|
{
|
||||||
lines = File.ReadAllLines(logFile);
|
lines = File.ReadAllLines(logFile);
|
||||||
for (int i = lines.Length - 1; i >= 0; i--)
|
for (int i = lines.Length - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
record = GetRecord(lines, i);
|
record = GetRecord(lines, i);
|
||||||
i = record.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 (record.CassetteId is null || record.CassetteSegments is null || record.Date is null || record.Employee is null || record.EquipmentSegments is null || record.Matches is null)
|
||||||
{
|
{
|
||||||
if (i < 4)
|
if (i < 4)
|
||||||
break;
|
break;
|
||||||
@ -114,7 +121,7 @@ internal static partial class Helper20240828
|
|||||||
ReadOnlyCollection<Record> records = GetRecords(logDirectory, logSearchPattern);
|
ReadOnlyCollection<Record> records = GetRecords(logDirectory, logSearchPattern);
|
||||||
foreach (Record record in records)
|
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)
|
if (record.CassetteId is null || record.CassetteSegments is null || record.Date is null || record.Employee is null || record.EquipmentSegments is null || record.Matches is null)
|
||||||
continue;
|
continue;
|
||||||
timeSpan = TimeSpan.FromTicks(record.Date.Value.Ticks);
|
timeSpan = TimeSpan.FromTicks(record.Date.Value.Ticks);
|
||||||
totalMinutes = (int)Math.Floor(timeSpan.TotalMinutes);
|
totalMinutes = (int)Math.Floor(timeSpan.TotalMinutes);
|
||||||
@ -132,37 +139,72 @@ 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 keyFile;
|
||||||
|
string[] lines;
|
||||||
int totalMinutes;
|
int totalMinutes;
|
||||||
string checkFile;
|
string checkFile;
|
||||||
TimeSpan timeSpan;
|
TimeSpan timeSpan;
|
||||||
string? checkDirectory;
|
string weekOfYear;
|
||||||
|
string checkDirectory;
|
||||||
string logDateFormat = args[3];
|
string logDateFormat = args[3];
|
||||||
string wcSearchPattern = args[5];
|
string wcSearchPattern = args[5];
|
||||||
string logSearchPattern = args[2];
|
string logSearchPattern = args[2];
|
||||||
ReadOnlyCollection<Record>? records;
|
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]);
|
||||||
|
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||||
Dictionary<int, ReadOnlyCollection<Record>> keyValuePairs = GetKeyValuePairs(logSearchPattern, logDirectory);
|
Dictionary<int, ReadOnlyCollection<Record>> keyValuePairs = GetKeyValuePairs(logSearchPattern, logDirectory);
|
||||||
logger.LogInformation("Mapped {keyValuePairs}(s)", keyValuePairs.Count);
|
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)
|
||||||
{
|
{
|
||||||
timeSpan = TimeSpan.FromTicks(fileInfo.LastWriteTime.Ticks);
|
if (fileInfo.DirectoryName is null || !fileInfo.DirectoryName.Contains('-'))
|
||||||
totalMinutes = (int)Math.Floor(timeSpan.TotalMinutes);
|
|
||||||
if (!keyValuePairs.TryGetValue(totalMinutes, out records))
|
|
||||||
continue;
|
continue;
|
||||||
if (records.Count != 1)
|
keyFile = $"{fileInfo.FullName}.txt";
|
||||||
|
if (!File.Exists(keyFile))
|
||||||
continue;
|
continue;
|
||||||
checkDirectory = Path.Combine(logDirectory, timeSpan.ToString(logDateFormat));
|
lines = File.ReadAllLines(keyFile);
|
||||||
if (string.IsNullOrEmpty(checkDirectory))
|
if (lines.Length != 1)
|
||||||
continue;
|
continue;
|
||||||
|
checkDirectory = Path.Combine(fileInfo.DirectoryName, lines[0]);
|
||||||
if (!Directory.Exists(checkDirectory))
|
if (!Directory.Exists(checkDirectory))
|
||||||
_ = Directory.CreateDirectory(checkDirectory);
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
checkFile = Path.Combine(checkDirectory, fileInfo.Name);
|
checkFile = Path.Combine(checkDirectory, fileInfo.Name);
|
||||||
if (File.Exists(checkFile))
|
if (File.Exists(checkFile))
|
||||||
continue;
|
continue;
|
||||||
File.Move(fileInfo.FullName, checkFile);
|
File.Move(fileInfo.FullName, checkFile);
|
||||||
|
File.Delete(keyFile);
|
||||||
|
}
|
||||||
|
foreach (FileInfo fileInfo in collection)
|
||||||
|
{
|
||||||
|
if (fileInfo.DirectoryName is null || fileInfo.DirectoryName.Contains('-'))
|
||||||
|
continue;
|
||||||
|
timeSpan = TimeSpan.FromTicks(fileInfo.LastWriteTime.Ticks);
|
||||||
|
totalMinutes = (int)Math.Floor(timeSpan.TotalMinutes);
|
||||||
|
if (!keyValuePairs.TryGetValue(totalMinutes, out records))
|
||||||
|
continue;
|
||||||
|
if (records.Count != 1)
|
||||||
|
continue;
|
||||||
|
record = records[0];
|
||||||
|
if (record.CassetteId is null || record.CassetteSegments is null || record.Date is null || record.Employee is null || record.EquipmentSegments is null || record.Matches is null)
|
||||||
|
continue;
|
||||||
|
weekOfYear = $"{record.Date.Value.Year}_Week_{calendar.GetWeekOfYear(record.Date.Value, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
||||||
|
checkDirectory = Path.Combine(archiveDirectory,
|
||||||
|
string.Join('-', record.EquipmentSegments.Reverse()),
|
||||||
|
weekOfYear,
|
||||||
|
record.Date.Value.ToString("yyyy-MM-dd"),
|
||||||
|
record.CassetteId);
|
||||||
|
if (!Directory.Exists(checkDirectory))
|
||||||
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
|
checkFile = Path.Combine(checkDirectory, fileInfo.Name);
|
||||||
|
if (File.Exists(checkFile))
|
||||||
|
continue;
|
||||||
|
File.Move(fileInfo.FullName, checkFile);
|
||||||
|
lines = record.Matches.Select(l => string.Join(',', l)).ToArray();
|
||||||
|
File.WriteAllLines($"{checkFile}.txt", lines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user