Esempio n. 1
0
 public static ApplicationDataModel.Common.UnitOfMeasure ToModelUom(this UnitOfMeasure uom)
 {
     var unitOfMeasure = new ApplicationDataModel.Common.UnitOfMeasure
     {
         Code = uom.DomainID,
     };
     var scalarUom = uom as ScalarUnitOfMeasure;
     if (scalarUom != null)
     {
         unitOfMeasure.Scale = scalarUom.Scale;
         unitOfMeasure.Offset = scalarUom.BaseOffset;
     }
     return unitOfMeasure;
 }
Esempio n. 2
0
        public static ApplicationDataModel.Common.UnitOfMeasure ToModelUom(this UnitOfMeasure uom)
        {
            var unitOfMeasure = new ApplicationDataModel.Common.UnitOfMeasure
            {
                Code = uom.DomainID,
            };
            var scalarUom = uom as ScalarUnitOfMeasure;

            if (scalarUom != null)
            {
                unitOfMeasure.Scale  = scalarUom.Scale;
                unitOfMeasure.Offset = scalarUom.BaseOffset;
            }
            return(unitOfMeasure);
        }
 public static ApplicationDataModel.Common.UnitOfMeasure ToModelUom(this UnitOfMeasure uom)
 {
     var unitOfMeasure = new ApplicationDataModel.Common.UnitOfMeasure
     {
         Code = uom.DomainID,
     };
     var unitDimensionId = uom.UnitDimension != null ? uom.UnitDimension.DomainID.TrimStart(new []{'u','t'}) : null;
     if (unitDimensionId != null)
     {
         var adaptUnitDimension = (UnitOfMeasureDimensionEnum) Enum.Parse(typeof (UnitOfMeasureDimensionEnum), unitDimensionId);
         unitOfMeasure.Dimension = adaptUnitDimension;
     }
     var scalarUom = uom as ScalarUnitOfMeasure;
     if (scalarUom != null)
     {
         unitOfMeasure.Scale = scalarUom.Scale;
         unitOfMeasure.Offset = scalarUom.BaseOffset;
     }
     return unitOfMeasure;
 }
Esempio n. 4
0
        public static ApplicationDataModel.Common.UnitOfMeasure ToModelUom(this UnitOfMeasure uom)
        {
            var unitOfMeasure = new ApplicationDataModel.Common.UnitOfMeasure
            {
                Code = uom.DomainID,
            };
            var unitDimensionId = uom.UnitDimension != null?uom.UnitDimension.DomainID.TrimStart(new [] { 'u', 't' }) : null;

            if (unitDimensionId != null)
            {
                var adaptUnitDimension = (UnitOfMeasureDimensionEnum)Enum.Parse(typeof(UnitOfMeasureDimensionEnum), unitDimensionId);
                unitOfMeasure.Dimension = adaptUnitDimension;
            }
            var scalarUom = uom as ScalarUnitOfMeasure;

            if (scalarUom != null)
            {
                unitOfMeasure.Scale  = scalarUom.Scale;
                unitOfMeasure.Offset = scalarUom.BaseOffset;
            }
            return(unitOfMeasure);
        }
Esempio n. 5
0
 public static UnitOfMeasure ToInternalUom(this ApplicationDataModel.Common.UnitOfMeasure uom)
 {
     return(InternalUnitSystemManager.Instance.UnitOfMeasures[uom.Code]);
 }
Esempio n. 6
0
 public static string GetUNRec20Code(ApplicationDataModel.Common.UnitOfMeasure uom)
 {
     return(InternalUnitSystemManager.Instance.DomainIdToUnRec20Code[uom.Code]);
 }
        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)
            {
                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
                {
                    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);
            }
        }
Esempio n. 8
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);
        }