public void Test_ProjectImmutableDataEventsTests_OverrideEvents() { var siteModel = new SiteModel(Guid.Empty, StorageMutability.Immutable, false); var events = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); var referenceDate = DateTime.UtcNow; events.DesignOverrideEvents.PutValueAtDate(referenceDate.AddMinutes(-60), new OverrideEvent <int>(referenceDate.AddMinutes(-50), 0)); events.DesignOverrideEvents.PutValueAtDate(referenceDate.AddMinutes(-30), new OverrideEvent <int>(referenceDate.AddMinutes(-15), 1)); Assert.True(2 == events.DesignOverrideEvents.Count(), $"List contains {events.DesignOverrideEvents.Count()} DesignOverride events, instead of 2"); var mutableStream = events.DesignOverrideEvents.GetMutableStream(); var targetEventList = Deserialize(mutableStream); Assert.Equal(2, targetEventList.Count()); var evt = ((ProductionEvents <OverrideEvent <int> >)targetEventList).Events[0]; events.DesignOverrideEvents.GetStateAtIndex(0, out var dateTime, out var state); Assert.Equal(state, evt.State); Assert.Equal(dateTime, evt.Date); var immutableStream = events.DesignOverrideEvents.GetImmutableStream(); targetEventList = Deserialize(immutableStream); Assert.Equal(2, targetEventList.Count()); events.DesignOverrideEvents.GetStateAtIndex(0, out dateTime, out state); Assert.Equal(state, evt.State); Assert.Equal(dateTime, evt.Date); }
public void Test_TerrainSwather_SwathExtentTooLarge() { var siteModel = new SiteModel(StorageMutability.Immutable); var machine = new Machine(); var grid = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var SiteModelGridAggregator = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); var processor = new TAGProcessor(siteModel, machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); var fence = new Fence(new BoundingWorldExtent3D(0, 0, 10000, 2)); var swather = new TerrainSwather(processor, MachineTargetValueChangesAggregator, siteModel, grid, fence); CreateSwathContext(0, 0, 0, 10000, 0, 0, 0, 2, 0, 10000, 2, 0, out SimpleTriangle HeightInterpolator1, out SimpleTriangle HeightInterpolator2, out SimpleTriangle TimeInterpolator1, out SimpleTriangle TimeInterpolator2); bool swathResult = swather.PerformSwathing(HeightInterpolator1, HeightInterpolator2, TimeInterpolator1, TimeInterpolator2, false, PassType.Front, MachineSide.None); swathResult.Should().BeTrue(); processor.ProcessedEpochCount.Should().Be(0); processor.ProcessedCellPassesCount.Should().Be(0); }
public void Test_ProjectImmutableDataEventsTests_MachineDesignNameIDStateEvents_SaveAndLoad() { var siteModel = new SiteModel(Guid.Empty, StorageMutability.Immutable, false); var events = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); DateTime referenceDate = DateTime.UtcNow; events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-60), 0); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-30), 1); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-29), 1); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-29), 2); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-29), 3); Assert.True(3 == events.MachineDesignNameIDStateEvents.Count(), $"List contains {events.MachineDesignNameIDStateEvents.Count()} MachineDesignName events, instead of 3"); var storageProxy = new StorageProxy_Ignite_Transactional(StorageMutability.Mutable); storageProxy.SetImmutableStorageProxy(new StorageProxy_Ignite_Transactional(StorageMutability.Immutable)); events.SaveMachineEventsToPersistentStore(storageProxy); var resultantEvents = events.GetEventList(ProductionEventType.DesignChange); Assert.Equal(3, resultantEvents.Count()); resultantEvents.LoadFromStore(storageProxy.ImmutableProxy); Assert.Equal(2, resultantEvents.Count()); resultantEvents.LoadFromStore(storageProxy); Assert.Equal(3, resultantEvents.Count()); }
public void Test_TAGProcessor_DoPostProcessFileAction() { var SiteModel = new SiteModel(StorageMutability.Immutable); var Machine = new Machine(); var SiteModelGridAggregator = new ServerSubGridTree(SiteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); TAGProcessor processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); // Set the state of the processor to emulate the end of processing this TAG file at which point the processor should emit // a "Stop recording event". In this instance, the NoGPSModeSet flag will also be true which should trigger emission of // a 'NoGPS' GPS mode state event and a 'UTS' positioning technology state event DateTime eventDate = DateTime.SpecifyKind(new DateTime(2000, 1, 1, 1, 1, 1), DateTimeKind.Utc); // Setting the first data time will create the start event processor.DataTime = eventDate; DateTime eventDate2 = eventDate.AddMinutes(1); processor.DataTime = eventDate2; processor.DoPostProcessFileAction(true); Assert.True(MachineTargetValueChangesAggregator.GPSModeStateEvents.LastStateValue() == GPSMode.NoGPS && MachineTargetValueChangesAggregator.GPSModeStateEvents.LastStateDate() == eventDate, "DoPostProcessFileAction did not set GPSMode event"); Assert.True(MachineTargetValueChangesAggregator.PositioningTechStateEvents.LastStateValue() == PositioningTech.UTS && MachineTargetValueChangesAggregator.PositioningTechStateEvents.LastStateDate() == eventDate, "DoPostProcessFileAction did not set positioning tech event"); Assert.True(MachineTargetValueChangesAggregator.StartEndRecordedDataEvents.LastStateValue() == ProductionEventType.EndEvent /*EndRecordedData*/ && MachineTargetValueChangesAggregator.StartEndRecordedDataEvents.LastStateDate() == eventDate2, "DoPostProcessFileAction did not set end recorded data event"); }
public void Test_Events_Serialization <T>(Func <ProductionEventLists, IProductionEvents <T> > eventList, T evt1, T evt2) { var siteModel = new SiteModel(Guid.Empty, StorageMutability.Immutable, false); var events = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); var referenceDate = DateTime.UtcNow; eventList(events).PutValueAtDate(referenceDate.AddMinutes(-60), evt1); eventList(events).PutValueAtDate(referenceDate.AddMinutes(-30), evt2); eventList(events).Count().Should().Be(2); var storageProxy = new StorageProxy_Ignite_Transactional(StorageMutability.Mutable); storageProxy.SetImmutableStorageProxy(new StorageProxy_Ignite_Transactional(StorageMutability.Immutable)); events.SaveMachineEventsToPersistentStore(storageProxy); var resultantEvents = eventList(events); // events.GetEventList(ProductionEventType.GPSAccuracyChange); resultantEvents.Count().Should().Be(2); resultantEvents.LoadFromStore(storageProxy.ImmutableProxy); resultantEvents.Count().Should().Be(2); ((ProductionEvents <T>)resultantEvents).Events[0].State.Should().BeEquivalentTo(evt1); ((ProductionEvents <T>)resultantEvents).Events[1].State.Should().BeEquivalentTo(evt2); }
public void Test_ProjectImmutableDataEventsTests_Duplicates() { var siteModel = new SiteModel(Guid.Empty, StorageMutability.Immutable, false); var events = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); DateTime referenceDate = DateTime.UtcNow; events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-60), 0); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-30), 1); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-29), 1); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-29), 2); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-29), 3); Assert.True(3 == events.MachineDesignNameIDStateEvents.Count(), $"List contains {events.MachineDesignNameIDStateEvents.Count()} MachineDesignName events, instead of 3"); var mutableStream = events.MachineDesignNameIDStateEvents.GetMutableStream(); var targetEventList = Deserialize(mutableStream); Assert.Equal(3, targetEventList.Count()); events.MachineDesignNameIDStateEvents.GetStateAtIndex(0, out DateTime dateTime, out int state); var evt = ((ProductionEvents <int>)targetEventList).Events[0]; Assert.Equal(state, evt.State); Assert.Equal(dateTime, evt.Date); var immutableStream = events.MachineDesignNameIDStateEvents.GetImmutableStream(); targetEventList = Deserialize(immutableStream); Assert.Equal(2, targetEventList.Count()); events.MachineDesignNameIDStateEvents.GetStateAtIndex(0, out dateTime, out state); events.MachineDesignNameIDStateEvents.GetStateAtIndex(0, out dateTime, out state); Assert.Equal(state, evt.State); Assert.Equal(dateTime, evt.Date); }
public void Test_TAGProcessor_Creation() { var SiteModel = new SiteModel(StorageMutability.Immutable); var Machine = new Machine(); var SiteModelGridAggregator = new ServerSubGridTree(SiteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); TAGProcessor processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); Assert.NotNull(processor); }
/// <summary> /// Primary constructor for the TAGProcessor. The arguments passed to it are: /// 1. The target SiteModel which is intended to be the recipient of the TAG information processed /// 2. The target Machine in the site model which recorded the TAG information /// 3. The event lists related to the target machine in the target site model /// 4. A subgrid tree representing the aggregator for all the spatial cell pass information processed /// from the TAG information as an independent entity. /// 5. A set of event lists representing the aggregator for all the machine events for the target machine /// in the target site model that were processed from the TAG information as a separate entity. /// </summary> /// <param name="targetSiteModel"></param> /// <param name="targetMachine"></param> /// <param name="siteModelGridAggregator"></param> /// <param name="machineTargetValueChangesAggregator"></param> public TAGProcessor(ISiteModel targetSiteModel, IMachine targetMachine, IServerSubGridTree siteModelGridAggregator, ProductionEventLists machineTargetValueChangesAggregator) : this() { SiteModel = targetSiteModel; Machine = targetMachine; SiteModelGridAggregator = siteModelGridAggregator; MachineTargetValueChangesAggregator = machineTargetValueChangesAggregator; // MachineTargetValueChangesAggregator.MarkAllEventListsAsInMemoryOnly; }
public void Test_TAGProcessor_DoEpochPreProcessAction() { var SiteModel = new SiteModel(StorageMutability.Immutable); var Machine = new Machine(); var SiteModelGridAggregator = new ServerSubGridTree(SiteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); TAGProcessor processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); Assert.True(processor.DoEpochPreProcessAction(), "EpochPreProcessAction returned false in default TAGProcessor state"); // Current PreProcessAction activity is limited to handling proofing runs. This will be handled by proofing run tests elsewhere }
public void Test_TerrainSwather_Creation() { var siteModel = new SiteModel(StorageMutability.Immutable); var machine = new Machine(); var grid = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var fence = new Fence(); var SiteModelGridAggregator = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); var processor = new TAGProcessor(siteModel, machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); var swather = new TerrainSwather(processor, MachineTargetValueChangesAggregator, siteModel, grid, fence); Assert.True(swather != null, "TerrainSwather not created as expected"); }
public void Test_MutabilityConverterTests_ConvertEventListTest() { DIBuilder .Continue() .Add(VSS.TRex.Storage.Utilities.DIUtilities.AddProxyCacheFactoriesToDI) .Build(); var storageProxy = new StorageProxy_Ignite_Transactional(StorageMutability.Mutable); storageProxy.SetImmutableStorageProxy(new StorageProxy_Ignite_Transactional(StorageMutability.Immutable)); var moqSiteModels = new Mock <ISiteModels>(); moqSiteModels.Setup(mk => mk.PrimaryMutableStorageProxy).Returns(storageProxy); DIBuilder .Continue() .Add(x => x.AddSingleton <IProductionEventsFactory>(new ProductionEventsFactory())) .Add(x => x.AddSingleton <ISiteModels>(moqSiteModels.Object)) .Complete(); var siteModel = new SiteModel(Guid.Empty, StorageMutability.Immutable, true); var events = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); DateTime ReferenceTime = DateTime.UtcNow; events.MachineDesignNameIDStateEvents.PutValueAtDate(ReferenceTime.AddMinutes(-60), 0); events.MachineDesignNameIDStateEvents.PutValueAtDate(ReferenceTime.AddMinutes(-30), 1); events.MachineDesignNameIDStateEvents.PutValueAtDate(ReferenceTime.AddMinutes(-29), 1); events.MachineDesignNameIDStateEvents.PutValueAtDate(ReferenceTime.AddMinutes(-29), 2); events.MachineDesignNameIDStateEvents.PutValueAtDate(ReferenceTime.AddMinutes(-29), 3); Assert.True(3 == events.MachineDesignNameIDStateEvents.Count(), $"List contains {events.MachineDesignNameIDStateEvents.Count()} MachineDesignName events, instead of 3"); var mutableStream = events.MachineDesignNameIDStateEvents.GetMutableStream(); var targetEventList = Deserialize(mutableStream); Assert.Equal(3, targetEventList.Count()); var mutabilityConverter = new MutabilityConverter(); mutabilityConverter.ConvertToImmutable(FileSystemStreamType.Events, null, events.MachineDesignNameIDStateEvents, out MemoryStream immutableStream); targetEventList = Deserialize(immutableStream); Assert.Equal(2, targetEventList.Count()); mutabilityConverter.ConvertToImmutable(FileSystemStreamType.Events, mutableStream, null, out immutableStream); targetEventList = Deserialize(immutableStream); Assert.Equal(2, targetEventList.Count()); }
public void LoadFile() { using var stream = new FileStream(FILENAME, FileMode.Open, FileAccess.Read); var file = new VolvoEarthworksCSVReader(stream); var siteModel = new SiteModel(StorageMutability.Immutable); var machine = new Machine(); var siteModelGridAggregator = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var machineTargetValueChangesAggregator = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); var processor = new TAGProcessor(siteModel, machine, siteModelGridAggregator, machineTargetValueChangesAggregator); file.Read(null, processor); processor.ProcessedEpochCount.Should().Be(19325); siteModelGridAggregator.CountLeafSubGridsInMemory().Should().Be(11); }
public void Test_TAGProcessor_TestZeroValuesInvalid() { var SiteModel = new SiteModel(StorageMutability.Immutable); var Machine = new Machine(); var SiteModelGridAggregator = new ServerSubGridTree(SiteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); TAGProcessor processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); Assert.True(processor.ICMDPValues.GetLatest() == CellPassConsts.NullMDP, "MDP Initial value incorrect"); Assert.True(processor.ICCCVValues.GetLatest() == CellPassConsts.NullCCV, "CCV Initial value incorrect"); Assert.True(processor.ICCCAValues.GetLatest() == CellPassConsts.NullCCA, "CCA Initial value incorrect"); processor.SetICMDPValue(0); processor.SetICCCVValue(0); processor.SetICCCAValue(0); Assert.True(processor.ICMDPValues.GetLatest() == CellPassConsts.NullMDP, "Zero should not be a valid for MDP"); Assert.True(processor.ICCCVValues.GetLatest() == CellPassConsts.NullCCV, "Zero should not be a valid for CCV"); Assert.True(processor.ICCCAValues.GetLatest() == CellPassConsts.NullCCA, "Zero should not be a valid for CCA"); }
public void Test_ProjectImmutableDataEventsTests_AllTypesNoDuplicates() { var siteModel = new SiteModel(Guid.Empty, StorageMutability.Immutable, false); var events = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); DateTime referenceDate = DateTime.UtcNow; events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-60), 0); events.MachineDesignNameIDStateEvents.PutValueAtDate(referenceDate.AddMinutes(-30), 1); Assert.True(2 == events.MachineDesignNameIDStateEvents.Count(), $"List contains {events.MachineDesignNameIDStateEvents.Count()} MachineDesignName events, instead of 2"); events.GPSAccuracyAndToleranceStateEvents.PutValueAtDate(referenceDate.AddMinutes(-60), new GPSAccuracyAndTolerance(GPSAccuracy.Coarse, 2)); events.GPSAccuracyAndToleranceStateEvents.PutValueAtDate(referenceDate.AddMinutes(-58), new GPSAccuracyAndTolerance(GPSAccuracy.Medium, 2)); events.GPSAccuracyAndToleranceStateEvents.PutValueAtDate(referenceDate.AddMinutes(-56), new GPSAccuracyAndTolerance(GPSAccuracy.Coarse, 1)); Assert.True(3 == events.GPSAccuracyAndToleranceStateEvents.Count(), $"List contains {events.GPSAccuracyAndToleranceStateEvents.Count()} GPSAccuracy events, instead of 3"); var storageProxy = new StorageProxy_Ignite_Transactional(StorageMutability.Mutable); storageProxy.SetImmutableStorageProxy(new StorageProxy_Ignite_Transactional(StorageMutability.Immutable)); events.SaveMachineEventsToPersistentStore(storageProxy); }
public void Test_AggregatedDataIntegratorWorker_EventIntegrator_NoOverlappedDesignIds() { /* * source list * id Value * 0 'DesignName2' * 1 'DesignName4' * * target list * id Value * 0 'DesignName5' */ var eventIntegrator = new EventIntegrator(); var sourceSiteModel = BuildModel(); var design3 = sourceSiteModel.SiteModelMachineDesigns.CreateNew("DesignName2"); var design4 = sourceSiteModel.SiteModelMachineDesigns.CreateNew("DesignName4"); var sourceEventList = new ProductionEventLists(sourceSiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); sourceEventList.MachineDesignNameIDStateEvents.PutValueAtDate(DateTime.UtcNow.AddMinutes(-60), design3.Id); sourceEventList.MachineDesignNameIDStateEvents.PutValueAtDate(DateTime.UtcNow.AddMinutes(-30), design4.Id); Assert.Equal(2, sourceEventList.MachineDesignNameIDStateEvents.Count()); var targetSiteModel = BuildModel(); var design5 = targetSiteModel.SiteModelMachineDesigns.CreateNew("DesignName5"); Assert.Equal(2, targetSiteModel.SiteModelMachineDesigns.Count); var targetEventList = new ProductionEventLists(targetSiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); targetEventList.MachineDesignNameIDStateEvents.PutValueAtDate(DateTime.UtcNow.AddMinutes(-32), design5.Id); Assert.Equal(1, targetEventList.MachineDesignNameIDStateEvents.Count()); eventIntegrator.IntegrateMachineEvents(sourceEventList, targetEventList, false, sourceSiteModel, targetSiteModel); Assert.Equal(4, targetSiteModel.SiteModelMachineDesigns.Count); // integration re-orders the event lists so cannot locate orig by [] Assert.Equal(1, targetSiteModel.SiteModelMachineDesigns.Locate("DesignName5").Id); Assert.Equal(2, targetSiteModel.SiteModelMachineDesigns.Locate("DesignName2").Id); Assert.Equal(3, targetSiteModel.SiteModelMachineDesigns.Locate("DesignName4").Id); }
public void Test_TAGProcessor_ProcessEpochContext_WithValidPosition() { var SiteModel = new SiteModel(StorageMutability.Immutable); SiteModel.IgnoreInvalidPositions = false; var Machine = new Machine(); var SiteModelGridAggregator = new ServerSubGridTree(SiteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); TAGProcessor processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); // Set the blade left and right tip locations to a trivial epoch, the epoch and do it again to trigger a swathing scan, then // check to see if it generated anything! Fence interpolationFence = new Fence(); interpolationFence.SetRectangleFence(0, 0, 1, 1); DateTime StartTime = DateTime.SpecifyKind(new DateTime(2000, 1, 1, 1, 1, 1), DateTimeKind.Utc); processor.DataLeft = new XYZ(0, 0, 5); processor.DataRight = new XYZ(1, 0, 5); processor.DataTime = StartTime; Assert.True(processor.ProcessEpochContext(), "ProcessEpochContext returned false in default TAGProcessor state (1)"); DateTime EndTime = DateTime.SpecifyKind(new DateTime(2000, 1, 1, 1, 1, 3), DateTimeKind.Utc); processor.DataLeft = new XYZ(0, 1, 5); processor.DataRight = new XYZ(1, 1, 5); processor.DataTime = EndTime; Assert.True(processor.ProcessEpochContext(), "ProcessEpochContext returned false in default TAGProcessor state (2)"); Assert.Equal(9, processor.ProcessedCellPassesCount); Assert.Equal(2, processor.ProcessedEpochCount); }
public void Test_TAGProcessor_ProcessEpochContext_WithoutValidTimestamp() { var SiteModel = new SiteModel(StorageMutability.Immutable); SiteModel.IgnoreInvalidPositions = false; var Machine = new Machine(); var SiteModelGridAggregator = new ServerSubGridTree(SiteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, MachineConsts.kNullInternalSiteModelMachineIndex); TAGProcessor processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); // Set the blade left and right tip locations to a trivial epoch, the epoch and do it again to trigger a swathing scan, then // check to see if it generated anything! Fence interpolationFence = new Fence(); interpolationFence.SetRectangleFence(0, 0, 1, 1); processor.DataLeft = new XYZ(0, 0, 5); processor.DataRight = new XYZ(1, 0, 5); Assert.False(processor.ProcessEpochContext(), "ProcessEpochContext returned true without a valid epoch timestamp"); }
/// <summary> /// Execute the conversion operation on the Volvo earthworks CSV file /// NOTE: This is a POC implementation and does not support some behaviours in the legacy TAG file ingest pathway /// </summary> public bool ExecuteVolvoEarthworksCSVFile(string filename, Stream tagData, Guid assetUid, bool isJohnDoe) { ReadResult = TAGReadResult.NoError; Log.LogInformation($"In {nameof(ExecuteVolvoEarthworksCSVFile)}: reading file {filename} for asset {assetUid}, JohnDoe: {isJohnDoe}"); try { var fileDescriptor = new VolvoEarthworksFileNameDescriptor(filename); Processor?.Dispose(); // Locate the machine in the local set of machines, adding one if necessary Machine = Machines.Locate(assetUid, true /*isJohnDoe - hard code Volvo machines to be John Does for POC*/); var machineType = MachineType.Unknown; var machineHardwareId = fileDescriptor.MachineID; var machineId = fileDescriptor.MachineID; if (Machine == null) { Log.LogDebug($"Creating new machine in common converter for AssetUid = {assetUid}, JohnDoe = {isJohnDoe}, machineId = {machineId}, machineHardwareId = {machineHardwareId}"); Machine = Machines.CreateNew(machineId, machineHardwareId, machineType, DeviceTypeEnum.MANUALDEVICE, isJohnDoe, assetUid); } var holdMachineType = Machine.MachineType; // Locate the aggregator, adding one if necessary var machineTargetValueChangesAggregator = MachinesTargetValueChangesAggregator[Machine.InternalSiteModelMachineIndex] as ProductionEventLists; if (machineTargetValueChangesAggregator == null) { machineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, Machine.InternalSiteModelMachineIndex); MachinesTargetValueChangesAggregator.Add(machineTargetValueChangesAggregator); } Processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, machineTargetValueChangesAggregator); var sink = new TAGValueSink(Processor); var reader = new VolvoEarthworksCSVReader(tagData); ReadResult = reader.Read(sink, Processor); // Notify the processor that all reading operations have completed for the file Processor.DoPostProcessFileAction(ReadResult == TAGReadResult.NoError); SetPublishedState(Processor); Machine.MachineType = holdMachineType; if (ReadResult != TAGReadResult.NoError) { return(false); } } catch (Exception e) // make sure any exception is trapped to return correct response to caller { Log.LogError(e, "Exception occurred while converting a Volvo CSV file"); return(false); } return(true); }
/// <summary> /// Execute the conversion operation on the TAG file, returning a boolean success result. /// Sets up local state detailing the pre-scan fields retrieved from the TAG file /// </summary> public bool ExecuteLegacyTAGFile(string filename, Stream tagData, Guid assetUid, bool isJohnDoe) { Log.LogInformation($"In {nameof(ExecuteLegacyTAGFile)}: reading file {filename} for asset {assetUid}, JohnDoe: {isJohnDoe}"); ReadResult = TAGReadResult.NoError; List <UTMCoordPointPair> aCSBladePositions = null; List <UTMCoordPointPair> ACSRearAxlePositions = null; List <UTMCoordPointPair> ACSTrackPositions = null; List <UTMCoordPointPair> ACSWheelPositions = null; try { Processor?.Dispose(); // Locate the machine in the local set of machines, adding one if necessary Machine = Machines.Locate(assetUid, isJohnDoe); var machineType = MachineType.Unknown; var machineHardwareId = string.Empty; var machineId = string.Empty; //Prescan to get all relevant information necessary for processing the tag file. e.g. Machinetype for swather, Type of coordinate system (ACS) var tagFilePreScan = new TAGFilePreScan(); tagFilePreScan.Execute(tagData); tagData.Position = 0; // reset if (tagFilePreScan.ReadResult == TAGReadResult.NoError) { machineType = tagFilePreScan.MachineType; // used in creation of swather machineHardwareId = tagFilePreScan.HardwareID; machineId = tagFilePreScan.MachineID; IsUTMCoordinateSystem = !tagFilePreScan.IsCSIBCoordSystemTypeOnly; // do we need to convert UTM coordinates to project coordinates if (IsUTMCoordinateSystem && tagFilePreScan.ProcessedEpochCount > 0) { Log.LogInformation($"{nameof(ExecuteLegacyTAGFile)}: ACS coordinate system detected. {filename}"); aCSBladePositions = new List <UTMCoordPointPair>(); ACSRearAxlePositions = new List <UTMCoordPointPair>(); ACSTrackPositions = new List <UTMCoordPointPair>(); ACSWheelPositions = new List <UTMCoordPointPair>(); if (!CollectAndConvertBladePostions(_targetSiteModel, ref tagData, ref aCSBladePositions, ref ACSRearAxlePositions, ref ACSTrackPositions, ref ACSWheelPositions)) { Log.LogError($"{nameof(ExecuteLegacyTAGFile)}: Failed to collect and convert blade positions for tagfile processing with ACS. TAG FILE:{filename}"); ReadResult = TAGReadResult.CoordinateConversionFailure; return(false); } } } else { Log.LogError($"Unsuccessful prescan of tagfile. {tagFilePreScan.ReadResult}"); return(false); } if (Machine == null) { // Now we know more about the machine have another go finding it Machine = Machines.Locate(assetUid, machineId, isJohnDoe); } if (Machine == null) { Log.LogDebug($"Creating new machine in common converter for AssetUid = {assetUid}, JohnDoe = {isJohnDoe}, machineId = {machineId}, machineHardwareId = {machineHardwareId}"); Machine = Machines.CreateNew(machineId, machineHardwareId, machineType, DeviceTypeEnum.MANUALDEVICE, isJohnDoe, assetUid); } if (Machine.MachineType == MachineType.Unknown && machineType != MachineType.Unknown) { Machine.MachineType = machineType; } var holdMachineType = Machine.MachineType; // Locate the aggregator, adding one if necessary var machineTargetValueChangesAggregator = MachinesTargetValueChangesAggregator[Machine.InternalSiteModelMachineIndex] as ProductionEventLists; if (machineTargetValueChangesAggregator == null) { machineTargetValueChangesAggregator = new ProductionEventLists(SiteModel, Machine.InternalSiteModelMachineIndex); MachinesTargetValueChangesAggregator.Add(machineTargetValueChangesAggregator); } Processor = new TAGProcessor(SiteModel, Machine, SiteModelGridAggregator, machineTargetValueChangesAggregator); // If ACS coordinate system populate converted UTM coordinates if (IsUTMCoordinateSystem && tagFilePreScan.ProcessedEpochCount > 0) { if (aCSBladePositions != null && aCSBladePositions.Count > 0) { Processor.ConvertedBladePositions.AddRange(aCSBladePositions); } if (ACSRearAxlePositions != null && ACSRearAxlePositions.Count > 0) { Processor.ConvertedRearAxlePositions.AddRange(ACSRearAxlePositions); } if (ACSTrackPositions != null && ACSTrackPositions.Count > 0) { Processor.ConvertedTrackPositions.AddRange(ACSTrackPositions); } if (ACSWheelPositions != null && ACSWheelPositions.Count > 0) { Processor.ConvertedWheelPositions.AddRange(ACSWheelPositions); } } var sink = new TAGValueSink(Processor); using (var reader = new TAGReader(tagData)) { var tagFile = new TAGFile(); ReadResult = tagFile.Read(reader, sink); // Notify the processor that all reading operations have completed for the file Processor.DoPostProcessFileAction(ReadResult == TAGReadResult.NoError); SetPublishedState(Processor); Machine.MachineType = holdMachineType; if (ReadResult != TAGReadResult.NoError) { return(false); } } } catch (Exception e) // make sure any exception is trapped to return correct response to caller { Log.LogError(e, "Exception occurred while converting a TAG file"); return(false); } return(true); }
public void Test_TerrainSwather_PerformSwathing() { var siteModel = new SiteModel(StorageMutability.Immutable); var machine = new VSS.TRex.Machines.Machine(); var grid = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var SiteModelGridAggregator = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); var processor = new TAGProcessor(siteModel, machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); var fence = new Fence(); fence.SetRectangleFence(0, 0, 10, 2); TerrainSwather swather = new TerrainSwather(processor, MachineTargetValueChangesAggregator, siteModel, grid, fence); CreateSwathContext(0, 0, 0, 10, 0, 0, 0, 2, 0, 10, 2, 0, out SimpleTriangle HeightInterpolator1, out SimpleTriangle HeightInterpolator2, out SimpleTriangle TimeInterpolator1, out SimpleTriangle TimeInterpolator2); // Compute swath with full cell pass on the front (blade) measurement location bool swathResult = swather.PerformSwathing(HeightInterpolator1, HeightInterpolator2, TimeInterpolator1, TimeInterpolator2, false, PassType.Front, MachineSide.None); // Did the swathing operation succeed? Assert.True(swathResult, "Perform swathing failed"); // Did it produce the expected set of swathed cells? Assert.Equal(1, grid.Root.CountChildren()); // Computation of the latest pass information which aids locating cells with non-null values try { IStorageProxy storageProxy = StorageProxy.Instance(StorageMutability.Mutable); grid.Root.ScanSubGrids(grid.FullCellExtent(), x => { ((IServerLeafSubGrid)x).ComputeLatestPassInformation(true, storageProxy); return(true); }); } catch (Exception E) { Assert.False(true, $"Exception {E} occured computing latest cell information"); } grid.CalculateIndexOfCellContainingPosition(grid.CellSize / 2, grid.CellSize / 2, out int _, out int _); int nonNullCellCount = 0; try { grid.Root.ScanSubGrids(grid.FullCellExtent(), x => { nonNullCellCount += ((IServerLeafSubGrid)x).CountNonNullCells(); return(true); }); } catch (Exception e) { Assert.False(true, $"Exception {e} occured counting non-null cells"); } Assert.Equal(174, nonNullCellCount); // Todo: Iterate over the cells and confirm their content is as expected }