示例#1
0
        public List <DeviceElementUse> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, int operationDataId, IEnumerable <string> isoDeviceElementIDs)
        {
            var sections = new List <DeviceElementUse>();

            foreach (string isoDeviceElementID in isoDeviceElementIDs)
            {
                DeviceElementHierarchy hierarchy = TaskDataMapper.DeviceElementHierarchies.GetRelevantHierarchy(isoDeviceElementID);
                if (hierarchy != null)
                {
                    DeviceElementUse   deviceElementUse = null;
                    List <WorkingData> workingDatas     = new List <WorkingData>();

                    //Get the relevant DeviceElementConfiguration
                    int           adaptDeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID).Value;
                    DeviceElement adaptDeviceElement   = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == adaptDeviceElementId);
                    if (adaptDeviceElement != null)
                    {
                        DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchy, DataModel.Catalog);

                        int depth = hierarchy.Depth;
                        int order = hierarchy.Order;
                        if (config.DeviceElementId == adaptDeviceElement.ParentDeviceId)
                        {
                            //The configuration references the parent ISO element
                            depth = hierarchy.Parent.Depth;
                            order = hierarchy.Parent.Order;
                        }

                        //Read any spatially-listed widths/offsets on this data onto the DeviceElementConfiguration objects
                        hierarchy.SetWidthsAndOffsetsFromSpatialData(isoRecords, config, RepresentationMapper);

                        //Create the DeviceElementUse
                        deviceElementUse                       = new DeviceElementUse();
                        deviceElementUse.Depth                 = depth;
                        deviceElementUse.Order                 = order;
                        deviceElementUse.OperationDataId       = operationDataId;
                        deviceElementUse.DeviceConfigurationId = config.Id.ReferenceId;

                        //Add Working Data for any data on this device element
                        List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchy, sections);
                        if (data.Any())
                        {
                            workingDatas.AddRange(data);
                        }

                        deviceElementUse.GetWorkingDatas = () => workingDatas;

                        if (!sections.Contains(deviceElementUse))
                        {
                            sections.Add(deviceElementUse);
                        }
                    }
                }
            }

            return(sections);
        }
示例#2
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
            });
        }
示例#3
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 < isoSectionElements.Count(); i++)
                {
                    WorkingData workingData = condensedWorkingDatas[i];

                    DeviceElementUse condensedDeviceElementUse = new DeviceElementUse();
                    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)
                        {
                            //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);
                }
            }
        }
        /// <summary>
        /// Adds a connector with a hitch at the given reference point, referencing the parent DeviceElement as the DeviceElementConfiguration
        /// </summary>
        /// <param name="rootDeviceHierarchy"></param>
        /// <param name="connectorDeviceElement"></param>
        /// <param name="deviceElement"></param>
        private void AddConnector(DeviceElementHierarchy rootDeviceHierarchy, ISODeviceElement connectorDeviceElement)
        {
            //Per the TC-GEO specification, the connector is always a child of the root device element.
            DeviceElementHierarchy hierarchy = rootDeviceHierarchy.FromDeviceElementID(connectorDeviceElement.DeviceElementId);

            if (hierarchy.Parent == rootDeviceHierarchy)
            {
                int?rootDeviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(rootDeviceHierarchy.DeviceElement.DeviceElementId);
                if (rootDeviceElementID.HasValue)
                {
                    HitchPoint hitch = new HitchPoint();
                    hitch.ReferencePoint = new ReferencePoint()
                    {
                        XOffset = hierarchy.XOffsetRepresentation, YOffset = hierarchy.YOffsetRepresentation, ZOffset = hierarchy.ZOffsetRepresentation
                    };
                    hitch.HitchTypeEnum = HitchTypeEnum.Unkown;
                    DataModel.Catalog.HitchPoints.Add(hitch);

                    //Get the DeviceElementConfiguration for the root element in order that we may link the Connector to it.
                    DeviceElement root = DataModel.Catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == rootDeviceElementID);
                    if (root != null)
                    {
                        DeviceElementConfiguration rootDeviceConfiguration = DeviceElementMapper.GetDeviceElementConfiguration(root, rootDeviceHierarchy, DataModel.Catalog);
                        if (rootDeviceConfiguration != null)
                        {
                            Connector connector = new Connector();
                            ImportIDs(connector.Id, hierarchy.DeviceElement.DeviceElementId);
                            connector.DeviceElementConfigurationId = rootDeviceConfiguration.Id.ReferenceId;
                            connector.HitchPointId = hitch.Id.ReferenceId;
                            DataModel.Catalog.Connectors.Add(connector);

                            //The ID mapping will link the ADAPT Connector to the ISO Device Element
                            TaskDataMapper.InstanceIDMap.Add(connector.Id.ReferenceId, connectorDeviceElement.DeviceElementId);
                        }
                    }
                }
            }
        }
 public DeviceMapper(TaskDataMapper taskDataMapper) : base(taskDataMapper, "DVC")
 {
     _deviceElementMapper = new DeviceElementMapper(taskDataMapper);
 }
示例#6
0
        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;
                    }
                }
            }
        }
示例#7
0
        public List <DeviceElementUse> Map(ISOTime time,
                                           IEnumerable <ISOSpatialRow> isoRecords,
                                           int operationDataId,
                                           IEnumerable <string> isoDeviceElementIDs,
                                           Dictionary <string, List <ISOProductAllocation> > isoProductAllocations)
        {
            var sections = new List <DeviceElementUse>();

            foreach (string isoDeviceElementID in isoDeviceElementIDs)
            {
                DeviceHierarchyElement hierarchyElement = TaskDataMapper.DeviceElementHierarchies.GetMatchingElement(isoDeviceElementID);
                if (hierarchyElement != null)
                {
                    DeviceElementUse   deviceElementUse = null;
                    List <WorkingData> workingDatas     = new List <WorkingData>();

                    //Get the relevant DeviceElementConfiguration
                    int           adaptDeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID).Value;
                    DeviceElement adaptDeviceElement   = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == adaptDeviceElementId);
                    if (adaptDeviceElement != null)
                    {
                        DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchyElement, DataModel.Catalog);

                        int depth = hierarchyElement.Depth;
                        int order = hierarchyElement.Order;
                        if (config.DeviceElementId == adaptDeviceElement.ParentDeviceId)
                        {
                            //The configuration references the parent ISO element
                            depth = hierarchyElement.Parent.Depth;
                            order = hierarchyElement.Parent.Order;
                        }

                        deviceElementUse = sections.FirstOrDefault(d => d.DeviceConfigurationId == config.Id.ReferenceId);
                        if (deviceElementUse == null)
                        {
                            //Create the DeviceElementUse
                            deviceElementUse                       = new DeviceElementUse();
                            deviceElementUse.Depth                 = depth;
                            deviceElementUse.Order                 = order;
                            deviceElementUse.OperationDataId       = operationDataId;
                            deviceElementUse.DeviceConfigurationId = config.Id.ReferenceId;

                            //Add Working Data for any data on this device element
                            List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchyElement, sections, isoProductAllocations);
                            if (data.Any())
                            {
                                workingDatas.AddRange(data);
                            }
                        }
                        else
                        {
                            workingDatas = deviceElementUse.GetWorkingDatas().ToList();

                            //Add Additional Working Data
                            List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchyElement, sections, isoProductAllocations);
                            if (data.Any())
                            {
                                workingDatas.AddRange(data);
                            }
                        }

                        deviceElementUse.GetWorkingDatas = () => workingDatas;

                        if (!sections.Contains(deviceElementUse))
                        {
                            sections.Add(deviceElementUse);
                        }
                    }
                }
            }

            return(sections);
        }
示例#8
0
        public List <DeviceElementUse> Map(ISOTime time,
                                           IEnumerable <ISOSpatialRow> isoRecords,
                                           int operationDataId,
                                           IEnumerable <string> isoDeviceElementIDs,
                                           Dictionary <string, List <ISOProductAllocation> > isoProductAllocations)
        {
            var sections = new List <DeviceElementUse>();

            foreach (string isoDeviceElementID in isoDeviceElementIDs)
            {
                DeviceElementHierarchy hierarchy = TaskDataMapper.DeviceElementHierarchies.GetRelevantHierarchy(isoDeviceElementID);
                if (hierarchy != null)
                {
                    DeviceElementUse   deviceElementUse = null;
                    List <WorkingData> workingDatas     = new List <WorkingData>();

                    //Get the relevant DeviceElementConfiguration
                    int           adaptDeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID).Value;
                    DeviceElement adaptDeviceElement   = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == adaptDeviceElementId);
                    if (adaptDeviceElement != null)
                    {
                        DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchy, DataModel.Catalog);

                        int depth = hierarchy.Depth;
                        int order = hierarchy.Order;
                        if (config.DeviceElementId == adaptDeviceElement.ParentDeviceId)
                        {
                            //The configuration references the parent ISO element
                            depth = hierarchy.Parent.Depth;
                            order = hierarchy.Parent.Order;
                        }

                        //Read any spatially-listed widths/offsets on this data onto the DeviceElementConfiguration objects
                        hierarchy.SetWidthsAndOffsetsFromSpatialData(time, isoRecords, config, RepresentationMapper);

                        deviceElementUse = sections.FirstOrDefault(d => d.DeviceConfigurationId == config.Id.ReferenceId);
                        if (deviceElementUse == null)
                        {
                            //Create the DeviceElementUse
                            deviceElementUse                       = new DeviceElementUse();
                            deviceElementUse.Depth                 = depth;
                            deviceElementUse.Order                 = order;
                            deviceElementUse.OperationDataId       = operationDataId;
                            deviceElementUse.DeviceConfigurationId = config.Id.ReferenceId;

                            //Add Working Data for any data on this device element
                            List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchy, sections, isoProductAllocations);
                            if (data.Any())
                            {
                                workingDatas.AddRange(data);
                            }
                        }
                        else
                        {
                            workingDatas = deviceElementUse.GetWorkingDatas().ToList();

                            //Add Additional Working Data
                            List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchy, sections, isoProductAllocations);
                            if (data.Any())
                            {
                                workingDatas.AddRange(data);
                            }
                        }

                        deviceElementUse.GetWorkingDatas = () => workingDatas;

                        if (!sections.Contains(deviceElementUse))
                        {
                            sections.Add(deviceElementUse);
                        }
                    }
                    else if (hierarchy.DeviceElement.DeviceElementType == ISOEnumerations.ISODeviceElementType.Connector)
                    {
                        int?connectorID = TaskDataMapper.InstanceIDMap.GetADAPTID(hierarchy.DeviceElement.DeviceElementId).Value;
                        if (connectorID.HasValue)
                        {
                            Connector adaptConnector = DataModel.Catalog.Connectors.FirstOrDefault(c => c.Id.ReferenceId == connectorID.Value);
                            if (adaptConnector != null)
                            {
                                HitchPoint hitch = DataModel.Catalog.HitchPoints.FirstOrDefault(h => h.Id.ReferenceId == adaptConnector.HitchPointId);
                                if (hitch != null)
                                {
                                    hierarchy.SetHitchOffsetsFromSpatialData(time, isoRecords, hitch, RepresentationMapper);
                                }
                            }
                        }
                    }
                }
            }

            return(sections);
        }