Reactor
This commit is contained in:
parent
095618b194
commit
fd1ee79e75
17
.vscode/launch.json
vendored
17
.vscode/launch.json
vendored
@ -13,18 +13,11 @@
|
|||||||
"args": [
|
"args": [
|
||||||
"s",
|
"s",
|
||||||
"X",
|
"X",
|
||||||
"T:/MESAFIBACKLOG/06_SourceCode/MESAFIBACKLOG/Adaptation/.vscode/helper",
|
"L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/2024-01-13",
|
||||||
"Day-Helper-2024-08-09",
|
"Day-Helper-2023-11-30",
|
||||||
"MES",
|
"yyMMddhhmmssfff",
|
||||||
"https://tfs.intra.infineon.com",
|
"\"SystemState\"",
|
||||||
"/tfs/FactoryIntegration",
|
"\\\\mesfs.infineon.com\\EC_APC\\Staging\\Traces\\DEP08CEPIEPSILON\\Test\\1762-T27\\2024-01-13",
|
||||||
"ART SPS",
|
|
||||||
"/_apis/wit",
|
|
||||||
"/wiql/3373b300-8de3-4301-9795-e990c3b226f9",
|
|
||||||
"4n7d2jcql6bkq32f66tohddonfxajkypq66lm5y3zqemtlohawsa",
|
|
||||||
"FI Backlog Mesa - Request List.json",
|
|
||||||
"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",
|
||||||
|
@ -52,24 +52,57 @@ internal static class Helper20231130
|
|||||||
return new(results.OrderBy(l => l.TimeStamp).ToArray());
|
return new(results.OrderBy(l => l.TimeStamp).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int? GetKeyColumnIndex(string[] columns, string keyColumn)
|
||||||
|
{
|
||||||
|
int? result = null;
|
||||||
|
for (int i = 0; i < columns.Length; i++)
|
||||||
|
{
|
||||||
|
if (columns[i] != keyColumn)
|
||||||
|
continue;
|
||||||
|
result = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ReadOnlyCollection<string> GetSystemStateValues(List<string> lines, string[] columns, int keyColumnIndex, ReadOnlyDictionary<string, string> systemStates)
|
||||||
|
{
|
||||||
|
List<string> results = [];
|
||||||
|
string[] values;
|
||||||
|
string? systemState;
|
||||||
|
string keyColumnValue;
|
||||||
|
for (int i = 7; i < lines.Count; i++)
|
||||||
|
{
|
||||||
|
values = lines[i].Split('\t');
|
||||||
|
if (values.Length != columns.Length)
|
||||||
|
continue;
|
||||||
|
keyColumnValue = values[keyColumnIndex];
|
||||||
|
if (string.IsNullOrEmpty(keyColumnValue))
|
||||||
|
continue;
|
||||||
|
if (!systemStates.TryGetValue(keyColumnValue, out systemState))
|
||||||
|
continue;
|
||||||
|
if (results.Contains(systemState))
|
||||||
|
continue;
|
||||||
|
results.Add(systemState);
|
||||||
|
}
|
||||||
|
return new(results);
|
||||||
|
}
|
||||||
|
|
||||||
internal static void RenameReactorProcessDataStandardFormatFiles(ILogger<Worker> logger, List<string> args)
|
internal static void RenameReactorProcessDataStandardFormatFiles(ILogger<Worker> logger, List<string> args)
|
||||||
{
|
{
|
||||||
string line;
|
|
||||||
string[] lines;
|
|
||||||
string[] values;
|
|
||||||
string[] columns;
|
string[] columns;
|
||||||
DateTime dateTime;
|
DateTime dateTime;
|
||||||
|
List<string> lines;
|
||||||
|
string systemState;
|
||||||
int? keyColumnIndex;
|
int? keyColumnIndex;
|
||||||
string? systemState;
|
|
||||||
string checkFileName;
|
string checkFileName;
|
||||||
string keyColumnValue;
|
|
||||||
string? lastColumn = null;
|
|
||||||
List<string> allLines = [];
|
|
||||||
string keyColumn = args[3];
|
string keyColumn = args[3];
|
||||||
|
List<string> headerLines = [];
|
||||||
string sourceDirectory = args[0];
|
string sourceDirectory = args[0];
|
||||||
string timestampFormat = args[2];
|
string timestampFormat = args[2];
|
||||||
if (!Directory.Exists(sourceDirectory))
|
if (!Directory.Exists(sourceDirectory))
|
||||||
throw new Exception(sourceDirectory);
|
throw new Exception(sourceDirectory);
|
||||||
|
ReadOnlyCollection<string> systemStateValues;
|
||||||
string missingKeyDirectory = Path.Combine(sourceDirectory, "Missing-Key");
|
string missingKeyDirectory = Path.Combine(sourceDirectory, "Missing-Key");
|
||||||
if (!Directory.Exists(missingKeyDirectory))
|
if (!Directory.Exists(missingKeyDirectory))
|
||||||
_ = Directory.CreateDirectory(missingKeyDirectory);
|
_ = Directory.CreateDirectory(missingKeyDirectory);
|
||||||
@ -77,52 +110,42 @@ internal static class Helper20231130
|
|||||||
ReadOnlyCollection<Record> records = GetRecords(sourceDirectory, timestampFormat);
|
ReadOnlyCollection<Record> records = GetRecords(sourceDirectory, timestampFormat);
|
||||||
foreach (Record record in records)
|
foreach (Record record in records)
|
||||||
{
|
{
|
||||||
lines = File.ReadAllLines(record.File);
|
headerLines.Clear();
|
||||||
if (lines.Length < 8)
|
lines = File.ReadAllLines(record.File).ToList();
|
||||||
|
if (lines.Count < 8)
|
||||||
continue;
|
continue;
|
||||||
if (lines[6].Length < 1 || lines[6][0] != '"' || !lines[6].StartsWith("\"Time\""))
|
for (int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
headerLines.Add(lines[0]);
|
||||||
|
lines.RemoveAt(0);
|
||||||
|
}
|
||||||
|
if (lines[0].Length < 1 || lines[0][0] != '"' || !lines[0].StartsWith("\"Time\""))
|
||||||
continue;
|
continue;
|
||||||
if (lastColumn is not null && lines[6] != lastColumn)
|
|
||||||
break;
|
|
||||||
keyColumnIndex = null;
|
keyColumnIndex = null;
|
||||||
lastColumn = lines[6];
|
columns = lines[0].Split('\t');
|
||||||
if (allLines.Count == 0)
|
|
||||||
allLines.Add($"\"Timestamp\"\t{lastColumn}");
|
|
||||||
columns = lines[6].Split('\t');
|
|
||||||
if (columns.Length < 3)
|
if (columns.Length < 3)
|
||||||
continue;
|
continue;
|
||||||
values = lines[7].Split('\t');
|
keyColumnIndex = GetKeyColumnIndex(columns, keyColumn);
|
||||||
if (values.Length != columns.Length)
|
|
||||||
continue;
|
|
||||||
for (int i = 0; i < columns.Length; i++)
|
|
||||||
{
|
|
||||||
if (columns[i] != keyColumn)
|
|
||||||
continue;
|
|
||||||
keyColumnIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (keyColumnIndex is null)
|
if (keyColumnIndex is null)
|
||||||
{
|
{
|
||||||
File.Move(record.File, Path.Combine(sourceDirectory, missingKeyDirectory, record.FileName));
|
File.Move(record.File, Path.Combine(sourceDirectory, missingKeyDirectory, record.FileName));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int i = 7; i < lines.Length; i++)
|
|
||||||
{
|
|
||||||
line = lines[i];
|
|
||||||
if (line.Length < 1 || line[0] == 'N' && line.StartsWith("NUM_DATA_ROWS\t"))
|
|
||||||
break;
|
|
||||||
allLines.Add($"'{record.TimeStamp}\t{line}");
|
|
||||||
}
|
|
||||||
keyColumnValue = values[keyColumnIndex.Value];
|
|
||||||
logger.LogInformation("{timestamp} triggered", record.TimeStamp);
|
logger.LogInformation("{timestamp} triggered", record.TimeStamp);
|
||||||
if (!systemStates.TryGetValue(keyColumnValue, out systemState))
|
systemStateValues = GetSystemStateValues(lines, columns, keyColumnIndex.Value, systemStates);
|
||||||
|
if (systemStateValues.Count == 0)
|
||||||
|
{
|
||||||
|
File.Move(record.File, Path.Combine(sourceDirectory, missingKeyDirectory, record.FileName));
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
lines.AddRange(headerLines);
|
||||||
|
systemState = string.Join('-', systemStateValues);
|
||||||
checkFileName = Path.Combine(Path.GetDirectoryName(record.File) ?? throw new Exception(), $"{record.Equipment}-{record.TimeStamp}-{systemState}.pdsf");
|
checkFileName = Path.Combine(Path.GetDirectoryName(record.File) ?? throw new Exception(), $"{record.Equipment}-{record.TimeStamp}-{systemState}.pdsf");
|
||||||
File.Move(record.File, checkFileName);
|
File.WriteAllLines(checkFileName, lines);
|
||||||
|
File.Delete(record.File);
|
||||||
if (DateTime.TryParseExact(record.TimeStamp, timestampFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
if (DateTime.TryParseExact(record.TimeStamp, timestampFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||||
File.SetLastWriteTime(checkFileName, dateTime);
|
File.SetLastWriteTime(checkFileName, dateTime);
|
||||||
}
|
}
|
||||||
File.WriteAllLines(Path.Combine(sourceDirectory, $"{DateTime.Now.Ticks}.tsv"), allLines);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user