private int?GetZOffsetFromSpatialData(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, string isoDeviceElementID, RepresentationMapper representationMapper)
 {
     if (time.DataLogValues.Any(d => d.DeviceElementIdRef == isoDeviceElementID && d.ProcessDataDDI == "0088"))
     {
         ISODataLogValue dlv = time.DataLogValues.First(d => d.DeviceElementIdRef == isoDeviceElementID && d.ProcessDataDDI == "0088");
         if (dlv.ProcessDataValue.HasValue)
         {
             //Fixed value
             return(dlv.ProcessDataValue.Value);
         }
         else
         {
             //Look for first matching record in binary
             ISOSpatialRow firstZOffset = isoRecords.FirstOrDefault(r => r.SpatialValues.Any(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID &&
                                                                                             s.DataLogValue.ProcessDataDDI == "0088"));
             if (firstZOffset != null)
             {
                 double offset = firstZOffset.SpatialValues.First(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID &&
                                                                  s.DataLogValue.ProcessDataDDI == "0088").Value;
                 return((int)offset);
             }
         }
     }
     return(null);
 }
        private IEnumerable <WorkingData> Map(ISODataLogValue dlv,
                                              IEnumerable <ISOSpatialRow> isoSpatialRows,
                                              DeviceElementUse deviceElementUse,
                                              int order,
                                              List <DeviceElementUse> pendingDeviceElementUses,
                                              DeviceElementHierarchy isoDeviceElementHierarchy)
        {
            var workingDatas = new List <WorkingData>();

            if (_ddis.ContainsKey(dlv.ProcessDataDDI.AsInt32DDI()))
            {
                NumericWorkingData numericMeter = MapNumericMeter(dlv, deviceElementUse.Id.ReferenceId, order);
                DataLogValuesByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv);
                workingDatas.Add(numericMeter);
                return(workingDatas);
            }
            var meterCreator = _enumeratedMeterCreatorFactory.GetMeterCreator(dlv.ProcessDataDDI.AsInt32DDI());

            if (meterCreator != null)
            {
                var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows);
                foreach (ISOEnumeratedMeter enumeratedMeter in isoEnumeratedMeters)
                {
                    DataLogValuesByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv);
                    enumeratedMeter.DeviceElementUseId = deviceElementUse.Id.ReferenceId;
                }
                workingDatas.AddRange(isoEnumeratedMeters);

                if (meterCreator is CondensedStateMeterCreator)
                {
                    UpdateCondensedWorkingDatas(workingDatas, dlv, deviceElementUse, pendingDeviceElementUses, isoDeviceElementHierarchy);
                }
            }
            return(workingDatas);
        }
Beispiel #3
0
        private MeteredValue GetSummaryMeteredValue(ISODataLogValue dlv)
        {
            if (dlv.ProcessDataDDI == null)
            {
                return(null);
            }
            int ddi = dlv.ProcessDataDDI.AsInt32DDI();

            int dataValue = 0;

            if (dlv.ProcessDataValue.HasValue)
            {
                dataValue = dlv.ProcessDataValue.Value;
            }

            var unitOfMeasure = RepresentationMapper.GetUnitForDdi(ddi);

            if (!DDIs.ContainsKey(ddi) || unitOfMeasure == null)
            {
                return(null);
            }

            DdiDefinition ddiDefintion = DDIs[ddi];

            return(new MeteredValue
            {
                Value = new NumericRepresentationValue(RepresentationMapper.Map(ddi) as NumericRepresentation,
                                                       unitOfMeasure, new NumericValue(unitOfMeasure, dataValue * ddiDefintion.Resolution))
            });
        }
        private NumericWorkingData MapNumericMeter(ISODataLogValue dlv, int deviceElementUseId)
        {
            var meter = new NumericWorkingData
            {
                UnitOfMeasure      = RepresentationMapper.GetUnitForDdi(dlv.ProcessDataDDI.AsInt32DDI()),
                DeviceElementUseId = deviceElementUseId,
                Representation     = RepresentationMapper.Map(dlv.ProcessDataDDI.AsInt32DDI())
            };

            return(meter);
        }
        private IEnumerable <WorkingData> Map(ISODataLogValue dlv,
                                              IEnumerable <ISOSpatialRow> isoSpatialRows,
                                              DeviceElementUse deviceElementUse,
                                              int order,
                                              List <DeviceElementUse> pendingDeviceElementUses,
                                              DeviceElementHierarchy isoDeviceElementHierarchy)
        {
            var workingDatas = new List <WorkingData>();

            if (_ddis.ContainsKey(dlv.ProcessDataDDI.AsInt32DDI()))
            {
                //Numeric Representations
                NumericWorkingData numericMeter = MapNumericMeter(dlv, deviceElementUse.Id.ReferenceId);
                DataLogValuesByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv);
                ISODeviceElementIDsByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv.DeviceElementIdRef);
                workingDatas.Add(numericMeter);
                return(workingDatas);
            }
            var meterCreator = _enumeratedMeterCreatorFactory.GetMeterCreator(dlv.ProcessDataDDI.AsInt32DDI());

            if (meterCreator != null)
            {
                //Enumerated Representations
                var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows);
                foreach (ISOEnumeratedMeter enumeratedMeter in isoEnumeratedMeters)
                {
                    DataLogValuesByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv);
                    ISODeviceElementIDsByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv.DeviceElementIdRef);
                    enumeratedMeter.DeviceElementUseId = deviceElementUse.Id.ReferenceId;
                }
                workingDatas.AddRange(isoEnumeratedMeters);

                if (meterCreator is CondensedStateMeterCreator)
                {
                    UpdateCondensedWorkingDatas(workingDatas, dlv, deviceElementUse, pendingDeviceElementUses, isoDeviceElementHierarchy);
                }
            }
            else
            {
                //Proprietary DDIs - report out as numeric value
                NumericWorkingData proprietaryWorkingData = new NumericWorkingData();
                proprietaryWorkingData.Representation = new ApplicationDataModel.Representations.NumericRepresentation {
                    Code = dlv.ProcessDataDDI, CodeSource = RepresentationCodeSourceEnum.ISO11783_DDI
                };
                proprietaryWorkingData.DeviceElementUseId = deviceElementUse.Id.ReferenceId;
                proprietaryWorkingData.UnitOfMeasure      = AgGateway.ADAPT.Representation.UnitSystem.UnitSystemManager.GetUnitOfMeasure("count"); //Best we can do

                DataLogValuesByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv);
                ISODeviceElementIDsByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv.DeviceElementIdRef);
                workingDatas.Add(proprietaryWorkingData);
            }
            return(workingDatas);
        }
Beispiel #6
0
        public IEnumerable <ISODataLogValue> ExportDataLogValues(List <WorkingData> workingDatas, List <DeviceElementUse> deviceElementUses)
        {
            if (workingDatas == null)
            {
                return(null);
            }

            List <ISODataLogValue> dlvs = new List <ISODataLogValue>();
            int i = 0;

            foreach (WorkingData workingData in workingDatas)
            {
                //DDI
                int?mappedDDI = RepresentationMapper.Map(workingData.Representation);
                var dlv       = new ISODataLogValue();
                if (mappedDDI != null)
                {
                    if (workingData.Representation != null && workingData.Representation.Code == "dtRecordingStatus" && workingData.DeviceElementUseId != 0)
                    {
                        dlv.ProcessDataDDI = 141.AsHexDDI(); //No support for exporting CondensedWorkState at this time
                    }
                    else
                    {
                        dlv.ProcessDataDDI = mappedDDI.Value.AsHexDDI();
                    }
                }
                else if (workingData.Representation.CodeSource == ApplicationDataModel.Representations.RepresentationCodeSourceEnum.ISO11783_DDI)
                {
                    dlv.ProcessDataDDI = workingData.Representation.Code;
                }

                //DeviceElementIdRef
                DeviceElementUse use = deviceElementUses.FirstOrDefault(d => d.Id.ReferenceId == workingData.DeviceElementUseId);
                if (use != null)
                {
                    DeviceElementConfiguration deviceElementConfiguration = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(d => d.Id.ReferenceId == use.DeviceConfigurationId);
                    if (deviceElementConfiguration != null)
                    {
                        //This requires the Devices will have been mapped prior to the LoggedData
                        dlv.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(deviceElementConfiguration.DeviceElementId);
                    }
                }

                if (dlv.ProcessDataDDI != null && dlv.DeviceElementIdRef != null)
                {
                    dlvs.Add(dlv);
                    _dataLogValueOrdersByWorkingDataID.Add(workingData.Id.ReferenceId, i++);
                }
            }
            return(dlvs);
        }
Beispiel #7
0
        private List <ISOTime> ExportSummary(Summary summary)
        {
            List <ISOTime> times = new List <ISOTime>();

            foreach (StampedMeteredValues values in summary.SummaryData)
            {
                ISOTime time = new ISOTime();
                time.Start = values.Stamp.TimeStamp1;
                time.Stop  = values.Stamp.TimeStamp2;
                if (values.Stamp.Duration.HasValue)
                {
                    time.Duration = (uint)values.Stamp.Duration.Value.TotalSeconds;
                }
                time.Type = values.Stamp.DateContext == DateContextEnum.ProposedStart ? ISOEnumerations.ISOTimeType.Planned : ISOEnumerations.ISOTimeType.Effective;

                foreach (MeteredValue value in values.Values)
                {
                    if (value.Value != null && value.Value is NumericRepresentationValue)
                    {
                        NumericRepresentationValue numericValue = value.Value as NumericRepresentationValue;
                        ISODataLogValue            dlv          = new ISODataLogValue();
                        int?ddi = RepresentationMapper.Map(numericValue.Representation);
                        if (ddi.HasValue)
                        {
                            dlv.ProcessDataDDI = ddi.Value.AsHexDDI();
                            DdiDefinition DdiDefinition = DDIs[ddi.Value];
                            dlv.ProcessDataValue = (int)(numericValue.Value.Value / (DdiDefinition.Resolution != 0 ? DdiDefinition.Resolution : 1d));
                        }
                        else
                        {
                            if (numericValue.Representation.CodeSource == RepresentationCodeSourceEnum.ISO11783_DDI)
                            {
                                dlv.ProcessDataDDI   = numericValue.Representation.Code;
                                dlv.ProcessDataValue = (int)numericValue.Value.Value;
                            }
                        }
                        if (value.DeviceConfigurationId.HasValue)
                        {
                            DeviceElementConfiguration config = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(c => c.Id.ReferenceId == value.DeviceConfigurationId.Value);
                            if (config != null)
                            {
                                dlv.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(config.DeviceElementId);
                            }
                        }
                        time.DataLogValues.Add(dlv);
                    }
                }
                times.Add(time);
            }
            return(times);
        }
Beispiel #8
0
        private MeteredValue GetSummaryMeteredValue(ISODataLogValue dlv)
        {
            if (dlv.ProcessDataDDI == null)
            {
                return(null);
            }
            int ddi = dlv.ProcessDataDDI.AsInt32DDI();

            int dataValue = 0;

            if (dlv.ProcessDataValue.HasValue)
            {
                dataValue = dlv.ProcessDataValue.Value;
            }

            var unitOfMeasure = RepresentationMapper.GetUnitForDdi(ddi);

            if (!DDIs.ContainsKey(ddi) || unitOfMeasure == null)
            {
                return(null);
            }

            DdiDefinition ddiDefintion = DDIs[ddi];

            int?deviceConfigurationID = null;
            int?deviceElementID       = TaskDataMapper.InstanceIDMap.GetADAPTID(dlv.DeviceElementIdRef);

            if (deviceElementID.HasValue)
            {
                //Since Device creation is on-demand, we need to call GetDeviceElementConfiguration here to ensure the relevant device is created if it hasn't been yet.
                var hierarchy          = TaskDataMapper?.DeviceElementHierarchies?.GetRelevantHierarchy(dlv.DeviceElementIdRef);
                var adaptDeviceElement = DataModel?.Catalog?.DeviceElements?.FirstOrDefault(d => d?.Id?.ReferenceId == deviceElementID.Value);
                if (hierarchy != null && adaptDeviceElement != null)
                {
                    DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchy, DataModel.Catalog);
                    if (config != null)
                    {
                        deviceConfigurationID = config.Id.ReferenceId;
                    }
                }
            }

            return(new MeteredValue
            {
                Value = new NumericRepresentationValue(RepresentationMapper.Map(ddi) as NumericRepresentation,
                                                       unitOfMeasure,
                                                       new NumericValue(unitOfMeasure, dataValue * ddiDefintion.Resolution)),
                DeviceConfigurationId = deviceConfigurationID
            });
        }
Beispiel #9
0
        private MeteredValue GetSummaryMeteredValue(ISODataLogValue dlv)
        {
            if (dlv.ProcessDataDDI == null)
            {
                return(null);
            }
            int ddi = dlv.ProcessDataDDI.AsInt32DDI();

            int dataValue = 0;

            if (dlv.ProcessDataValue.HasValue)
            {
                dataValue = dlv.ProcessDataValue.Value;
            }

            var unitOfMeasure = RepresentationMapper.GetUnitForDdi(ddi);

            if (!DDIs.ContainsKey(ddi) || unitOfMeasure == null)
            {
                return(null);
            }

            DdiDefinition ddiDefintion = DDIs[ddi];

            int?deviceConfigurationID = null;
            int?deviceElementID       = TaskDataMapper.InstanceIDMap.GetADAPTID(dlv.DeviceElementIdRef);

            if (deviceElementID.HasValue)
            {
                DeviceElementConfiguration config = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(c => c.DeviceElementId == deviceElementID.Value);
                if (config != null)
                {
                    deviceConfigurationID = config.Id.ReferenceId;
                }
            }

            return(new MeteredValue
            {
                Value = new NumericRepresentationValue(RepresentationMapper.Map(ddi) as NumericRepresentation,
                                                       unitOfMeasure,
                                                       new NumericValue(unitOfMeasure, dataValue * ddiDefintion.Resolution)),
                DeviceConfigurationId = deviceConfigurationID
            });
        }
        private void UpdateCondensedWorkingDatas(List <ISOEnumeratedMeter> condensedWorkingDatas, ISODataLogValue dlv, DeviceElementUse deviceElementUse, List <DeviceElementUse> pendingDeviceElementUses, DeviceHierarchyElement isoDeviceElementHierarchy)
        {
            ISODeviceElement        isoDeviceElement   = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(dlv.DeviceElementIdRef);
            List <ISODeviceElement> isoSectionElements = isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section).ToList();

            foreach (var subElement in isoDeviceElement.ChildDeviceElements)
            {
                //This handles cases where the condensed workstate is reported on a top-level boom with sub-booms in the hierarchy above the sections (e.g., ISO 11783-10:2015(E) Figure F.35)
                isoSectionElements.AddRange(subElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section).ToList());
            }
            //We have some sections in the DDOP
            if (isoSectionElements.Count > 0)
            {
                //Update the DeviceElementReference on the Condensed WorkingDatas
                foreach (var workingData in condensedWorkingDatas)
                {
                    if (workingData.SectionIndex - 1 >= isoSectionElements.Count)
                    {
                        break;
                    }
                    ISODeviceElement targetSection = isoSectionElements[workingData.SectionIndex - 1];

                    DeviceElementUse condensedDeviceElementUse = FindExistingDeviceElementUseForCondensedData(targetSection, pendingDeviceElementUses);
                    if (condensedDeviceElementUse == null)
                    {
                        //Make a new DeviceElementUse
                        condensedDeviceElementUse = new DeviceElementUse();
                        condensedDeviceElementUse.OperationDataId = deviceElementUse.OperationDataId;

                        int?deviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(targetSection.DeviceElementId);
                        if (deviceElementID.HasValue)
                        {
                            DeviceElement deviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == deviceElementID.Value);
                            if (deviceElement != null)
                            {
                                //Reference the device element in its hierarchy so that we can get the depth & order
                                DeviceHierarchyElement deviceElementInHierarchy = isoDeviceElementHierarchy.FromDeviceElementID(targetSection.DeviceElementId);

                                //Get the config id
                                DeviceElementConfiguration deviceElementConfig = DeviceElementMapper.GetDeviceElementConfiguration(deviceElement, deviceElementInHierarchy, DataModel.Catalog);
                                condensedDeviceElementUse.DeviceConfigurationId = deviceElementConfig.Id.ReferenceId;

                                //Set the depth & order
                                condensedDeviceElementUse.Depth = deviceElementInHierarchy.Depth;
                                condensedDeviceElementUse.Order = deviceElementInHierarchy.Order;
                            }
                        }

                        condensedDeviceElementUse.GetWorkingDatas = () => new List <WorkingData> {
                            workingData
                        };

                        workingData.DeviceElementUseId = condensedDeviceElementUse.Id.ReferenceId;

                        pendingDeviceElementUses.Add(condensedDeviceElementUse);
                    }
                    else
                    {
                        //Use the existing DeviceElementUse
                        List <WorkingData>        data = new List <WorkingData>();
                        IEnumerable <WorkingData> existingWorkingDatas = condensedDeviceElementUse.GetWorkingDatas();
                        if (existingWorkingDatas != null)
                        {
                            data.AddRange(existingWorkingDatas.ToList());  //Add the preexisting
                        }
                        data.Add(workingData);
                        condensedDeviceElementUse.GetWorkingDatas = () => data;
                    }
                }
            }
        }
        private IEnumerable <WorkingData> Map(ISODataLogValue dlv,
                                              IEnumerable <ISOSpatialRow> isoSpatialRows,
                                              DeviceElementUse deviceElementUse,
                                              int order,
                                              List <DeviceElementUse> pendingDeviceElementUses,
                                              DeviceElementHierarchy isoDeviceElementHierarchy)
        {
            var workingDatas = new List <WorkingData>();

            if (_ddis.ContainsKey(dlv.ProcessDataDDI.AsInt32DDI()))
            {
                //Numeric Representations
                NumericWorkingData numericMeter = MapNumericMeter(dlv, deviceElementUse.Id.ReferenceId);
                DataLogValuesByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv);
                ISODeviceElementIDsByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv.DeviceElementIdRef);
                workingDatas.Add(numericMeter);
                return(workingDatas);
            }
            var meterCreator = _enumeratedMeterCreatorFactory.GetMeterCreator(dlv.ProcessDataDDI.AsInt32DDI());

            if (meterCreator != null)
            {
                //Enumerated Representations
                var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows, dlv);
                foreach (ISOEnumeratedMeter enumeratedMeter in isoEnumeratedMeters)
                {
                    DataLogValuesByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv);
                    ISODeviceElementIDsByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv.DeviceElementIdRef);
                    enumeratedMeter.DeviceElementUseId = deviceElementUse.Id.ReferenceId;
                }
                workingDatas.AddRange(isoEnumeratedMeters);

                if (meterCreator is CondensedStateMeterCreator)
                {
                    UpdateCondensedWorkingDatas(workingDatas, dlv, deviceElementUse, pendingDeviceElementUses, isoDeviceElementHierarchy);
                }
            }
            else
            {
                //Proprietary DDIs - report out as numeric value
                NumericWorkingData proprietaryWorkingData = new NumericWorkingData();
                proprietaryWorkingData.Representation = new ApplicationDataModel.Representations.NumericRepresentation {
                    Code = dlv.ProcessDataDDI, CodeSource = RepresentationCodeSourceEnum.ISO11783_DDI
                };
                proprietaryWorkingData.DeviceElementUseId = deviceElementUse.Id.ReferenceId;

                //Always set unit as count.   In SpatialRecordMapper, we will place the DVP unit on the NumericRepresentationValue.UserProvidedUnitOfMeasure
                //so that consumers can apply any offset/scaling to get to the desired display unit.
                proprietaryWorkingData.UnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("count");

                //Take any information from DPD
                ISODeviceElement det = isoDeviceElementHierarchy.DeviceElement;
                if (det != null)
                {
                    ISODeviceProcessData dpd = det.DeviceProcessDatas.FirstOrDefault(d => d.DDI == dlv.ProcessDataDDI);
                    if (dpd != null)
                    {
                        proprietaryWorkingData.Representation.Description = dpd.Designator; //Update the representation with a name since we have one here.
                    }
                }

                DataLogValuesByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv);
                ISODeviceElementIDsByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv.DeviceElementIdRef);
                workingDatas.Add(proprietaryWorkingData);
            }
            return(workingDatas);
        }
        public List <ISOEnumeratedMeter> CreateMeters(IEnumerable <ISOSpatialRow> spatialRows, ISODataLogValue dlv)
        {
            var unloadingMeter = new ISOEnumeratedMeter
            {
                DeviceElementUseId = 1,
                Representation     = RepresentationInstanceList.dtUnloadingAugerState.ToModelRepresentation(),
                GetEnumeratedValue = GetValueForMeter
            };

            var loadingMeter = new ISOEnumeratedMeter
            {
                DeviceElementUseId = 2,
                Representation     = RepresentationInstanceList.dtUnloadingAugerState.ToModelRepresentation(),
                GetEnumeratedValue = GetValueForMeter
            };

            var meters = new List <ISOEnumeratedMeter> {
                unloadingMeter, loadingMeter
            };

            return(meters);
        }
        /// <summary>
        /// Perform a targeted read of the Timelog binary files to obtain implement geometry details logged via DeviceProcessData
        /// </summary>
        /// <param name="missingDefinitions"></param>
        /// <param name="timeLogTimeElements"></param>
        /// <param name="taskDataPath"></param>
        /// <param name="allDeviceHierarchyElements"></param>
        public void FillDPDGeometryDefinitions(Dictionary <string, List <string> > missingDefinitions, IEnumerable <ISOTimeLog> timeLogs, string taskDataPath)
        {
            Dictionary <string, int?> reportedValues = new Dictionary <string, int?>(); //DLV signature / value

            foreach (ISOTimeLog timeLog in timeLogs)
            {
                ISOTime time = timeLog.GetTimeElement(taskDataPath);
                if (time != null &&
                    time.DataLogValues.Any(dlv => missingDefinitions.ContainsKey(dlv.DeviceElementIdRef)))
                {
                    List <ISODataLogValue> dlvsToRead = time.DataLogValues.Where(dlv => missingDefinitions.ContainsKey(dlv.DeviceElementIdRef) &&
                                                                                 missingDefinitions[dlv.DeviceElementIdRef].Contains(dlv.ProcessDataDDI)).ToList();
                    foreach (string deviceElementID in missingDefinitions.Keys)
                    {
                        List <string> ddis = missingDefinitions[deviceElementID];
                        if (ddis.Any(d => d == "0046"))
                        {
                            //We used 0046 generically for a missing width.  Check for any 0044 or 0043
                            var defaultWidthDLV = time.DataLogValues.FirstOrDefault(gt => gt.ProcessDataDDI == "0044" && gt.DeviceElementIdRef == deviceElementID);
                            if (defaultWidthDLV != null)
                            {
                                dlvsToRead.Add(defaultWidthDLV);
                            }
                            else
                            {
                                var workingWidthDLV = time.DataLogValues.FirstOrDefault(gt => gt.ProcessDataDDI == "0043" && gt.DeviceElementIdRef == deviceElementID);
                                if (workingWidthDLV != null)
                                {
                                    dlvsToRead.Add(workingWidthDLV);
                                }
                            }
                        }
                    }

                    if (dlvsToRead.Any())
                    {
                        string binaryPath = System.IO.Path.Combine(taskDataPath, timeLog.Filename + ".bin");
                        Dictionary <byte, int> timelogValues = Mappers.TimeLogMapper.ReadImplementGeometryValues(dlvsToRead.Select(d => d.Index), time, binaryPath);

                        foreach (byte reportedDLVIndex in timelogValues.Keys)
                        {
                            ISODataLogValue reportedDLV = dlvsToRead.First(d => d.Index == reportedDLVIndex);
                            string          dlvKey      = DeviceHierarchyElement.GetDataLogValueKey(reportedDLV);
                            if (!reportedValues.ContainsKey(dlvKey))
                            {
                                //First occurence of this DET and DDI in the timelogs
                                //We take the max width/max (from 0) offset from the 1st timelog.  This matches existing functionality, and is workable for foreseeable cases where working width is the only dynamic value.
                                //ISOXML supports changing widths and offsets dynamically throughout and across timelogs.
                                //Should max width and/or offset parameters change dynamically, data consumers will need to obtain this information via the OperationData.SpatialRecords as is commonly done with 0043 (working width) today
                                //An alternative would be to enhance this logic to clone the entire DeviceModel hierarchy for each variation in offset value, should such data ever occur in the field.
                                reportedValues.Add(dlvKey, timelogValues[reportedDLV.Index]);

                                //Add to this element
                                var matchingElement = GetMatchingElement(reportedDLV.DeviceElementIdRef);
                                if (matchingElement != null)
                                {
                                    switch (reportedDLV.ProcessDataDDI)
                                    {
                                    case "0046":
                                    case "0044":
                                    case "0043":
                                        if (matchingElement.Width == null || timelogValues[reportedDLV.Index] > matchingElement.Width)
                                        {
                                            //If max 0043 is greater than 0046, then take max 0043
                                            matchingElement.Width    = timelogValues[reportedDLV.Index];
                                            matchingElement.WidthDDI = reportedDLV.ProcessDataDDI;
                                        }
                                        break;

                                    case "0086":
                                        matchingElement.XOffset = timelogValues[reportedDLV.Index];
                                        break;

                                    case "0087":
                                        matchingElement.YOffset = timelogValues[reportedDLV.Index];
                                        break;

                                    case "0088":
                                        matchingElement.ZOffset = timelogValues[reportedDLV.Index];
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 internal static string GetDataLogValueKey(ISODataLogValue dlv)
 {
     return(string.Concat(dlv.DeviceElementIdRef, "_", dlv.ProcessDataDDI));
 }
        private void UpdateCondensedWorkingDatas(List <WorkingData> condensedWorkingDatas, ISODataLogValue dlv, DeviceElementUse deviceElementUse, List <DeviceElementUse> pendingDeviceElementUses, DeviceElementHierarchy isoDeviceElementHierarchy)
        {
            ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(dlv.DeviceElementIdRef);
            IEnumerable <ISODeviceElement> isoSectionElements = isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section);

            if (isoSectionElements.Count() > 0 && isoSectionElements.Count() <= condensedWorkingDatas.Count)
            {
                //We have found the expected number of sections in the DDOP
                List <ISODeviceElement> targetSections = isoSectionElements.ToList();

                //Update the DeviceElementReference on the Condensed WorkingDatas
                for (int i = 0; i < isoSectionElements.Count(); i++)
                {
                    WorkingData      workingData   = condensedWorkingDatas[i];
                    ISODeviceElement targetSection = targetSections[i];

                    DeviceElementUse condensedDeviceElementUse = FindExistingDeviceElementUseForCondensedData(targetSection, pendingDeviceElementUses);
                    if (condensedDeviceElementUse == null)
                    {
                        //Make a new DeviceElementUse
                        condensedDeviceElementUse = new DeviceElementUse();
                        condensedDeviceElementUse.OperationDataId = deviceElementUse.OperationDataId;

                        int?deviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(targetSection.DeviceElementId);
                        if (deviceElementID.HasValue)
                        {
                            DeviceElement deviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == deviceElementID.Value);
                            if (deviceElement != null)
                            {
                                //Reference the device element in its hierarchy so that we can get the depth & order
                                DeviceElementHierarchy deviceElementInHierarchy = isoDeviceElementHierarchy.FromDeviceElementID(targetSection.DeviceElementId);

                                //Get the config id
                                DeviceElementConfiguration deviceElementConfig = DeviceElementMapper.GetDeviceElementConfiguration(deviceElement, deviceElementInHierarchy, DataModel.Catalog);
                                condensedDeviceElementUse.DeviceConfigurationId = deviceElementConfig.Id.ReferenceId;

                                //Set the depth & order
                                condensedDeviceElementUse.Depth = deviceElementInHierarchy.Depth;
                                condensedDeviceElementUse.Order = deviceElementInHierarchy.Order;
                            }
                        }

                        condensedDeviceElementUse.GetWorkingDatas = () => new List <WorkingData> {
                            workingData
                        };

                        workingData.DeviceElementUseId = condensedDeviceElementUse.Id.ReferenceId;

                        pendingDeviceElementUses.Add(condensedDeviceElementUse);
                    }
                    else
                    {
                        //Use the existing DeviceElementUse
                        List <WorkingData>        data = new List <WorkingData>();
                        IEnumerable <WorkingData> existingWorkingDatas = condensedDeviceElementUse.GetWorkingDatas();
                        if (existingWorkingDatas != null)
                        {
                            data.AddRange(existingWorkingDatas.ToList());  //Add the preexisting
                        }
                        data.Add(workingData);
                        condensedDeviceElementUse.GetWorkingDatas = () => data;
                    }
                }
            }
        }
Beispiel #16
0
        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 &&
                                                                                        y.DataLogValue.DeviceElementIdRef == dlv.DeviceElementIdRef));

            int numberOfSections = 0;

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

            var meters = new List <ISOEnumeratedMeter>();

            for (int i = StartingSection; i < StartingSection + numberOfSections; i++)
            {
                meters.Add(new ISOEnumeratedMeter
                {
                    SectionIndex       = i,
                    Representation     = Representation,
                    GetEnumeratedValue = GetValueForMeter
                });
            }

            return(meters);
        }
Beispiel #17
0
        private void UpdateCondensedWorkingDatas(List <WorkingData> condensedWorkingDatas, ISODataLogValue dlv, DeviceElementUse deviceElementUse, List <DeviceElementUse> pendingDeviceElementUses, DeviceElementHierarchy isoDeviceElementHierarchy)
        {
            ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(dlv.DeviceElementIdRef);
            IEnumerable <ISODeviceElement> isoSectionElements = isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section);

            if (isoSectionElements.Count() > 0 && isoSectionElements.Count() == condensedWorkingDatas.Count)
            {
                //We have found the expected number of sections in the DDOP
                List <ISODeviceElement> targetSections = isoSectionElements.ToList();

                //Update the DeviceElementReference on the Condensed WorkingDatas
                for (int i = 0; i < condensedWorkingDatas.Count; i++)
                {
                    WorkingData workingData = condensedWorkingDatas[i];

                    DeviceElementUse condensedDeviceElementUse = new DeviceElementUse();
                    condensedDeviceElementUse.Depth           = deviceElementUse.Depth + 1;
                    condensedDeviceElementUse.Order           = i + 1;
                    condensedDeviceElementUse.OperationDataId = deviceElementUse.OperationDataId;

                    ISODeviceElement targetSection = targetSections[i];
                    int?deviceElementID            = TaskDataMapper.InstanceIDMap.GetADAPTID(targetSection.DeviceElementId);
                    if (deviceElementID.HasValue)
                    {
                        DeviceElement deviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == deviceElementID.Value);
                        if (deviceElement != null)
                        {
                            DeviceElementConfiguration deviceElementConfig = DeviceElementMapper.GetDeviceElementConfiguration(deviceElement, isoDeviceElementHierarchy.FromDeviceElementID(targetSection.DeviceElementId), DataModel.Catalog);
                            condensedDeviceElementUse.DeviceConfigurationId = deviceElementConfig.Id.ReferenceId;
                        }
                    }
                    condensedDeviceElementUse.GetWorkingDatas = () => new List <WorkingData> {
                        workingData
                    };

                    workingData.DeviceElementUseId = condensedDeviceElementUse.Id.ReferenceId;

                    pendingDeviceElementUses.Add(condensedDeviceElementUse);
                }
            }
        }
Beispiel #18
0
        private IEnumerable <WorkingData> Map(ISODataLogValue dlv,
                                              IEnumerable <ISOSpatialRow> isoSpatialRows,
                                              DeviceElementUse deviceElementUse,
                                              int order,
                                              List <DeviceElementUse> pendingDeviceElementUses,
                                              DeviceElementHierarchy isoDeviceElementHierarchy)
        {
            var workingDatas = new List <WorkingData>();

            if (_ddis.ContainsKey(dlv.ProcessDataDDI.AsInt32DDI()))
            {
                //Numeric Representations
                NumericWorkingData numericMeter = MapNumericMeter(dlv, deviceElementUse.Id.ReferenceId);
                DataLogValuesByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv);
                ISODeviceElementIDsByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv.DeviceElementIdRef);
                workingDatas.Add(numericMeter);
                return(workingDatas);
            }
            var meterCreator = _enumeratedMeterCreatorFactory.GetMeterCreator(dlv.ProcessDataDDI.AsInt32DDI());

            if (meterCreator != null)
            {
                //Enumerated Representations
                var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows);
                foreach (ISOEnumeratedMeter enumeratedMeter in isoEnumeratedMeters)
                {
                    DataLogValuesByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv);
                    ISODeviceElementIDsByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv.DeviceElementIdRef);
                    enumeratedMeter.DeviceElementUseId = deviceElementUse.Id.ReferenceId;
                }
                workingDatas.AddRange(isoEnumeratedMeters);

                if (meterCreator is CondensedStateMeterCreator)
                {
                    UpdateCondensedWorkingDatas(workingDatas, dlv, deviceElementUse, pendingDeviceElementUses, isoDeviceElementHierarchy);
                }
            }
            else
            {
                //Proprietary DDIs - report out as numeric value
                NumericWorkingData proprietaryWorkingData = new NumericWorkingData();
                proprietaryWorkingData.Representation = new ApplicationDataModel.Representations.NumericRepresentation {
                    Code = dlv.ProcessDataDDI, CodeSource = RepresentationCodeSourceEnum.ISO11783_DDI
                };
                proprietaryWorkingData.DeviceElementUseId = deviceElementUse.Id.ReferenceId;

                //Take any information from DPDs/DVPs
                ApplicationDataModel.Common.UnitOfMeasure uom = null;
                ISODeviceElement det = isoDeviceElementHierarchy.DeviceElement;
                if (det != null)
                {
                    ISODeviceProcessData dpd = det.DeviceProcessDatas.FirstOrDefault(d => d.DDI == dlv.ProcessDataDDI);
                    if (dpd != null)
                    {
                        proprietaryWorkingData.Representation.Description = dpd.Designator; //Update the representation with a name since we have one here.
                        ISODeviceValuePresentation dvp = det.Device.DeviceValuePresentations.FirstOrDefault(d => d.ObjectID == dpd.DeviceValuePresentationObjectId);
                        if (dvp != null && dvp.UnitDesignator != null)
                        {
                            if (AgGateway.ADAPT.Representation.UnitSystem.InternalUnitSystemManager.Instance.UnitOfMeasures.Contains(dvp.UnitDesignator))
                            {
                                //The unit designator used by the OEM will need to match ADAPT for this to work, otherwise we'll need to default to 'count' below
                                //It will likely work for many simple units and will not for work compound units
                                uom = UnitSystemManager.GetUnitOfMeasure(dvp.UnitDesignator);
                            }
                        }
                    }
                }

                proprietaryWorkingData.UnitOfMeasure = uom ?? UnitSystemManager.GetUnitOfMeasure("count"); //Best we can do

                DataLogValuesByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv);
                ISODeviceElementIDsByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv.DeviceElementIdRef);
                workingDatas.Add(proprietaryWorkingData);
            }
            return(workingDatas);
        }
        public List <ISOEnumeratedMeter> CreateMeters(IEnumerable <ISOSpatialRow> spatialRows, ISODataLogValue dlv)
        {
            var meter = new ISOEnumeratedMeter
            {
                Representation     = RepresentationInstanceList.dtHitchType.ToModelRepresentation(),
                GetEnumeratedValue = GetValueForMeter
            };

            return(new List <ISOEnumeratedMeter> {
                meter
            });
        }
        private int?GetWidthFromSpatialData(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, string isoDeviceElementID, RepresentationMapper representationMapper)
        {
            double maxWidth        = 0d;
            string updatedWidthDDI = null;

            if (time.DataLogValues.Any(d => d.DeviceElementIdRef == isoDeviceElementID && d.ProcessDataDDI == "0046"))
            {
                //Find a relevant max width
                ISODataLogValue dlv = time.DataLogValues.First(d => d.DeviceElementIdRef == isoDeviceElementID && d.ProcessDataDDI == "0046");
                if (dlv.ProcessDataValue.HasValue)
                {
                    //Fixed value
                    maxWidth        = dlv.ProcessDataValue.Value;
                    updatedWidthDDI = "0046";
                }
                else
                {
                    //Look for value in first spatial record matching the DDI and DET
                    ISOSpatialRow rowWithMaxWidth = isoRecords.FirstOrDefault(r => r.SpatialValues.Any(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0046"));
                    if (rowWithMaxWidth != null)
                    {
                        maxWidth        = rowWithMaxWidth.SpatialValues.Single(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0046").Value;
                        updatedWidthDDI = "0046";
                    }
                }
            }
            else if (time.DataLogValues.Any(d => d.DeviceElementIdRef == isoDeviceElementID && d.ProcessDataDDI == "0043"))
            {
                //Find the largest working width
                ISODataLogValue dlv = time.DataLogValues.First(d => d.DeviceElementIdRef == isoDeviceElementID && d.ProcessDataDDI == "0043");
                if (dlv.ProcessDataValue.HasValue)
                {
                    //Fixed value
                    maxWidth        = dlv.ProcessDataValue.Value;
                    updatedWidthDDI = "0043";
                }
                else
                {
                    IEnumerable <ISOSpatialRow> rows = isoRecords.Where(r => r.SpatialValues.Any(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID &&
                                                                                                 s.DataLogValue.ProcessDataDDI == "0043"));
                    if (rows.Any())
                    {
                        foreach (ISOSpatialRow row in rows)
                        {
                            double value = row.SpatialValues.Single(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0043").Value;
                            if (value > maxWidth)
                            {
                                maxWidth = value;
                            }
                        }
                        updatedWidthDDI = "0043";
                    }
                }
            }

            if (updatedWidthDDI != null)
            {
                WidthDDI = updatedWidthDDI;
                return((int)maxWidth);
            }
            else
            {
                return(null);
            }
        }