176 lines
7.5 KiB
C#
176 lines
7.5 KiB
C#
using DataPROWin7.DataModel;
|
|
using DTS.Common.Classes;
|
|
using DTS.Common.Classes.Sensors;
|
|
using DTS.Common.Import.Interfaces;
|
|
using DTS.Common.Interface.Groups.GroupList;
|
|
using DTS.SensorDB;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DTS.Common.Import
|
|
{
|
|
public static class GroupHelper
|
|
{
|
|
//FB 36879 Single responsibility principle , moved group realted utility methods to this class
|
|
public static IGroup CreateEmptyGroup()
|
|
{
|
|
return new GroupList.Model.Group(true);
|
|
}
|
|
|
|
public static void GetTestSensorParameters(out string isoCode, out string isoChannelName, out string userCode, out string userChannelName,
|
|
ParseParameters pp, SensorData sd, out string dasSerialNumber, out int dasChannelIdx)
|
|
{
|
|
isoCode = sd.ISOCode;
|
|
if (pp.SensorISOCode.ContainsKey(sd.SerialNumber)) { isoCode = pp.SensorISOCode[sd.SerialNumber]; }
|
|
|
|
isoChannelName = sd.ISOChannelName;
|
|
if (pp.SensorISOChannelName.ContainsKey(sd.SerialNumber)) { isoChannelName = pp.SensorISOChannelName[sd.SerialNumber]; }
|
|
|
|
userCode = sd.UserCode;
|
|
if (pp.SensorUserCode.ContainsKey(sd.SerialNumber)) { userCode = pp.SensorUserCode[sd.SerialNumber]; }
|
|
|
|
userChannelName = sd.UserChannelName;
|
|
if (pp.SensorUserChannelName.ContainsKey(sd.SerialNumber)) { userChannelName = pp.SensorUserChannelName[sd.SerialNumber]; }
|
|
|
|
dasSerialNumber = string.Empty;
|
|
if (pp.SensorDASSerialNumber.ContainsKey(sd.SerialNumber)) { dasSerialNumber = pp.SensorDASSerialNumber[sd.SerialNumber]; }
|
|
|
|
dasChannelIdx = -1;
|
|
if (pp.SensorDASChannelIndex.ContainsKey(sd.SerialNumber)) { dasChannelIdx = pp.SensorDASChannelIndex[sd.SerialNumber]; }
|
|
}
|
|
public static IReadOnlyDictionary<string, int> GetDAS(Dictionary<string, List<TsetSetupImportSensorInfo>> groupSensorLookupgroupSensorLookup,
|
|
DASHardware[] allDAS)
|
|
{
|
|
var lookup = new Dictionary<string, int>();
|
|
using (var e = groupSensorLookupgroupSensorLookup.GetEnumerator())
|
|
{
|
|
while (e.MoveNext())
|
|
{
|
|
var list = e.Current.Value;
|
|
foreach (var sensorDASSerialNumber in list.Select(s => s.DASSerialNumber))
|
|
{
|
|
if (!string.IsNullOrEmpty(sensorDASSerialNumber))
|
|
{
|
|
if (lookup.ContainsKey(sensorDASSerialNumber)) { continue; }
|
|
var das = Array.Find(allDAS, d => d.SerialNumber.Equals(sensorDASSerialNumber));
|
|
if (null == das) { continue; }
|
|
lookup[sensorDASSerialNumber] = das.DASId;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return lookup;
|
|
}
|
|
|
|
public static int? GetGroupId(TestTestObject testObject, Dictionary<string, int> groupIdMapping, List<TestObject> groupList)
|
|
{
|
|
foreach (var group in groupList)
|
|
{
|
|
if (group.SerialNumber == testObject.SerialNumber)
|
|
{
|
|
//Found the embedded Group, now find the static Group
|
|
foreach (var serialNumber in groupList.Select(p => p.SerialNumber))
|
|
{
|
|
if (serialNumber == group.GetISOTestObject().OriginalSerialNumber)
|
|
{
|
|
if (groupIdMapping.ContainsKey(serialNumber))
|
|
{
|
|
return groupIdMapping[serialNumber];
|
|
}
|
|
else
|
|
{
|
|
//Must not be from a static Group
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static List<string> ReverseChannelOrder(TestTemplate testTemplate, Dictionary<string, string> sensorGroupNameLookup, List<SensorData> sensors)
|
|
{
|
|
var orders = new List<string>();
|
|
//store the original channel order
|
|
//note that for some reason the channels are reversed
|
|
//I don't change that, I just make sure that when I set the channel order
|
|
//it's not reversed ...
|
|
if (sensors == null) { return orders; }
|
|
|
|
if (testTemplate == null) { return orders; }
|
|
|
|
if (sensorGroupNameLookup != null && sensorGroupNameLookup.Any())
|
|
{
|
|
foreach (var ch in sensors)
|
|
{
|
|
orders.Add($"{testTemplate.Name}_{sensorGroupNameLookup[ch.SerialNumber]}_{ch.Comment}");
|
|
}
|
|
orders.Reverse();
|
|
}
|
|
return orders;
|
|
}
|
|
|
|
public static List<SensorData> CleanUneededSensorDataPlaceHolder(Dictionary<string, List<SensorCalibration>> calibrationLookup, List<SensorData> sensorList)
|
|
{
|
|
|
|
// Cleanup unneeded sensor data place holders
|
|
for (int i = sensorList.Count - 1; i >= 0; i--)
|
|
{
|
|
if (sensorList[i].SerialNumber.StartsWith(Constants.ISO_CH_ONLY_PREFIX))
|
|
{
|
|
// Only an ISO channel
|
|
sensorList.RemoveAt(i);
|
|
}
|
|
else if (sensorList[i].IsSquib() || sensorList[i].IsStreamOutput() || sensorList[i].IsUart() || sensorList[i].IsStreamInput()
|
|
|| sensorList[i].IsDigitalInput() || sensorList[i].IsCan())
|
|
{
|
|
//DON'T REMOVE, doesn't have a calibration.
|
|
}
|
|
else if (calibrationLookup[sensorList[i].SerialNumber].Exists(sc => sc.CalibrationDate == DateTime.MinValue))
|
|
{
|
|
// invalid default cal
|
|
// likely incomplete sensor reference
|
|
// Don't try to import this
|
|
sensorList.RemoveAt(i);
|
|
}
|
|
}
|
|
|
|
return sensorList;
|
|
}
|
|
|
|
public static List<SensorData> NormalizeSensorIds(List<SensorData> sensorList)
|
|
{
|
|
if(sensorList == null) { return new List<SensorData>(); }
|
|
|
|
//normalize sensor ids
|
|
for (int i = 0; i < sensorList.Count; i++)
|
|
{
|
|
var existing = SensorsCollection.SensorsList.GetSensorBySerialNumber(sensorList[i].SerialNumber);
|
|
|
|
if (null != existing && existing.IsAnalog())
|
|
{
|
|
//FB 41866 If the calibration is null use the one from parsed file
|
|
existing.Calibration = SensorCalibrationList.GetLatestCalibrationBySerialNumber(existing) ?? existing.Calibration;
|
|
}
|
|
|
|
if (existing != null)
|
|
{
|
|
sensorList[i].DatabaseId = existing.DatabaseId;
|
|
sensorList[i].Calibration = existing.Calibration;
|
|
}
|
|
else
|
|
{
|
|
//normalize to -2 ... -n (-1 preserved for no sensor)
|
|
sensorList[i].DatabaseId = -1 * (2 + i);
|
|
}
|
|
|
|
}
|
|
return sensorList;
|
|
}
|
|
}
|
|
}
|