Init
This commit is contained in:
.gitignoreMETCLIMATEC-Development.ymlMETCLIMATEC.Tests.csprojMETCLIMATEC.ymlappsettings.Development.jsonappsettings.jsonpackage.json
.vscode
Adaptation
.config
.editorconfig.vscode
Eaf
Core
EquipmentCore
Control
AutoGenerated
ChangeDataCollectionHandler.csDataCollectionRequest.csEquipmentEvent.csEquipmentException.csEquipmentSelfDescription.csGetParameterValuesHandler.csIConnectionControl.csIDataTracingHandler.csIEquipmentCommandService.csIEquipmentControl.csIEquipmentSelfDescriptionBuilder.csIPackage.csISelfDescriptionLookup.csIVirtualParameterValuesHandler.csSetParameterValuesHandler.csTraceRequest.cs
IEquipmentDataCollection.csIPackageSource.csDataCollection
Reporting
SelfDescription
ElementDescription
ParameterTypes
Management
ConfigurationData
CellAutomation
Semiconductor
CellInstances
FileHandlers
Ifx
Eaf
Common
Configuration
EquipmentConnector
File
Component
Configuration
SelfDescription
Infineon
Monitoring
PeerGroup
GCL
Shared
Duplicator
FileRead.csLogistics.csLogistics2.csMethods
Metrology
ParameterType.csProcessDataStandardFormat.csProperties
Test.cs_Tests
CreateSelfDescription
Staging
v2.52.0
Extract
Staging
v2.52.0
Shared
AdaptationTesting.csEAFLoggingUnitTesting.csIsEnvironment.cs
Log
ConsoleLogger.csConsoleProvider.csDebugLogger.csDebugProvider.csFeedbackLogger.csFeedbackProvider.csIFeedback.csLog.cs
LoggingUnitTesting.csMethodBaseName.csPasteSpecialXml
UnitTesting.csStatic
FileHandlers
METCLIMATEC.csprojProperties
README.mdShared
130
Adaptation/FileHandlers/csv/ProcessData.cs
Normal file
130
Adaptation/FileHandlers/csv/ProcessData.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Methods;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Adaptation.FileHandlers.csv;
|
||||
|
||||
public class ProcessData : IProcessData
|
||||
{
|
||||
|
||||
private readonly List<object> _Details;
|
||||
|
||||
public string JobID { get; set; }
|
||||
public string MesEntity { get; set; }
|
||||
public MetaData MetaData { get; set; }
|
||||
|
||||
List<object> Shared.Properties.IProcessData.Details => _Details;
|
||||
|
||||
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, CommaSeparatedValuesConfiguration commaSeparatedValuesConfiguration, string csvFile, MetaData metaData)
|
||||
{
|
||||
JobID = logistics.JobID;
|
||||
fileInfoCollection.Clear();
|
||||
_Details = new List<object>();
|
||||
MesEntity = logistics.MesEntity;
|
||||
Parse(fileRead, logistics, fileInfoCollection, commaSeparatedValuesConfiguration, csvFile, metaData);
|
||||
}
|
||||
|
||||
string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors) => throw new Exception(string.Concat("See ", nameof(Parse)));
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IProcessData.GetResults(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
List<Test> tests = new();
|
||||
foreach (object item in _Details)
|
||||
tests.Add(Test.Climatec);
|
||||
List<IDescription> descriptions = fileRead.GetDescriptions(fileRead, tests, this);
|
||||
if (tests.Count != descriptions.Count)
|
||||
throw new Exception();
|
||||
for (int i = 0; i < tests.Count; i++)
|
||||
{
|
||||
if (descriptions[i] is not Description description)
|
||||
throw new Exception();
|
||||
if (description.Test != (int)tests[i])
|
||||
throw new Exception();
|
||||
}
|
||||
List<Description> fileReadDescriptions = (from l in descriptions select (Description)l).ToList();
|
||||
string json = JsonSerializer.Serialize(fileReadDescriptions, fileReadDescriptions.GetType());
|
||||
JsonElement[] jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(logistics.Logistics1[0], tests.ToArray(), jsonElements, fileInfoCollection);
|
||||
return results;
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
|
||||
internal static MetaData? GetMetaData(CommaSeparatedValuesConfiguration commaSeparatedValuesConfiguration, string fileNameWithoutExtension)
|
||||
{
|
||||
MetaData? result;
|
||||
Match match = Regex.Match(fileNameWithoutExtension, commaSeparatedValuesConfiguration.RegularExpressionPattern);
|
||||
if (!match.Success || match.Groups.Count != commaSeparatedValuesConfiguration.RegularExpressionGroupCount)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
int deviceId = int.Parse(match.Groups["DeviceId"].Value);
|
||||
int deviceNumber = int.Parse(match.Groups["DeviceNumber"].Value);
|
||||
result = new()
|
||||
{
|
||||
DeviceId = deviceId,
|
||||
DeviceType = match.Groups["DeviceType"].Value,
|
||||
DeviceNumber = deviceNumber,
|
||||
Description = match.Groups["Description"].Value,
|
||||
Frequency = match.Groups["Frequency"].Value,
|
||||
Date = match.Groups["Date"].Value
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma warning disable IDE0060
|
||||
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, CommaSeparatedValuesConfiguration commaSeparatedValuesConfiguration, string csvFile, MetaData metaData)
|
||||
#pragma warning restore IDE0060
|
||||
{
|
||||
string[] lines = File.ReadAllLines(csvFile);
|
||||
string line = lines[0];
|
||||
string[] columns = line.Split('"');
|
||||
fileInfoCollection.Add(new FileInfo(csvFile));
|
||||
if (columns.Length == commaSeparatedValuesConfiguration.Columns)
|
||||
{
|
||||
string test = columns[commaSeparatedValuesConfiguration.TestIndex].Trim().Trim('"');
|
||||
if (test == metaData.Description)
|
||||
{
|
||||
for (int i = 1; i < lines.Length; i++)
|
||||
{
|
||||
line = lines[i];
|
||||
if (line.Length < 1)
|
||||
continue;
|
||||
columns = line.Split(',').Select(l => l.Trim().Trim('"')).ToArray();
|
||||
if (columns.Length != commaSeparatedValuesConfiguration.Columns)
|
||||
continue;
|
||||
_Details.Add(new Record() { Test = test, Date = columns[0], Value = columns[1], Event = columns[2] });
|
||||
}
|
||||
MetaData = metaData;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static List<Description> GetDescriptions(JsonElement[] jsonElements)
|
||||
{
|
||||
List<Description> results = new();
|
||||
Description? description;
|
||||
JsonSerializerOptions jsonSerializerOptions = new() { NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString };
|
||||
foreach (JsonElement jsonElement in jsonElements)
|
||||
{
|
||||
if (jsonElement.ValueKind != JsonValueKind.Object)
|
||||
throw new Exception();
|
||||
description = JsonSerializer.Deserialize<Description>(jsonElement.ToString(), jsonSerializerOptions);
|
||||
if (description is null)
|
||||
continue;
|
||||
results.Add(description);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user