public static void AreEqual(ISOSpatialRow isoSpatialRow, SpatialRecord adaptSpatialRecord, IEnumerable<WorkingData> meters) { foreach (var meter in meters) { var isoValue = isoSpatialRow.SpatialValues.SingleOrDefault(v => v.Id == meter.Id.FindIntIsoId()); if(isoValue == null) continue; if (meter is NumericWorkingData) { var numericMeter = meter as NumericWorkingData; var numericRepresentationValue = (NumericRepresentationValue)adaptSpatialRecord.GetMeterValue(numericMeter); if (isoValue != null) Assert.AreEqual(isoValue.Value, numericRepresentationValue.Value.Value); } if (meter is EnumeratedWorkingData) { var isoEnumeratedMeter = meter as ISOEnumeratedMeter; var enumeratedValue = isoEnumeratedMeter.GetEnumeratedValue(isoValue, isoEnumeratedMeter); Assert.AreEqual(enumeratedValue.Representation.Description, meter.Representation.Description); } } }
public SpatialRecord Map(ISOSpatialRow isoSpatialRow, List<WorkingData> meters) { var spatialRecord = new SpatialRecord(); foreach (var meter in meters.OfType<NumericWorkingData>()) { SetNumericMeterValue(isoSpatialRow, meter, spatialRecord); } foreach (var meter in meters.OfType<EnumeratedWorkingData>()) { SetEnumeratedMeterValue(isoSpatialRow, meter, spatialRecord); } spatialRecord.Geometry = new ApplicationDataModel.Shapes.Point { X = Convert.ToDouble(isoSpatialRow.EastPosition * CoordinateMultiplier), Y = Convert.ToDouble(isoSpatialRow.NorthPosition * CoordinateMultiplier), Z = isoSpatialRow.Elevation }; spatialRecord.Timestamp = isoSpatialRow.TimeStart; return spatialRecord; }
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); }
public IEnumerable<ISOSpatialRow> Read(string dataPath, string fileName, TIM tim) { if (tim == null) yield break; if (!File.Exists(Path.Combine(dataPath, fileName))) yield break; using (var binaryReader = new System.IO.BinaryReader(File.Open(Path.Combine(dataPath, fileName), FileMode.Open))) { while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { var ptn = tim.Items.FirstOrDefault(x => x.GetType() == typeof (PTN)) as PTN; var record = new ISOSpatialRow { TimeStart = GetStartTime(tim, binaryReader) }; if (ptn != null) { record.NorthPosition = ReadInt32(ptn.A, ptn.ASpecified, binaryReader).GetValueOrDefault(0); record.EastPosition = ReadInt32(ptn.B, ptn.BSpecified, binaryReader).GetValueOrDefault(0); record.Elevation = ReadInt32(ptn.C, ptn.CSpecified, binaryReader); record.PositionStatus = ReadByte(ptn.D, ptn.DSpecified, binaryReader); record.PDOP = ReadShort(ptn.E, ptn.ESpecified, binaryReader); record.HDOP = ReadShort(ptn.F, ptn.FSpecified, binaryReader); record.NumberOfSatellites = ReadByte(ptn.G, ptn.GSpecified, binaryReader); SetGpsUtcDateTime(ptn, record, binaryReader); } SetSpatialValues(tim, record, binaryReader); yield return record; } } }
private static void AreEqual(SpatialRecord adaptSpatialRecord, ISOSpatialRow isoSpatialRow, List<WorkingData> meters) { Assert.AreEqual(adaptSpatialRecord.Timestamp, isoSpatialRow.TimeStart); var point = (Point)adaptSpatialRecord.Geometry; Assert.AreEqual((int)(point.X / CoordinateMultiplier), isoSpatialRow.EastPosition, CoordinateMultiplier); Assert.AreEqual((int)(point.Y / CoordinateMultiplier), isoSpatialRow.NorthPosition, CoordinateMultiplier); Assert.AreEqual(point.Z, isoSpatialRow.Elevation); SpatialValueAssert.AreEqual(isoSpatialRow, adaptSpatialRecord, meters); }
private static void AreEqual(ISOSpatialRow isoSpatialRow, SpatialRecord adaptSpatialRecord, IEnumerable<WorkingData> meters) { Assert.AreEqual(isoSpatialRow.TimeStart, adaptSpatialRecord.Timestamp); var point = adaptSpatialRecord.Geometry as Point; Assert.AreEqual(isoSpatialRow.EastPosition * CoordinateMultiplier, point.X, 0.000001); Assert.AreEqual(isoSpatialRow.NorthPosition * CoordinateMultiplier, point.Y, 0.000001); Assert.AreEqual(isoSpatialRow.Elevation, point.Z); SpatialValueAssert.AreEqual(isoSpatialRow, adaptSpatialRecord, meters); }
public static void AreEqual(ISOSpatialRow isoSpatialRow, SpatialRecord adaptSpatialRecord, List<WorkingData> meters) { foreach (var meter in meters) { var adaptValue = adaptSpatialRecord.GetMeterValue(meter); if(adaptValue == null) continue; var isoValue = isoSpatialRow.SpatialValues.Single(v => v.Id == meter.Id.FindIntIsoId()); var adaptEnumeratedValue = adaptValue as EnumeratedValue; if (adaptEnumeratedValue != null) { var representation = RepresentationManager.Instance.Representations.First(x => x.DomainId == adaptEnumeratedValue.Representation.Code); Assert.AreEqual(representation.Ddi.GetValueOrDefault(), Convert.ToInt32(isoValue.Dlv.A, 16)); if(representation.Ddi == 141) CompareWorkState(adaptEnumeratedValue, isoValue); if (representation.Ddi == 157) CompareConnectorType(adaptEnumeratedValue, isoValue); if (representation.Ddi == 158) ComparePrescriptionControl(adaptEnumeratedValue, isoValue); if (representation.Ddi == 160) CompareSectionControlState(adaptEnumeratedValue, isoValue); if (representation.Ddi >= 161 && representation.Ddi <= 176) CompareCondensedWorkState(adaptEnumeratedValue, isoValue); if (representation.Ddi == 210) CompareSkyConditions(adaptEnumeratedValue, isoValue); if (representation.Ddi == 230) CompareNetWeightState(adaptEnumeratedValue, isoValue); if (representation.Ddi == 240) CompareActualLoadingSystemStatus(adaptEnumeratedValue, isoValue); if (representation.Ddi >= 290 && representation.Ddi < 305) CompareCondensedWorkState(adaptEnumeratedValue, isoValue); if (representation.Ddi >= 367 && representation.Ddi <= 382) CompareCondensedSectionOverrideState(adaptEnumeratedValue, isoValue); } var adaptNumericValue = adaptValue as NumericRepresentationValue; if (adaptNumericValue != null) { var representation = RepresentationManager.Instance.Representations.FirstOrDefault(x => x.DomainId == adaptNumericValue.Representation.Code); if (representation != null) Assert.AreEqual(representation.Ddi, Convert.ToInt32(isoValue.Dlv.A, 16)); Assert.AreEqual(adaptNumericValue.Value.Value, isoValue.Value); } } }
private int?GetZOffsetFromSpatialData(IEnumerable <ISOSpatialRow> isoRecords, string isoDeviceElementID, RepresentationMapper representationMapper) { double offset = 0d; ISOSpatialRow firstZOffset = isoRecords.FirstOrDefault(r => r.SpatialValues.Any(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0088")); if (firstZOffset != null) { offset = firstZOffset.SpatialValues.Single(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0088").Value; return((int)offset); } else { return(null); } }
private void SetEnumeratedMeterValue(ISOSpatialRow isoSpatialRow, EnumeratedWorkingData meter, SpatialRecord spatialRecord) { var isoValue = isoSpatialRow.SpatialValues.SingleOrDefault(v => v.Id == meter.Id.FindIntIsoId()); if (isoValue != null) { var isoEnumeratedMeter = meter as ISOEnumeratedMeter; var enumeratedValue = isoEnumeratedMeter.GetEnumeratedValue(isoValue, isoEnumeratedMeter); spatialRecord.SetMeterValue(meter, enumeratedValue); _representationValueInterpolator.SetMostRecentMeterValue(meter, enumeratedValue); } else { var value = _representationValueInterpolator.Interpolate(meter) as EnumeratedValue; spatialRecord.SetMeterValue(meter, value); } }
public void GivenCondensedWorkStateWithNoInstalledWhenCreateMetersThenNoMetersCreated() { var spatialRow = new ISOSpatialRow(); const long value = 0xFFFFFFFF; var spatialValue = new SpatialValue { Dlv = new DLV { A = "16F" }, Value = value }; spatialRow.SpatialValues = new List<SpatialValue> { spatialValue }; _isoSpatialRows = new List<ISOSpatialRow> { spatialRow }; var result = new CondensedSectionOverrideStateMeterCreator(367).CreateMeters(_isoSpatialRows); Assert.AreEqual(0, result.Count); }
/// <summary> /// Merge SpatialValues from provided SpatialRow into this one. /// </summary> /// <param name="otherRow"></param> /// <returns></returns> public ISOSpatialRow Merge(ISOSpatialRow otherRow) { if (otherRow == null) { return(this); } if (SpatialValues == null) { SpatialValues = new List <SpatialValue>(); } if (otherRow.SpatialValues != null) { SpatialValues.AddRange(otherRow.SpatialValues); } return(this); }
private int?GetWidthFromSpatialData(IEnumerable <ISOSpatialRow> isoRecords, string isoDeviceElementID, RepresentationMapper representationMapper) { double maxWidth = 0d; string updatedWidthDDI = null; 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 { //Find the largest working width 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); } }
public void GivenCondensedWorkStateWithSomeStatesNotInstalledThenOnlyCreatesInstalledSections() { var spatialRow = new ISOSpatialRow(); const long notInstalled = 3; long value = 0; for (int i = 15; i > 11; --i) { value |= (notInstalled << i * 2); } var spatialValue = new SpatialValue { Dlv = new DLV { A = "16F" }, Value = value }; spatialRow.SpatialValues = new List<SpatialValue> { spatialValue }; _isoSpatialRows = new List<ISOSpatialRow> { spatialRow }; var result = new CondensedSectionOverrideStateMeterCreator(367).CreateMeters(_isoSpatialRows); Assert.AreEqual(12, result.Count); }
public void GivenIsoSpatialRowsWithoutNumericMeterOnSecondWhenMapThenSecondValueIsInterpolator() { var spatialValue = new SpatialValue { Id = 0, Value = 12.3 }; _isoSpatialRow.SpatialValues = new List<SpatialValue> { spatialValue }; var isoSpatialRow2 = new ISOSpatialRow { SpatialValues = new List<SpatialValue>() }; _isoSpatialRows = new List<ISOSpatialRow> {_isoSpatialRow, isoSpatialRow2}; var meter = new NumericWorkingData { Representation = RepresentationInstanceList.vrAvgHarvestMoisture.ToModelRepresentation(), DeviceElementUseId = 1, UnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("prcnt") }; var uniqueId = new UniqueId { CiTypeEnum = CompoundIdentifierTypeEnum.String, Id = "DLV0" }; meter.Id.UniqueIds.Add(uniqueId); _meters.Add(meter); var numericRepresentation = new NumericRepresentationValue(meter.Representation as NumericRepresentation, meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, 2.3)); _spatialValueInterpolator.Setup(s => s.Interpolate(meter)).Returns(numericRepresentation); var result = Map().ToList(); Assert.AreEqual(numericRepresentation, result[1].GetMeterValue(meter) as NumericRepresentationValue); }
private static void SetSpatialValues(TIM tim, ISOSpatialRow record, System.IO.BinaryReader binaryReader) { var numberOfDLVs = binaryReader.ReadByte(); record.SpatialValues = new List<SpatialValue>(); for (int i = 0; i < numberOfDLVs; i++) { var order = binaryReader.ReadByte(); var value = binaryReader.ReadInt32(); record.SpatialValues.Add(CreateSpatialValue(tim, order, value)); } }
private void SetNumericMeterValue(ISOSpatialRow isoSpatialRow, NumericWorkingData meter, SpatialRecord spatialRecord) { var isoValue = isoSpatialRow.SpatialValues.SingleOrDefault(v => v.Id == meter.Id.FindIntIsoId()); 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 { var value = _representationValueInterpolator.Interpolate(meter) as NumericRepresentationValue; spatialRecord.SetMeterValue(meter, value); } }
private void SetGpsUtcDateTime(PTN ptn, ISOSpatialRow record, System.IO.BinaryReader binaryReader) { if (ptn.HSpecified) { if (ptn.H.HasValue) record.GpsUtcTime = Convert.ToInt32(ptn.H.Value); else record.GpsUtcTime = binaryReader.ReadInt32(); } if (ptn.ISpecified) { if (ptn.I.HasValue) record.GpsUtcDate = (short)ptn.I.Value; else record.GpsUtcDate = binaryReader.ReadInt16(); } if (record.GpsUtcDate != null && record.GpsUtcTime != null) record.GpsUtcDateTime = _firstDayOf1980.AddDays((double) record.GpsUtcDate).AddMilliseconds((double) record.GpsUtcTime); }
public void Setup() { _isoSpatialRow = new ISOSpatialRow(); _isoSpatialRows = new List<ISOSpatialRow> { _isoSpatialRow }; _meters = new List<WorkingData>(); _spatialValueInterpolator = new Mock<IRepresentationValueInterpolator>(); _spatialRecordMapper = new SpatialRecordMapper(_spatialValueInterpolator.Object); }
public void GivenIsoSpatialRowWithoutMeterWhenMapThenInterpolatorIsCalled() { var spatialValue = new SpatialValue { Id = 0, Value = 12.3 }; _isoSpatialRow.SpatialValues = new List<SpatialValue> { spatialValue }; var isoSpatialRow2 = new ISOSpatialRow { SpatialValues = new List<SpatialValue>() }; _isoSpatialRows = new List<ISOSpatialRow> {_isoSpatialRow, isoSpatialRow2}; var meter = new NumericWorkingData { Representation = RepresentationInstanceList.vrAvgHarvestMoisture.ToModelRepresentation(), DeviceElementUseId = 1, UnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("prcnt") }; var uniqueId = new UniqueId { CiTypeEnum = CompoundIdentifierTypeEnum.String, Id = "DLV0" }; meter.Id.UniqueIds.Add(uniqueId); _meters.Add(meter); Map().ToList(); _spatialValueInterpolator.Verify(s => s.Interpolate(It.IsAny<WorkingData>())); }
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); } }
public void GivenIsoSpatialRowsWithoutEnumeratedMeterOnSecondWhenMapThenSecondValueIsInterpolator() { var spatialValue = new SpatialValue { Id = 0, Value = 1 }; _isoSpatialRow.SpatialValues = new List<SpatialValue> { spatialValue }; var isoSpatialRow2 = new ISOSpatialRow {SpatialValues = new List<SpatialValue>()}; _isoSpatialRows = new List<ISOSpatialRow> { _isoSpatialRow, isoSpatialRow2 }; var meter = new ISOEnumeratedMeter { Representation = RepresentationInstanceList.dtSectionControlMasterState.ToModelRepresentation(), ValueCodes = new List<int> { 1, 2, 3 }, DeviceElementUseId = 1, GetEnumeratedValue = (sv, im) => new EnumeratedValue { Value = new AgGateway.ADAPT.ApplicationDataModel.Representations.EnumerationMember { Code = 3 } } }; var uniqueId = new UniqueId { CiTypeEnum = CompoundIdentifierTypeEnum.String, Id = "DLV0" }; meter.Id.UniqueIds.Add(uniqueId); _meters.Add(meter); var enumeratedRepresentation = new EnumeratedValue { Value = new AgGateway.ADAPT.ApplicationDataModel.Representations.EnumerationMember { Code = 3 } }; _spatialValueInterpolator.Setup(s => s.Interpolate(meter)).Returns(enumeratedRepresentation); var result = Map().ToList(); Assert.AreEqual(enumeratedRepresentation, result[1].GetMeterValue(meter) as EnumeratedValue); }