Skip to content

Commit

Permalink
Merge pull request #181 from lzaslav/operation_data_cleanup
Browse files Browse the repository at this point in the history
Ability to post-process data
  • Loading branch information
Stuart Rhea authored Jun 22, 2022
2 parents e320f1a + babee40 commit 19d1599
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ISOv4Plugin/Mappers/Factories/TimeLogMapperFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.
Expand Down Expand Up @@ -49,20 +51,23 @@ public TimeLogMapperFactory(TaskDataMapper taskDataMapper)
_taskDataMapper = taskDataMapper;
_timeLogMapper = new TimeLogMapper(taskDataMapper);
_multiFileTimeLogMapper = new MultiFileTimeLogMapper(taskDataMapper);

_manufacturer = ManufacturerFactory.GetManufacturer(taskDataMapper);
}

public IEnumerable<OperationData> ImportTimeLogs(ISOTask loggedTask, int? prescriptionID)
{
var timeLogGroups = GetTimeLogGroups(loggedTask);

var opearationDats = new List<OperationData>();
var operationDatas = new List<OperationData>();
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<ISOTimeLog> ExportTimeLogs(IEnumerable<OperationData> operationDatas, string dataPath)
Expand Down
39 changes: 39 additions & 0 deletions ISOv4Plugin/Mappers/Manufacturers/CNH.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -206,5 +210,40 @@ public string GetProductManufacturer(ISOProduct isoProduct)

return productManufacturer;
}


public IEnumerable<OperationData> PostProcessOperationData(TaskDataMapper taskDataMapper, IEnumerable<OperationData> operationDatas)
{
var result = new List<OperationData>();

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;
}
}
}
4 changes: 4 additions & 0 deletions ISOv4Plugin/Mappers/Manufacturers/ManufacturerFactory.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +13,8 @@ internal interface IManufacturer
ProductTypeEnum? GetProductType(ISOProduct isoProduct);
CategoryEnum? GetProductCategory(ISOProduct isoProduct);
string GetProductManufacturer(ISOProduct isoProduct);

IEnumerable<OperationData> PostProcessOperationData(TaskDataMapper taskDataMapper, IEnumerable<OperationData> operationDatas);
}

internal static class ManufacturerFactory
Expand Down

0 comments on commit 19d1599

Please sign in to comment.