json in process-data-standard-format

This commit is contained in:
Mike Phares 2025-05-16 15:15:49 -07:00
parent c5e45a7afd
commit 5e9f9e7a57
2 changed files with 77 additions and 24 deletions

View File

@ -27,21 +27,18 @@ public class FileRead : Shared.FileRead, IFileRead
internal string MatchingFile { get; private set; } internal string MatchingFile { get; private set; }
internal string CheckDirectory { get; private set; } internal string CheckDirectory { get; private set; }
internal string NoWaitDirectory { get; private set; } internal string NoWaitDirectory { get; private set; }
internal bool MesEntityMatchesProcess { get; private set; }
internal PreWith(string checkDirectory, internal PreWith(string checkDirectory,
string checkFile, string checkFile,
string errFile, string errFile,
string matchingFile, string matchingFile,
string noWaitDirectory, string noWaitDirectory)
bool mesEntityMatchesProcess)
{ {
ErrFile = errFile; ErrFile = errFile;
CheckFile = checkFile; CheckFile = checkFile;
MatchingFile = matchingFile; MatchingFile = matchingFile;
CheckDirectory = checkDirectory; CheckDirectory = checkDirectory;
NoWaitDirectory = noWaitDirectory; NoWaitDirectory = noWaitDirectory;
MesEntityMatchesProcess = mesEntityMatchesProcess;
} }
} }
@ -212,7 +209,7 @@ public class FileRead : Shared.FileRead, IFileRead
return result; return result;
} }
private static ReadOnlyCollection<PreWith> GetPreWithCollection(ReadOnlyCollection<Pre> preCollection, bool mesEntityMatchesProcess) private static ReadOnlyCollection<PreWith> GetPreWithCollection(ReadOnlyCollection<Pre> preCollection)
{ {
List<PreWith> results = new(); List<PreWith> results = new();
string errFile; string errFile;
@ -232,8 +229,7 @@ public class FileRead : Shared.FileRead, IFileRead
checkFile: pre.CheckFile, checkFile: pre.CheckFile,
errFile: errFile, errFile: errFile,
matchingFile: pre.MatchingFile, matchingFile: pre.MatchingFile,
noWaitDirectory: noWaitDirectory, noWaitDirectory: noWaitDirectory);
mesEntityMatchesProcess: mesEntityMatchesProcess);
results.Add(preWith); results.Add(preWith);
} }
return results.AsReadOnly(); return results.AsReadOnly();
@ -272,7 +268,7 @@ public class FileRead : Shared.FileRead, IFileRead
} }
} }
private static ReadOnlyCollection<Pre> GetPreCollection(int numberLength, string parentDirectory, ReadOnlyCollection<string> matchingFiles) private static ReadOnlyCollection<Pre> GetPreCollection(int numberLength, string parentDirectory, ReadOnlyCollection<string> matchingFiles, bool _)
{ {
List<Pre> results = new(); List<Pre> results = new();
Pre pre; Pre pre;
@ -287,7 +283,7 @@ public class FileRead : Shared.FileRead, IFileRead
return results.AsReadOnly(); return results.AsReadOnly();
} }
private void MoveCollection(DateTime dateTime, ProcessDataStandardFormat? processDataStandardFormat, ReadOnlyCollection<PreWith> preWithCollection) private void MoveCollection(DateTime dateTime, ProcessDataStandardFormat processDataStandardFormat, ReadOnlyCollection<PreWith> preWithCollection)
{ {
ReadOnlyCollection<Post> postCollection = GetPostCollection(dateTime, processDataStandardFormat, preWithCollection); ReadOnlyCollection<Post> postCollection = GetPostCollection(dateTime, processDataStandardFormat, preWithCollection);
if (postCollection.Count != 0) if (postCollection.Count != 0)
@ -306,7 +302,7 @@ public class FileRead : Shared.FileRead, IFileRead
} }
} }
private ReadOnlyCollection<Post> GetPostCollection(DateTime dateTime, ProcessDataStandardFormat? processDataStandardFormat, ReadOnlyCollection<PreWith> preWithCollection) private ReadOnlyCollection<Post> GetPostCollection(DateTime dateTime, ProcessDataStandardFormat processDataStandardFormat, ReadOnlyCollection<PreWith> preWithCollection)
{ {
List<Post> results = new(); List<Post> results = new();
Post post; Post post;
@ -315,15 +311,10 @@ public class FileRead : Shared.FileRead, IFileRead
{ {
if (!_IsEAFHosted) if (!_IsEAFHosted)
continue; continue;
if (processDataStandardFormat is null) if (!_StaticRuns.TryGetValue(_Logistics.Sequence, out List<Shared.Metrology.WS.Results>? wsResults))
File.Move(preWith.MatchingFile, preWith.CheckFile); wsResults = null;
else ProcessDataStandardFormat.Write(preWith.CheckFile, processDataStandardFormat, wsResults);
{ File.Delete(preWith.MatchingFile);
if (!_StaticRuns.TryGetValue(_Logistics.Sequence, out List<Shared.Metrology.WS.Results>? wsResults))
wsResults = null;
ProcessDataStandardFormat.Write(preWith.CheckFile, processDataStandardFormat, wsResults);
File.Delete(preWith.MatchingFile);
}
if (Directory.Exists(preWith.NoWaitDirectory)) if (Directory.Exists(preWith.NoWaitDirectory))
{ {
post = new(preWith.CheckFile, preWith.ErrFile); post = new(preWith.CheckFile, preWith.ErrFile);
@ -360,7 +351,7 @@ public class FileRead : Shared.FileRead, IFileRead
ProcessDataStandardFormat processDataStandardFormat = ProcessDataStandardFormat.GetProcessDataStandardFormat(reportFullPath, _ProcessDataStandardFormatMapping); ProcessDataStandardFormat processDataStandardFormat = ProcessDataStandardFormat.GetProcessDataStandardFormat(reportFullPath, _ProcessDataStandardFormatMapping);
_Logistics = new Logistics(reportFullPath, processDataStandardFormat); _Logistics = new Logistics(reportFullPath, processDataStandardFormat);
if (!_IsEAFHosted) if (!_IsEAFHosted)
ProcessDataStandardFormat.Write(".pdsf", processDataStandardFormat, wsResults: null); ProcessDataStandardFormat.Write("../../.pdsf", processDataStandardFormat, wsResults: null);
SetFileParameterLotIDToLogisticsMID(); SetFileParameterLotIDToLogisticsMID();
int numberLength = 2; int numberLength = 2;
long ticks = dateTime.Ticks; long ticks = dateTime.Ticks;
@ -378,8 +369,8 @@ public class FileRead : Shared.FileRead, IFileRead
JsonElement[] jsonElements = ProcessDataStandardFormat.GetArray(processDataStandardFormat); JsonElement[] jsonElements = ProcessDataStandardFormat.GetArray(processDataStandardFormat);
List<RsM.Description> descriptions = RsM.ProcessData.GetDescriptions(jsonElements); List<RsM.Description> descriptions = RsM.ProcessData.GetDescriptions(jsonElements);
bool mesEntityMatchesProcess = descriptions.Count > 0 && descriptions[0].MesEntity == descriptions[0].Reactor; bool mesEntityMatchesProcess = descriptions.Count > 0 && descriptions[0].MesEntity == descriptions[0].Reactor;
ReadOnlyCollection<Pre> preCollection = GetPreCollection(numberLength, parentParentDirectory, matchingFiles); ReadOnlyCollection<Pre> preCollection = GetPreCollection(numberLength, parentParentDirectory, matchingFiles, mesEntityMatchesProcess);
ReadOnlyCollection<PreWith> preWithCollection = GetPreWithCollection(preCollection, mesEntityMatchesProcess); ReadOnlyCollection<PreWith> preWithCollection = GetPreWithCollection(preCollection);
MoveCollection(dateTime, processDataStandardFormat, preWithCollection); MoveCollection(dateTime, processDataStandardFormat, preWithCollection);
return results; return results;
} }

View File

@ -360,6 +360,63 @@ internal class ProcessDataStandardFormat
return result; return result;
} }
private static string GetJson(ProcessDataStandardFormat processDataStandardFormat)
{
if (processDataStandardFormat.InputPDSF is null)
throw new NullReferenceException(nameof(processDataStandardFormat.InputPDSF));
#pragma warning disable CA1845, IDE0057
string result;
string line;
string value;
string[] segments;
List<string> lines = new();
for (int i = 0; i < processDataStandardFormat.InputPDSF.Body.Count; i++)
{
line = "{";
segments = processDataStandardFormat.InputPDSF.Body[i].Trim().Split('\t');
if (segments.Length != processDataStandardFormat.InputPDSF.Columns.Count)
break;
for (int c = 0; c < segments.Length; c++)
{
value = segments[c].Replace("\"", "\\\"").Replace("\\", "\\\\");
line += string.Concat('"', processDataStandardFormat.InputPDSF.Columns[c].Trim('"'), '"', ':', '"', value, '"', ',');
}
line = string.Concat(line.Substring(0, line.Length - 1), '}');
lines.Add(line);
}
result = string.Concat(
'{',
Environment.NewLine,
'"',
"Count",
'"',
": ",
processDataStandardFormat.Body.Count,
',',
Environment.NewLine,
'"',
"Records",
'"',
": ",
Environment.NewLine,
'[',
Environment.NewLine,
string.Join($",{Environment.NewLine}", lines),
Environment.NewLine,
']',
',',
Environment.NewLine,
'"',
"Sequence",
'"',
": ",
processDataStandardFormat.Sequence,
Environment.NewLine,
'}');
return result;
#pragma warning restore CA1845, IDE0057
}
internal static void Write(string path, ProcessDataStandardFormat processDataStandardFormat, List<Metrology.WS.Results>? wsResults) internal static void Write(string path, ProcessDataStandardFormat processDataStandardFormat, List<Metrology.WS.Results>? wsResults)
{ {
List<string> results = new(); List<string> results = new();
@ -399,12 +456,12 @@ internal class ProcessDataStandardFormat
results.Add($"{segments[0]}\t{segments[1][0]}_HeaderId={wsResults[0].HeaderId};{segments[1][0]}_SubgroupId={wsResults[0].SubgroupId};{segments[1]}"); results.Add($"{segments[0]}\t{segments[1][0]}_HeaderId={wsResults[0].HeaderId};{segments[1][0]}_SubgroupId={wsResults[0].SubgroupId};{segments[1]}");
} }
} }
results.Add("EOF"); results.Add("END_HEADER");
if (processDataStandardFormat.InputPDSF is not null) if (processDataStandardFormat.InputPDSF is not null)
{ {
results.Add(string.Empty);
List<char> hyphens = new(); List<char> hyphens = new();
results.AddRange(processDataStandardFormat.InputPDSF.Header.Select(l => l.Replace('\t', '|'))); results.AddRange(processDataStandardFormat.InputPDSF.Header.Select(l => l.Replace('\t', '|')));
results.Add(string.Empty);
results.Add($"|{string.Join("|", processDataStandardFormat.InputPDSF.Columns)}|"); results.Add($"|{string.Join("|", processDataStandardFormat.InputPDSF.Columns)}|");
for (int i = 0; i < processDataStandardFormat.InputPDSF.Columns.Count; i++) for (int i = 0; i < processDataStandardFormat.InputPDSF.Columns.Count; i++)
hyphens.Add('-'); hyphens.Add('-');
@ -412,6 +469,11 @@ internal class ProcessDataStandardFormat
results.AddRange(processDataStandardFormat.InputPDSF.Body.Select(l => l.Replace('\t', '|'))); results.AddRange(processDataStandardFormat.InputPDSF.Body.Select(l => l.Replace('\t', '|')));
results.Add(string.Empty); results.Add(string.Empty);
results.AddRange(processDataStandardFormat.InputPDSF.Footer.Select(l => l.Replace('\t', '|'))); results.AddRange(processDataStandardFormat.InputPDSF.Footer.Select(l => l.Replace('\t', '|')));
results.Add(string.Empty);
results.Add("EOF");
results.Add(string.Empty);
string json = GetJson(processDataStandardFormat);
results.Add(json);
} }
File.WriteAllText(path, string.Join(Environment.NewLine, results)); File.WriteAllText(path, string.Join(Environment.NewLine, results));
} }