diff --git a/ISOv4Plugin/Mappers/Factories/TimeLogMapperFactory.cs b/ISOv4Plugin/Mappers/Factories/TimeLogMapperFactory.cs index fd190ab..49de20f 100644 --- a/ISOv4Plugin/Mappers/Factories/TimeLogMapperFactory.cs +++ b/ISOv4Plugin/Mappers/Factories/TimeLogMapperFactory.cs @@ -7,6 +7,7 @@ using System.Linq; using AgGateway.ADAPT.ApplicationDataModel.LoggedData; using AgGateway.ADAPT.ISOv4Plugin.ISOModels; +using AgGateway.ADAPT.ISOv4Plugin.Mappers.Manufacturers; namespace AgGateway.ADAPT.ISOv4Plugin.Mappers.Factories { @@ -18,6 +19,7 @@ public class TimeLogMapperFactory private readonly TimeLogMapper _timeLogMapper; private readonly MultiFileTimeLogMapper _multiFileTimeLogMapper; private readonly TaskDataMapper _taskDataMapper; + private readonly IManufacturer _manufacturer; // A wrapper class to hold together ISOTimeLog and included ISODataLogValues. // This avoids multiple calls to ISOTimeLog.GetTimeElement() which performs xml parsing on each call. @@ -49,20 +51,23 @@ public TimeLogMapperFactory(TaskDataMapper taskDataMapper) _taskDataMapper = taskDataMapper; _timeLogMapper = new TimeLogMapper(taskDataMapper); _multiFileTimeLogMapper = new MultiFileTimeLogMapper(taskDataMapper); + + _manufacturer = ManufacturerFactory.GetManufacturer(taskDataMapper); } public IEnumerable ImportTimeLogs(ISOTask loggedTask, int? prescriptionID) { var timeLogGroups = GetTimeLogGroups(loggedTask); - var opearationDats = new List(); + var operationDatas = new List(); foreach (var timeLogGroup in timeLogGroups) { - opearationDats.AddRange(timeLogGroup.Count > 1 + operationDatas.AddRange(timeLogGroup.Count > 1 ? _multiFileTimeLogMapper.ImportTimeLogs(loggedTask, timeLogGroup, prescriptionID) : _timeLogMapper.ImportTimeLogs(loggedTask, timeLogGroup, prescriptionID)); } - return opearationDats; + + return _manufacturer?.PostProcessOperationData(_taskDataMapper, operationDatas) ?? operationDatas; } public IEnumerable ExportTimeLogs(IEnumerable operationDatas, string dataPath) diff --git a/ISOv4Plugin/Mappers/Manufacturers/CNH.cs b/ISOv4Plugin/Mappers/Manufacturers/CNH.cs index 393f9f4..574397b 100644 --- a/ISOv4Plugin/Mappers/Manufacturers/CNH.cs +++ b/ISOv4Plugin/Mappers/Manufacturers/CNH.cs @@ -1,6 +1,10 @@ using System.Collections.Generic; using System.Globalization; +using System.Linq; +using AgGateway.ADAPT.ApplicationDataModel.Common; +using AgGateway.ADAPT.ApplicationDataModel.LoggedData; using AgGateway.ADAPT.ApplicationDataModel.Products; +using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods; using AgGateway.ADAPT.ISOv4Plugin.ISOModels; namespace AgGateway.ADAPT.ISOv4Plugin.Mappers.Manufacturers @@ -206,5 +210,40 @@ public string GetProductManufacturer(ISOProduct isoProduct) return productManufacturer; } + + + public IEnumerable PostProcessOperationData(TaskDataMapper taskDataMapper, IEnumerable operationDatas) + { + var result = new List(); + + var catalog = taskDataMapper.AdaptDataModel.Catalog; + foreach (var operationData in operationDatas) + { + var deviceModels = operationData.GetAllSections() + .Select(x => catalog.DeviceElementConfigurations.FirstOrDefault(y => y.Id.ReferenceId == x.DeviceConfigurationId)) + .Where(x => x != null) + .Select(x => catalog.DeviceElements.FirstOrDefault(y => y.Id.ReferenceId == x.DeviceElementId)) + .Where(x => x != null) + .Select(x => x.DeviceModelId) + .Distinct() + .Select(x => catalog.DeviceModels.FirstOrDefault(y => y.Id.ReferenceId == x)) + .Where(x => x != null) + .ToList(); + if (deviceModels.Count == 1 && !string.IsNullOrWhiteSpace(deviceModels[0].Description)) + { + var trimmed = deviceModels[0].Description.Trim(); + if (trimmed.EqualsIgnoreCase("Trip Computer Data")) + { + operationData.OperationType = OperationTypeEnum.DataCollection; + } + else if (trimmed.EqualsIgnoreCase("Vehicle Geometry")) + { + continue; + } + } + result.Add(operationData); + } + return result; + } } } diff --git a/ISOv4Plugin/Mappers/Manufacturers/ManufacturerFactory.cs b/ISOv4Plugin/Mappers/Manufacturers/ManufacturerFactory.cs index a12d46d..025cb1f 100644 --- a/ISOv4Plugin/Mappers/Manufacturers/ManufacturerFactory.cs +++ b/ISOv4Plugin/Mappers/Manufacturers/ManufacturerFactory.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using AgGateway.ADAPT.ApplicationDataModel.LoggedData; using AgGateway.ADAPT.ApplicationDataModel.Products; using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods; using AgGateway.ADAPT.ISOv4Plugin.ISOModels; @@ -11,6 +13,8 @@ internal interface IManufacturer ProductTypeEnum? GetProductType(ISOProduct isoProduct); CategoryEnum? GetProductCategory(ISOProduct isoProduct); string GetProductManufacturer(ISOProduct isoProduct); + + IEnumerable PostProcessOperationData(TaskDataMapper taskDataMapper, IEnumerable operationDatas); } internal static class ManufacturerFactory