Ejemplo n.º 1
0
        private void SetNumericMeterValue(ISOSpatialRow isoSpatialRow, NumericWorkingData meter, SpatialRecord spatialRecord, Dictionary <string, List <ISOProductAllocation> > productAllocations)
        {
            var isoValue = isoSpatialRow.SpatialValues.FirstOrDefault(v =>
                                                                      v.DataLogValue.ProcessDataDDI != "DFFE" &&
                                                                      _workingDataMapper.DataLogValuesByWorkingDataID.ContainsKey(meter.Id.ReferenceId) &&
                                                                      v.DataLogValue.DeviceElementIdRef == _workingDataMapper.DataLogValuesByWorkingDataID[meter.Id.ReferenceId].DeviceElementIdRef &&
                                                                      v.DataLogValue.ProcessDataDDI == _workingDataMapper.DataLogValuesByWorkingDataID[meter.Id.ReferenceId].ProcessDataDDI);


            if (isoValue != null)
            {
                var value = new NumericRepresentationValue(meter.Representation as NumericRepresentation, meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, isoValue.Value));
                spatialRecord.SetMeterValue(meter, value);

                var other = new NumericRepresentationValue(meter.Representation as NumericRepresentation, meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, isoValue.Value));
                _representationValueInterpolator.SetMostRecentMeterValue(meter, other);
            }
            else if (meter.Representation.Code == "vrProductIndex")
            {
                string detID = _workingDataMapper.ISODeviceElementIDsByWorkingDataID[meter.Id.ReferenceId];
                if (productAllocations.ContainsKey(detID)) //The DeviceElement for this meter exists in the list of allocations
                {
                    double numericValue = 0d;
                    if (productAllocations[detID].Count == 1 || TimeLogMapper.GetDistinctProductIDs(_taskDataMapper, productAllocations).Count == 1)
                    {
                        //This product is consistent throughout the task on this device element
                        int?adaptProductID = _taskDataMapper.InstanceIDMap.GetADAPTID(productAllocations[detID].Single().ProductIdRef);
                        numericValue = adaptProductID.HasValue ? adaptProductID.Value : 0d;
                    }
                    else if (productAllocations[detID].Count > 1)
                    {
                        //There are multiple product allocations for the device element
                        //Find the product allocation that governs this timestamp
                        ISOProductAllocation relevantPan = productAllocations[detID].FirstOrDefault(p => Offset(p.AllocationStamp.Start) <= spatialRecord.Timestamp &&
                                                                                                    (p.AllocationStamp.Stop == null ||
                                                                                                     Offset(p.AllocationStamp.Stop) >= spatialRecord.Timestamp));
                        if (relevantPan != null)
                        {
                            int?adaptProductID = _taskDataMapper.InstanceIDMap.GetADAPTID(relevantPan.ProductIdRef);
                            numericValue = adaptProductID.HasValue ? adaptProductID.Value : 0d;
                        }
                    }
                    var value = new NumericRepresentationValue(meter.Representation as NumericRepresentation, meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, numericValue));
                    spatialRecord.SetMeterValue(meter, value);
                }
            }
            else
            {
                var value = _representationValueInterpolator.Interpolate(meter) as NumericRepresentationValue;
                spatialRecord.SetMeterValue(meter, value);
            }
        }
Ejemplo n.º 2
0
        private List <ISOProductAllocation> GetProductAllocationsForSummary(Summary summary)
        {
            List <ISOProductAllocation> productAllocations = null;

            if (summary.OperationSummaries != null && summary.OperationSummaries.Any())
            {
                productAllocations = new List <ISOProductAllocation>();
                foreach (OperationSummary operationSummary in summary.OperationSummaries)
                {
                    foreach (StampedMeteredValues values in operationSummary.Data)
                    {
                        ISOProductAllocation pan = new ISOProductAllocation();
                        pan.AllocationStamp = AllocationStampMapper.ExportAllocationStamp(values.Stamp);
                        pan.ProductIdRef    = TaskDataMapper.InstanceIDMap.GetISOID(operationSummary.ProductId);
                        productAllocations.Add(pan);
                    }
                }
            }
            return(productAllocations);
        }
Ejemplo n.º 3
0
        private void AddProductAllocationsForDeviceElement(Dictionary <string, List <ISOProductAllocation> > productAllocations, ISOProductAllocation pan, ISODeviceElement deviceElement)
        {
            if (!productAllocations.ContainsKey(deviceElement.DeviceElementId))
            {
                productAllocations.Add(deviceElement.DeviceElementId, new List <ISOProductAllocation>());
            }
            productAllocations[deviceElement.DeviceElementId].Add(pan);

            foreach (ISODeviceElement child in deviceElement.ChildDeviceElements)
            {
                AddProductAllocationsForDeviceElement(productAllocations, pan, child);
            }
        }
Ejemplo n.º 4
0
        private void SetNumericMeterValue(ISOSpatialRow isoSpatialRow, NumericWorkingData meter, SpatialRecord spatialRecord, Dictionary <string, List <ISOProductAllocation> > productAllocations)
        {
            var dataLogValue = _workingDataMapper.DataLogValuesByWorkingDataID.ContainsKey(meter.Id.ReferenceId)
                ? _workingDataMapper.DataLogValuesByWorkingDataID[meter.Id.ReferenceId]
                : null;
            var isoValue = dataLogValue != null
                           ? isoSpatialRow.SpatialValues.FirstOrDefault(v =>
                                                                        v.DataLogValue.ProcessDataDDI != "DFFE" &&
                                                                        v.DataLogValue.DeviceElementIdRef == dataLogValue.DeviceElementIdRef &&
                                                                        v.DataLogValue.ProcessDataDDI == dataLogValue.ProcessDataDDI)
                           : null;


            if (isoValue != null)
            {
                ADAPT.ApplicationDataModel.Common.UnitOfMeasure userProvidedUnitOfMeasure = meter.UnitOfMeasure; //Default; no display uom provided.
                var dvp = isoValue.DeviceProcessData?.DeviceValuePresentation;
                if (dvp != null)
                {
                    //If a DVP element is present, report out the desired display unit of measure as the UserProvidedUnitOfMeasure.
                    //This will not necessarily map to the Representation.UnitSystem.
                    userProvidedUnitOfMeasure = new ApplicationDataModel.Common.UnitOfMeasure()
                    {
                        Code = dvp.UnitDesignator, Scale = dvp.Scale, Offset = dvp.Offset
                    };
                }

                var value = new NumericRepresentationValue(meter.Representation as NumericRepresentation, userProvidedUnitOfMeasure, new NumericValue(meter.UnitOfMeasure, isoValue.Value));
                spatialRecord.SetMeterValue(meter, value);

                var other = new NumericRepresentationValue(meter.Representation as NumericRepresentation, userProvidedUnitOfMeasure, new NumericValue(meter.UnitOfMeasure, isoValue.Value));
                _representationValueInterpolator.SetMostRecentMeterValue(meter, other);
            }
            else if (meter.Representation.Code == "vrProductIndex")
            {
                string detID = _workingDataMapper.ISODeviceElementIDsByWorkingDataID[meter.Id.ReferenceId];
                if (productAllocations.ContainsKey(detID)) //The DeviceElement for this meter exists in the list of allocations
                {
                    var    productAllocationsForDeviceElement = productAllocations[detID];
                    double numericValue = 0d;
                    if (productAllocationsForDeviceElement.Count == 1 || TimeLogMapper.GetDistinctProductIDs(_taskDataMapper, productAllocations).Count == 1)
                    {
                        //This product is consistent throughout the task on this device element
                        int?adaptProductID = _taskDataMapper.InstanceIDMap.GetADAPTID(productAllocationsForDeviceElement.Single().ProductIdRef);
                        numericValue = adaptProductID.HasValue ? adaptProductID.Value : 0d;
                    }
                    else if (productAllocationsForDeviceElement.Count > 1)
                    {
                        //There are multiple product allocations for the device element
                        //Find the product allocation that governs this timestamp
                        ISOProductAllocation relevantPan = productAllocationsForDeviceElement.FirstOrDefault(p => Offset(p.AllocationStamp.Start) <= spatialRecord.Timestamp &&
                                                                                                             (p.AllocationStamp.Stop == null ||
                                                                                                              Offset(p.AllocationStamp.Stop) >= spatialRecord.Timestamp));
                        if (relevantPan == null)
                        {
                            //We couldn't correlate strictly based on time.  Check for a more general match on date alone before returning null.
                            var pansMatchingDate = productAllocationsForDeviceElement.Where(p => p.AllocationStamp.Start?.Date == p.AllocationStamp.Stop?.Date &&
                                                                                            p.AllocationStamp.Start?.Date == spatialRecord.Timestamp.Date);
                            if (pansMatchingDate.Count() == 1)
                            {
                                //Only one PAN on this date, use it.
                                relevantPan = pansMatchingDate.Single();
                            }
                        }

                        if (relevantPan != null)
                        {
                            int?adaptProductID = _taskDataMapper.InstanceIDMap.GetADAPTID(relevantPan.ProductIdRef);
                            numericValue = adaptProductID.HasValue ? adaptProductID.Value : 0d;
                        }
                    }
                    var value = new NumericRepresentationValue(meter.Representation as NumericRepresentation, meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, numericValue));
                    spatialRecord.SetMeterValue(meter, value);
                }
            }
            else
            {
                var value = _representationValueInterpolator.Interpolate(meter) as NumericRepresentationValue;
                spatialRecord.SetMeterValue(meter, value);
            }
        }
Ejemplo n.º 5
0
        private void AddProductAllocationsForDeviceElement(Dictionary <string, Dictionary <string, ISOProductAllocation> > productAllocations, ISOProductAllocation pan, ISODeviceElement deviceElement, string hierarchyPoistion)
        {
            if (!productAllocations.ContainsKey(deviceElement.DeviceElementId))
            {
                productAllocations.Add(deviceElement.DeviceElementId, new Dictionary <string, ISOProductAllocation>());
            }

            productAllocations[deviceElement.DeviceElementId][hierarchyPoistion] = pan;

            foreach (ISODeviceElement child in deviceElement.ChildDeviceElements)
            {
                AddProductAllocationsForDeviceElement(productAllocations, pan, child, hierarchyPoistion);
            }
        }