This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,155 @@
using DataPROWin7.DataModel;
using DTS.Common.Classes.Groups;
using DTS.Common.Classes.Sensors;
using DTS.Common.Interface.Groups.GroupList;
using DTS.Common.Storage;
using DTS.SensorDB;
using System;
using System.Collections.Generic;
using System.Linq;
//FB 36879 This class handles eqx group process logic
namespace DTS.Common.Import
{
public class EQXGroupImport : IGroupImport
{
public ParseParameters ParseParameters { get; set; }
public Tuple<TestTemplate, List<IGroup>> CreateGroups(List<SensorData> sensors, Dictionary<string, List<TsetSetupImportSensorInfo>> groupSensorLookup, TestTemplate testTemplate, bool createDynamicGroups, List<IGroup> staticGroups, Action<double> setProgress)
{
var channelDefaults = DbOperations.GetChannelSettingDefaults();
var sensorLookup = sensors.ToDictionary(s => s.SerialNumber);
if (groupSensorLookup == null || !groupSensorLookup.Any())
{
return null;
}
int total = groupSensorLookup.Count;
int current = 0;
var displayOrder = 1;
var sensorSerialHash = new HashSet<string>();
var groupList = new List<Tuple<string, int>>();
foreach( var group in groupSensorLookup) { groupList.Add(new Tuple<string, int>(group.Key, group.Value.Count)); }
groupList.Sort((a, b) =>
{
if ( a.Item2 == b.Item2) { return a.Item1.CompareTo(b.Item1); }
return b.Item2.CompareTo(a.Item2);
});
foreach (var groupTuple in groupList)
{
// Make your template
var newGroup = GroupHelper.CreateEmptyGroup();
newGroup.Name = groupTuple.Item1;
newGroup.DisplayName = newGroup.Name;
var importTemplateChannelList = groupSensorLookup[groupTuple.Item1];
List<Interface.Channels.IGroupChannel> groupChannels = new List<Interface.Channels.IGroupChannel>();
var testGroupChannels = 0;
foreach (var ch in importTemplateChannelList)
{
var groupChannel = new GroupChannel(false, newGroup.DisplayName, newGroup, channelDefaults);
groupChannel.IsoCode = ch.IsoCode;
if (sensorLookup.ContainsKey(ch.SerialNumber))
{
var sd = sensorLookup[ch.SerialNumber];
groupChannel.IsoChannelName = sd.ISOChannelName;
groupChannel.UserChannelName = sd.Comment;
groupChannel.SetSensorData(sd, null);
groupChannel.SensorId = sd.DatabaseId;
groupChannel.Range = sd.Capacity;
groupChannel.FilterClass = sd.FilterClass;
groupChannel.Polarity = sd.Polarity;
groupChannel.IsoCode = sd.ISOCode;
groupChannel.SquibLimitDuration = sd.LimitSquibFireDuration;
groupChannel.SquibDuration = sd.SquibFireDurationMS;
groupChannel.SquibDelay = sd.SquibFireDelayMS;
groupChannel.SquibFireMode = sd.SquibFireMode;
groupChannel.SquibCurrent = sd.SquibOutputCurrent;
groupChannel.DigitalOutputMode = sd.DigitalOutputMode;
groupChannel.DigitalOutDelay = sd.DigitalOutputDelayMS;
groupChannel.DigitalOutDuration = sd.DigitalOutputDurationMS;
groupChannel.DigitalInputMode = sd.InputMode;
groupChannel.ActiveValue = sd.InputActiveValue.ToString("N0");
groupChannel.DefaultValue = sd.InputDefaultValue.ToString("N0");
if (null != sd.Calibration)
{
//FB 36905 & 35530 check for null
groupChannel.ZeroMethod = sd.Calibration.ZeroMethods.Methods[0].Method;
groupChannel.ZeroMethodStart = sd.Calibration.ZeroMethods.Methods[0].Start;
groupChannel.ZeroMethodEnd = sd.Calibration.ZeroMethods.Methods[0].End;
groupChannel.AvailableInitialOffsets = sd.Calibration.InitialOffsets.Offsets;
groupChannel.InitialOffset = sd.Calibration.InitialOffsets.DefaultOffset;
}
groupChannel.GroupChannelOrder = 1 + sensors.IndexOf(sd);
groupChannel.TestSetupOrder = 1 + sensors.IndexOf(sd);
if ( !sensorSerialHash.Contains(sd.SerialNumber))
{
sensorSerialHash.Add(sd.SerialNumber);
testGroupChannels++;
}
}
groupChannels.Add(groupChannel);
}
newGroup.GroupChannelList = groupChannels;
if (!createDynamicGroups)
{
staticGroups.Add(newGroup);
}
newGroup.DisplayOrder = displayOrder++;
if (testGroupChannels > 0)
{
testTemplate.Groups.Add(newGroup);
testTemplate.ChannelsForGroup[newGroup] = groupChannels.ToArray();
}
setProgress(100D * current / total);
current++;
}
return Tuple.Create(testTemplate, staticGroups);
}
public Dictionary<string, List<TsetSetupImportSensorInfo>> GetGroupSensorLookup(List<SensorData> sensors, Dictionary<string, string> sensorGroupNameLookup, Dictionary<string, List<string>> groupNameSensorListLookup)
{
Dictionary<string, List<TsetSetupImportSensorInfo>> groupSensorLookup = new Dictionary<string, List<TsetSetupImportSensorInfo>>();
//FB 30358 Either sensorGroupNameLookup or groupNameSensorListLookup will be populated. dependes on the child class
if (sensorGroupNameLookup != null && sensorGroupNameLookup.Any())
{
groupSensorLookup = sensorGroupNameLookup?.Values.Distinct().AsEnumerable().
ToDictionary(groupName => groupName, groupName => new List<TsetSetupImportSensorInfo>());
foreach (var s in sensors)
{
// Build the group sensor and group type dictionary
if (!sensorGroupNameLookup.ContainsKey(s.SerialNumber)) continue;
// add to group dictionary
groupSensorLookup[sensorGroupNameLookup[s.SerialNumber]].Add(new TsetSetupImportSensorInfo(s.SerialNumber, s.ISOCode));
}
}
if (groupNameSensorListLookup != null && groupNameSensorListLookup.Any())
{
foreach (var g in groupNameSensorListLookup)
{
groupSensorLookup.Add(g.Key, new List<TsetSetupImportSensorInfo>());
foreach (var sensorSerialNumber in g.Value)
{
var sd = sensors.Find(s => s.SerialNumber == sensorSerialNumber);
if (sd != null)
{
groupSensorLookup[g.Key].Add(new TsetSetupImportSensorInfo(sd.SerialNumber, sd.ISOCode));
}
}
}
}
return groupSensorLookup;
}
}
}