CSV like PDSF ready to test
This commit is contained in:
205
Adaptation/FileHandlers/QS408M/Run.cs
Normal file
205
Adaptation/FileHandlers/QS408M/Run.cs
Normal file
@ -0,0 +1,205 @@
|
||||
using Adaptation.Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Adaptation.FileHandlers.QS408M;
|
||||
|
||||
#nullable enable
|
||||
|
||||
internal class Run
|
||||
{
|
||||
|
||||
public Run(Header header, ReadOnlyCollection<Site> sites, Body body, Footer footer)
|
||||
{
|
||||
Header = header;
|
||||
Sites = sites;
|
||||
Body = body;
|
||||
Footer = footer;
|
||||
}
|
||||
|
||||
public Header Header { get; }
|
||||
public ReadOnlyCollection<Site> Sites { get; }
|
||||
public Body Body { get; }
|
||||
public Footer Footer { get; }
|
||||
|
||||
internal static string GetBefore(string text, int[] i, string search)
|
||||
{
|
||||
string str;
|
||||
string str1;
|
||||
int num = text.IndexOf(search, i[0]);
|
||||
if (num <= -1)
|
||||
{
|
||||
str = text.Substring(i[0]);
|
||||
i[0] = text.Length;
|
||||
str1 = str.Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
str = text.Substring(i[0], num - i[0]);
|
||||
i[0] = num + search.Length;
|
||||
str1 = str.Trim();
|
||||
}
|
||||
return str1;
|
||||
}
|
||||
|
||||
internal static string GetToEOL(string text, int[] i)
|
||||
{
|
||||
string result;
|
||||
if (text.IndexOf("\n", i[0]) > -1)
|
||||
result = GetBefore(text, i, "\n");
|
||||
else
|
||||
result = GetBefore(text, i, Environment.NewLine);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int ScanPast(string text, int[] i, string search)
|
||||
{
|
||||
int result;
|
||||
int num = text.IndexOf(search, i[0]);
|
||||
if (num <= -1)
|
||||
result = text.Length;
|
||||
else
|
||||
result = num + search.Length;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteJson(Logistics logistics, List<FileInfo> fileInfoCollection, Run? result)
|
||||
{
|
||||
FileInfo fileInfo = new($"{logistics.ReportFullPath}.json");
|
||||
string json = JsonSerializer.Serialize(result, RunSourceGenerationContext.Default.Run);
|
||||
File.WriteAllText(fileInfo.FullName, json);
|
||||
File.SetLastWriteTime(fileInfo.FullName, logistics.DateTimeFromSequence);
|
||||
fileInfoCollection.Add(fileInfo);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetLines(JsonElement[]? jsonElements)
|
||||
{
|
||||
List<string> results = new();
|
||||
int columns = 0;
|
||||
StringBuilder stringBuilder = new();
|
||||
for (int i = 0; i < jsonElements?.Length;)
|
||||
{
|
||||
foreach (JsonProperty jsonProperty in jsonElements[0].EnumerateObject())
|
||||
{
|
||||
columns += 1;
|
||||
_ = stringBuilder.Append('"').Append(jsonProperty.Name).Append('"').Append('\t');
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (jsonElements?.Length != 0)
|
||||
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
|
||||
results.Add(stringBuilder.ToString());
|
||||
for (int i = 0; i < jsonElements?.Length; i++)
|
||||
{
|
||||
_ = stringBuilder.Clear();
|
||||
foreach (JsonProperty jsonProperty in jsonElements[i].EnumerateObject())
|
||||
{
|
||||
if (jsonProperty.Value.ValueKind == JsonValueKind.Object)
|
||||
_ = stringBuilder.Append('\t');
|
||||
else if (jsonProperty.Value.ValueKind != JsonValueKind.String)
|
||||
_ = stringBuilder.Append(jsonProperty.Value).Append('\t');
|
||||
else
|
||||
_ = stringBuilder.Append('"').Append(jsonProperty.Value).Append('"').Append('\t');
|
||||
}
|
||||
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
|
||||
results.Add(stringBuilder.ToString());
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetLines(JsonElement? jsonElement) =>
|
||||
jsonElement is null ? new(Array.Empty<string>()) : GetLines(new JsonElement[] { jsonElement.Value });
|
||||
|
||||
private static void WriteTabSeparatedValues(Logistics logistics, List<FileInfo> fileInfoCollection, Run run)
|
||||
{
|
||||
List<Row> results = new();
|
||||
Row row;
|
||||
FileInfo fileInfo = new($"{logistics.ReportFullPath}.tsv");
|
||||
for (int i = 0; i < run.Sites.Count; i++)
|
||||
{
|
||||
row = new(run, i);
|
||||
results.Add(row);
|
||||
}
|
||||
string json = JsonSerializer.Serialize(results);
|
||||
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
|
||||
ReadOnlyCollection<string> lines = GetLines(jsonElements);
|
||||
File.WriteAllText(fileInfo.FullName, string.Join(Environment.NewLine, lines));
|
||||
File.SetLastWriteTime(fileInfo.FullName, logistics.DateTimeFromSequence);
|
||||
fileInfoCollection.Add(fileInfo);
|
||||
}
|
||||
|
||||
private static void WriteException(Logistics logistics, Exception ex)
|
||||
{
|
||||
FileInfo fileInfo = new($"{logistics.ReportFullPath}.{nameof(Exception)}.txt");
|
||||
File.WriteAllText(fileInfo.FullName, $"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
|
||||
}
|
||||
|
||||
internal static Run? Get(Logistics logistics, List<FileInfo> fileInfoCollection, Header[] lastHeader)
|
||||
{
|
||||
Run? result;
|
||||
int[] i = new int[] { 0 };
|
||||
string text = File.ReadAllText(logistics.ReportFullPath);
|
||||
Header? header = Header.Get(lastHeader, text, i);
|
||||
if (header is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
ReadOnlyCollection<Site> sites = Site.Get(text, i);
|
||||
if (sites.Count == 0)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
Body? body = Body.Get(text, i);
|
||||
if (body is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
Footer? footer = Footer.Get(text, i);
|
||||
if (footer is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
result = new(header, sites, body, footer);
|
||||
WriteJson(logistics, fileInfoCollection, result);
|
||||
try
|
||||
{
|
||||
WriteTabSeparatedValues(logistics, fileInfoCollection, result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteException(logistics, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Bio-Rad QS400MEPI Recipe: EP_8IN9PT Thu Apr 30 11:29:10 1970
|
||||
// operator: J batch: BIORAD#2
|
||||
// cassette: wafer: 52-589368-4445
|
||||
// --------------------------------------------------------------------------------
|
||||
// position thickness position thickness position thickness
|
||||
// 1 45.735 2 46.536 3 46.742
|
||||
// 4 46.015 5 46.648 6 45.366
|
||||
// 7 46.263 8 46.512 9 46.373
|
||||
// wafer mean thickness = 46.2433, std. dev = 0.4564 PASS
|
||||
// ================================================================================
|
||||
|
||||
// Radial variation (computation B) PASS:
|
||||
|
||||
// thickness -2.7474
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Run))]
|
||||
internal partial class RunSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user