Skip to content

Commit

Permalink
Merge pull request #111 from ADAPT/develop
Browse files Browse the repository at this point in the history
Merging pending changes to Master
  • Loading branch information
strhea authored Jun 24, 2020
2 parents 76cc189 + 57f0597 commit 4eb3042
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 35 deletions.
12 changes: 5 additions & 7 deletions ISOv4Plugin/Mappers/ConnectionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
{
public interface IConnectionMapper
{
IEnumerable<ISOConnection> ExportConnections(int loggedDataOrWorkItemID, IEnumerable<EquipmentConfiguration> adaptConnections);
ISOConnection ExportConnection(int loggedDataOrWorkItemID, EquipmentConfiguration adaptConnection);
IEnumerable<ISOConnection> ExportConnections(ISOTask task, IEnumerable<EquipmentConfiguration> adaptConnections);
ISOConnection ExportConnection(ISOTask task, EquipmentConfiguration adaptConnection);

IEnumerable<EquipmentConfiguration> ImportConnections(ISOTask isoTask);
EquipmentConfiguration ImportConnection(ISOTask isoTask, ISOConnection isoConnection);
Expand All @@ -37,18 +37,18 @@ public ConnectionMapper(TaskDataMapper taskDataMapper) : base(taskDataMapper, "C
}

#region Export
public IEnumerable<ISOConnection> ExportConnections(int loggedDataOrWorkItemID, IEnumerable<EquipmentConfiguration> adaptConnections)
public IEnumerable<ISOConnection> ExportConnections(ISOTask task, IEnumerable<EquipmentConfiguration> adaptConnections)
{
List <ISOConnection> connections = new List<ISOConnection>();
foreach (EquipmentConfiguration adaptConnection in adaptConnections)
{
ISOConnection isoConnection = ExportConnection(loggedDataOrWorkItemID, adaptConnection);
ISOConnection isoConnection = ExportConnection(task, adaptConnection);
connections.Add(isoConnection);
}
return connections;
}

public ISOConnection ExportConnection(int loggedDataOrWorkItemID, EquipmentConfiguration adaptConnection)
public ISOConnection ExportConnection(ISOTask task, EquipmentConfiguration adaptConnection)
{
ISOConnection isoConnection = new ISOConnection();

Expand Down Expand Up @@ -97,8 +97,6 @@ public ISOConnection ExportConnection(int loggedDataOrWorkItemID, EquipmentConfi
//DataLogTriggers
if (adaptConnection.DataLogTriggers.Any())
{
string taskID = TaskDataMapper.InstanceIDMap.GetISOID(loggedDataOrWorkItemID);
ISOTask task = TaskDataMapper.ISOTaskData.ChildElements.OfType<ISOTask>().First(t => t.TaskID == taskID);
DataLogTriggerMapper dltMapper = new DataLogTriggerMapper(TaskDataMapper);
task.DataLogTriggers = dltMapper.ExportDataLogTriggers(adaptConnection.DataLogTriggers).ToList();
}
Expand Down
10 changes: 5 additions & 5 deletions ISOv4Plugin/Mappers/DataLogTriggerMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public ISODataLogTrigger ExportDataLogTrigger(DataLogTrigger adaptDataLogTrigger
{
isoDataLogTrigger.DataLogDDI = ddi.Value.AsHexDDI();
isoDataLogTrigger.DataLogMethod = ExportDataLogMethod(adaptDataLogTrigger.DataLogMethod);
isoDataLogTrigger.DataLogDistanceInterval = adaptDataLogTrigger.DataLogDistanceInterval.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogTimeInterval = adaptDataLogTrigger.DataLogTimeInterval.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogThresholdMinimum = adaptDataLogTrigger.DataLogThresholdMinimum.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogThresholdMaximum = adaptDataLogTrigger.DataLogThresholdMaximum.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogThresholdChange = adaptDataLogTrigger.DataLogThresholdChange.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogDistanceInterval = adaptDataLogTrigger.DataLogDistanceInterval?.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogTimeInterval = adaptDataLogTrigger.DataLogTimeInterval?.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogThresholdMinimum = adaptDataLogTrigger.DataLogThresholdMinimum?.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogThresholdMaximum = adaptDataLogTrigger.DataLogThresholdMaximum?.AsIntViaMappedDDI(RepresentationMapper);
isoDataLogTrigger.DataLogThresholdChange = adaptDataLogTrigger.DataLogThresholdChange?.AsIntViaMappedDDI(RepresentationMapper);
if (adaptDataLogTrigger.DeviceElementId.HasValue)
{
isoDataLogTrigger.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(adaptDataLogTrigger.DeviceElementId.Value);
Expand Down
3 changes: 2 additions & 1 deletion ISOv4Plugin/Mappers/DeviceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public ISODevice ExportDevice(DeviceModel adaptDevice)
dvc.DeviceDesignator = adaptDevice.Description;

//Device Elements
IEnumerable<DeviceElement> deviceElements = DataModel.Catalog.DeviceElements.Where(d => d.ParentDeviceId == adaptDevice.Id.ReferenceId);
IEnumerable<DeviceElement> deviceElements = DataModel.Catalog.DeviceElements.Where(d => d.ParentDeviceId == adaptDevice.Id.ReferenceId ||
(d.ParentDeviceId == 0 && d.DeviceModelId == adaptDevice.Id.ReferenceId));
if (deviceElements.Any())
{
dvc.DeviceElements = _deviceElementMapper.ExportDeviceElements(deviceElements, dvc).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
{
public interface IEnumeratedValueMapper
{
UInt32 Map(EnumeratedWorkingData currentMeter, List<WorkingData> meters, SpatialRecord spatialRecord);
UInt32? Map(EnumeratedWorkingData currentMeter, List<WorkingData> meters, SpatialRecord spatialRecord);
}

public class EnumeratedValueMapper : IEnumeratedValueMapper
Expand All @@ -33,9 +33,14 @@ public EnumeratedValueMapper(IEnumeratedMeterFactory enumeratedMeterFactory, IRe
_representationMapper = representationMapper;
}

public UInt32 Map(EnumeratedWorkingData currentMeter, List<WorkingData> meters, SpatialRecord spatialRecord)
public UInt32? Map(EnumeratedWorkingData currentMeter, List<WorkingData> meters, SpatialRecord spatialRecord)
{
var ddi = _representationMapper.Map(currentMeter.Representation);
if (ddi == null)
{
return null;
}

var creator = _enumeratedMeterFactory.GetMeterCreator(ddi.GetValueOrDefault());
//The intent of the meters parameter below is to send in those meters that reconcile to a single DLV.
//Since we are not exporting condensed DDIS at this time, just passing in the collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using AgGateway.ADAPT.ApplicationDataModel.LoggedData;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;
using AgGateway.ADAPT.Representation.RepresentationSystem;
using AgGateway.ADAPT.Representation.RepresentationSystem.ExtensionMethods;
Expand All @@ -20,7 +21,7 @@ public ActualLoadingSystemStatusMeterCreator(int ddi)
DDI = ddi;
}

public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows)
public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv)
{
var unloadingMeter = new ISOEnumeratedMeter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using EnumeratedRepresentation = AgGateway.ADAPT.ApplicationDataModel.Representations.EnumeratedRepresentation;
using EnumerationMember = AgGateway.ADAPT.Representation.RepresentationSystem.EnumerationMember;
using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;

namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
{
Expand Down Expand Up @@ -102,15 +103,16 @@ public abstract class CondensedStateMeterCreator : IEnumeratedMeterCreator

public Dictionary<int, EnumerationMember> SectionValueToEnumerationMember { get; set; }

public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows)
public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv)
{
//We need to find a row of data with the value in order to create the correct number of meters.
var spatialRowWithDdi = spatialRows.FirstOrDefault(x => x.SpatialValues.Any(y => y.DataLogValue.ProcessDataDDI.AsInt32DDI() == DDI));

int numberOfSections = 0;
if (spatialRowWithDdi != null)
{
var spatialValue = spatialRowWithDdi.SpatialValues.First(x => x.DataLogValue.ProcessDataDDI.AsInt32DDI() == DDI);
var spatialValue = spatialRowWithDdi.SpatialValues.First(x => x.DataLogValue.ProcessDataDDI.AsInt32DDI() == DDI &&
x.DataLogValue.DeviceElementIdRef == dlv.DeviceElementIdRef);
numberOfSections = GetNumberOfInstalledSections(spatialValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using AgGateway.ADAPT.ApplicationDataModel.LoggedData;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;
using AgGateway.ADAPT.Representation.RepresentationSystem;
using AgGateway.ADAPT.Representation.RepresentationSystem.ExtensionMethods;
Expand All @@ -20,7 +21,7 @@ public ConnectorTypeMeterCreator(int ddi)
DDI = ddi;
}

public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows)
public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv)
{
var meter = new ISOEnumeratedMeter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;
using System;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;

namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
{
public interface IEnumeratedMeterCreator
{
int DDI { get; set; }
int StartingSection { get; }
List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows); //CondensedWorkstateMeter is necessarily forcing CreateMeters process to read spatial data to create meters.
List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv); //CondensedWorkstateMeter is necessarily forcing CreateMeters process to read spatial data to create meters.
EnumeratedValue GetValueForMeter(SpatialValue value, ISOEnumeratedMeter workingData);
UInt32 GetMetersValue(List<WorkingData> meters, SpatialRecord spatialRecord);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using AgGateway.ADAPT.ApplicationDataModel.LoggedData;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;
using AgGateway.ADAPT.Representation.RepresentationSystem;
using AgGateway.ADAPT.Representation.RepresentationSystem.ExtensionMethods;
Expand All @@ -20,7 +21,7 @@ public NetWeightStateMeterCreator(int ddi)
DDI = ddi;
}

public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows)
public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv)
{
var meter = new ISOEnumeratedMeter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using AgGateway.ADAPT.ApplicationDataModel.LoggedData;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;
using AgGateway.ADAPT.Representation.RepresentationSystem;
using AgGateway.ADAPT.Representation.RepresentationSystem.ExtensionMethods;
Expand All @@ -21,7 +22,7 @@ public PrescriptionControlMeterCreator(int ddi)
public int DDI { get; set; }
public int StartingSection { get; private set; }

public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows)
public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv)
{
var meter = new ISOEnumeratedMeter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using AgGateway.ADAPT.ApplicationDataModel.LoggedData;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;
using AgGateway.ADAPT.Representation.RepresentationSystem;
using AgGateway.ADAPT.Representation.RepresentationSystem.ExtensionMethods;
Expand All @@ -20,7 +21,7 @@ public SectionControlStateMeterCreator(int ddi)
DDI = ddi;
}

public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows)
public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv)
{
var meter = new ISOEnumeratedMeter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using AgGateway.ADAPT.Representation.RepresentationSystem;
using AgGateway.ADAPT.Representation.RepresentationSystem.ExtensionMethods;
using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;

namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
{
Expand All @@ -21,7 +22,7 @@ public SkyConditionsMeterCreator(int ddi)
DDI = ddi;
}

public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows)
public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv)
{
var meter = new ISOEnumeratedMeter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using AgGateway.ADAPT.ApplicationDataModel.LoggedData;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;
using AgGateway.ADAPT.Representation.RepresentationSystem;
using AgGateway.ADAPT.Representation.RepresentationSystem.ExtensionMethods;
Expand All @@ -20,7 +21,7 @@ public WorkStateMeterCreator(int ddi)
public int DDI { get; set; }
public int StartingSection { get; private set; }

public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows)
public List<ISOEnumeratedMeter> CreateMeters(IEnumerable<ISOSpatialRow> spatialRows, ISODataLogValue dlv)
{
var meter = new ISOEnumeratedMeter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private IEnumerable<WorkingData> Map(ISODataLogValue dlv,
if (meterCreator != null)
{
//Enumerated Representations
var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows);
var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows, dlv);
foreach (ISOEnumeratedMeter enumeratedMeter in isoEnumeratedMeters)
{
DataLogValuesByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv);
Expand Down
5 changes: 4 additions & 1 deletion ISOv4Plugin/Mappers/PolygonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public ISOPolygon ExportPolygon(Polygon adaptPolygon, ISOPolygonType polygonType

LineStringMapper lsgMapper = new LineStringMapper(TaskDataMapper);
ISOPolygon.LineStrings = new List<ISOLineString>();
ISOPolygon.LineStrings.Add(lsgMapper.ExportLinearRing(adaptPolygon.ExteriorRing, ISOLineStringType.PolygonExterior));
if (adaptPolygon.ExteriorRing != null)
{
ISOPolygon.LineStrings.Add(lsgMapper.ExportLinearRing(adaptPolygon.ExteriorRing, ISOLineStringType.PolygonExterior));
}
if (adaptPolygon.InteriorRings != null)
{
foreach(LinearRing interiorRing in adaptPolygon.InteriorRings)
Expand Down
2 changes: 1 addition & 1 deletion ISOv4Plugin/Mappers/PrescriptionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public ISOTask ExportPrescription(WorkItem workItem, int gridType, Prescription
//Connections
if (workItem.EquipmentConfigurationGroup != null)
{
task.Connections = _connectionMapper.ExportConnections(workItem.Id.ReferenceId, workItem.EquipmentConfigurationGroup.EquipmentConfigurations).ToList();
task.Connections = _connectionMapper.ExportConnections(task, workItem.EquipmentConfigurationGroup.EquipmentConfigurations).ToList();
}

//Status
Expand Down
2 changes: 1 addition & 1 deletion ISOv4Plugin/Mappers/TaskMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private ISOTask Export(LoggedData loggedData)
if (taskEquipmentConfigIDs.Any())
{
IEnumerable<EquipmentConfiguration> taskEquipmentConfigs = DataModel.Catalog.EquipmentConfigurations.Where(d => taskEquipmentConfigIDs.Contains(d.Id.ReferenceId));
task.Connections = ConnectionMapper.ExportConnections(loggedData.Id.ReferenceId, taskEquipmentConfigs).ToList();
task.Connections = ConnectionMapper.ExportConnections(task, taskEquipmentConfigs).ToList();
}
}

Expand Down
14 changes: 9 additions & 5 deletions ISOv4Plugin/Mappers/TimeLogMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public IEnumerable<ISODataLogValue> ExportDataLogValues(List<WorkingData> workin
}

List<ISODataLogValue> dlvs = new List<ISODataLogValue>();
for(int i = 0; i < workingDatas.Count(); i++)
int i = 0;
foreach (WorkingData workingData in workingDatas)
{
WorkingData workingData = workingDatas[i];

//DDI
int? mappedDDI = RepresentationMapper.Map(workingData.Representation);
Expand Down Expand Up @@ -140,8 +140,12 @@ public IEnumerable<ISODataLogValue> ExportDataLogValues(List<WorkingData> workin
dlv.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(deviceElementConfiguration.DeviceElementId);
}
}
dlvs.Add(dlv);
_dataLogValueOrdersByWorkingDataID.Add(workingData.Id.ReferenceId, i);

if (dlv.ProcessDataDDI != null && dlv.DeviceElementIdRef != null)
{
dlvs.Add(dlv);
_dataLogValueOrdersByWorkingDataID.Add(workingData.Id.ReferenceId, i++);
}
}
return dlvs;
}
Expand Down Expand Up @@ -237,7 +241,7 @@ private Dictionary<int, uint> GetMeterValues(SpatialRecord spatialRecord, List<W
var dlvsToWrite = new Dictionary<int, uint>();
var workingDatasWithValues = workingDatas.Where(x => spatialRecord.GetMeterValue(x) != null);

foreach (WorkingData workingData in workingDatasWithValues)
foreach (WorkingData workingData in workingDatasWithValues.Where(d => _dlvOrdersByWorkingDataID.ContainsKey(d.Id.ReferenceId)))
{
int order = _dlvOrdersByWorkingDataID[workingData.Id.ReferenceId];

Expand Down
2 changes: 1 addition & 1 deletion ISOv4Plugin/ObjectModel/DeviceElementHierarchy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void SetWidthsAndOffsetsFromSpatialData(IEnumerable<ISOSpatialRow> isoRec
s.DataLogValue.ProcessDataDDI == "0087"));
if (firstYOffset != null)
{
offset = firstYOffset.SpatialValues.Single(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID &&
offset = firstYOffset.SpatialValues.First(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID &&
s.DataLogValue.ProcessDataDDI == "0087").Value;
return (int)offset;
}
Expand Down

0 comments on commit 4eb3042

Please sign in to comment.