private List <TimeLogWrapperGroup> GroupByDataLogValueCount(ISOTask loggedTask, string dataPath)
        {
            // All consequent time logs with 255 DLVs are kept together as a group.
            var timeLogGroups = new List <TimeLogWrapperGroup>();
            var logGroup      = new TimeLogWrapperGroup();

            foreach (var timeLog in loggedTask.TimeLogs)
            {
                ISOTime templateTime = timeLog.GetTimeElement(dataPath);
                if (templateTime != null)
                {
                    logGroup.Add(new TimeLogWrapper {
                        DataLogValues = templateTime.DataLogValues, ISOTimeLog = timeLog
                    });
                    // A time log with less than 255 DLVs found. Add it to current group
                    // and start a new one.
                    if (templateTime.DataLogValues.Count < 255)
                    {
                        timeLogGroups.Add(logGroup);
                        logGroup = new TimeLogWrapperGroup();
                    }
                }
            }
            // Add remaning log group
            if (logGroup.Count > 0)
            {
                timeLogGroups.Add(logGroup);
            }
            return(timeLogGroups);
        }
        public ManualPrescription ImportManualPrescription(ISOTask task, WorkItem workItem)
        {
            ManualPrescription manualRx = null;

            if (task.DefaultTreatmentZone != null)
            {
                foreach (ISOProcessDataVariable pdv in task.DefaultTreatmentZone.ProcessDataVariables)
                {
                    if (manualRx == null)
                    {
                        manualRx             = new ManualPrescription();
                        manualRx.ProductUses = new List <ProductUse>();
                        manualRx.ProductIds  = new List <int>();
                        ImportSharedPrescriptionProperties(task, workItem, manualRx);
                    }

                    if (pdv.ProductIdRef != null) //Products on ISO Rxs are optional, but without a place to store a product-agnostic prescription, those will not be imported here.
                    {
                        ProductUse productUse = new ProductUse();
                        int?       productID  = TaskDataMapper.InstanceIDMap.GetADAPTID(pdv.ProductIdRef);
                        if (productID.HasValue)
                        {
                            productUse.ProductId = productID.Value;
                            manualRx.ProductIds.Add(productID.Value);
                        }
                        productUse.Rate = pdv.ProcessDataValue.AsNumericRepresentationValue(pdv.ProcessDataDDI, RepresentationMapper);
                        manualRx.ProductUses.Add(productUse);
                    }
                }
            }
            return(manualRx);
        }
示例#3
0
 private int?GetProductIDForOperationData(ISOTask loggedTask, ISODevice dvc)
 {
     if (loggedTask.ProductAllocations.Count == 1 || loggedTask.ProductAllocations.Select(p => p.ProductIdRef).Distinct().Count() == 1)
     {
         //There is only one product in the data
         return(TaskDataMapper.InstanceIDMap.GetADAPTID(loggedTask.ProductAllocations.First().ProductIdRef));
     }
     else
     {
         HashSet <string> productRefsForThisDevice = new HashSet <string>();
         foreach (ISODeviceElement det in dvc.DeviceElements)
         {
             foreach (ISOProductAllocation detMappedPan in loggedTask.ProductAllocations.Where(p => !string.IsNullOrEmpty(p.DeviceElementIdRef)))
             {
                 productRefsForThisDevice.Add(detMappedPan.ProductIdRef);
             }
         }
         if (productRefsForThisDevice.Count == 1)
         {
             //There is only one product represented on this device
             return(TaskDataMapper.InstanceIDMap.GetADAPTID(productRefsForThisDevice.Single()));
         }
         else
         {
             //Unable to reconcile a single product
             return(null);
         }
     }
 }
示例#4
0
        private GridDescriptor LoadGridDescriptor(ISOTask task, string dataPath)
        {
            if (task.Grid == null)
            {
                return(null);
            }

            GridDescriptor descriptor = new GridDescriptor();

            if (!descriptor.LoadGridDefinition(task.Grid))
            {
                return(null);
            }

            ISOTreatmentZone treatmentZone = null;

            if (task.Grid.GridType == 2)
            {
                treatmentZone = task.TreatmentZones.SingleOrDefault(tz => tz.TreatmentZoneCode == task.Grid.TreatmentZoneCode);
                if (treatmentZone == null)
                {
                    return(null);
                }
            }
            if (!descriptor.LoadRates(dataPath, task.Grid, treatmentZone))
            {
                return(null);
            }

            return(descriptor);
        }
示例#5
0
        private void ImportRates(ISOTask task, GridDescriptor gridDescriptor, RasterGridPrescription prescription)
        {
            if (task.PositionLostTreatmentZone != null)
            {
                prescription.LossOfGpsRate = ImportTreatmentZoneAsNumericRepValue(task.PositionLostTreatmentZone);
            }
            if (task.OutOfFieldTreatmentZone != null)
            {
                prescription.OutOfFieldRate = ImportTreatmentZoneAsNumericRepValue(task.OutOfFieldTreatmentZone);
            }

            if (gridDescriptor.TreatmentZoneCodes != null)
            {
                //Grid Type 1
                ISOTreatmentZone treatmentZone = task.TreatmentZones.FirstOrDefault();
                if (treatmentZone == null)
                {
                    return;
                }

                prescription.Rates = ImportRatesFromTreatmentZones(gridDescriptor, task.TreatmentZones, prescription.ProductIds, prescription);
            }
            else if (gridDescriptor.ProductRates != null)
            {
                //Grid Type 2
                var treatmentZoneTemplate = task.DefaultTreatmentZone;
                if (treatmentZoneTemplate == null)
                {
                    return;
                }

                prescription.Rates = ImportRatesFromProducts(gridDescriptor, prescription.ProductIds, prescription);
            }
        }
示例#6
0
        public RasterGridPrescription Import(ISOTask task, WorkItem workItem)
        {
            RasterGridPrescription rasterPrescription = new RasterGridPrescription();

            _prescriptionMapper.ImportSharedPrescriptionProperties(task, workItem, rasterPrescription);

            GridDescriptor gridDescriptor = LoadGridDescriptor(task, TaskDataPath);

            if (gridDescriptor != null)
            {
                rasterPrescription.BoundingBox      = new BoundingBox();
                rasterPrescription.BoundingBox.MinY = new NumericRepresentationValue(RepresentationInstanceList.vrLatitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), gridDescriptor.Origin.Y));
                rasterPrescription.BoundingBox.MinX = new NumericRepresentationValue(RepresentationInstanceList.vrLongitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), gridDescriptor.Origin.X));
                var maxYValue = rasterPrescription.BoundingBox.MinY.Value.Value + gridDescriptor.CellHeight.Value.Value * gridDescriptor.RowCount;
                var maxXValue = rasterPrescription.BoundingBox.MinX.Value.Value + gridDescriptor.CellWidth.Value.Value * gridDescriptor.ColumnCount;
                rasterPrescription.BoundingBox.MaxY = new NumericRepresentationValue(RepresentationInstanceList.vrLatitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), maxYValue));
                rasterPrescription.BoundingBox.MaxX = new NumericRepresentationValue(RepresentationInstanceList.vrLongitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), maxXValue));
                rasterPrescription.Origin           = gridDescriptor.Origin;
                rasterPrescription.CellHeight       = gridDescriptor.CellHeight;
                rasterPrescription.CellWidth        = gridDescriptor.CellWidth;
                rasterPrescription.ColumnCount      = gridDescriptor.ColumnCount;
                rasterPrescription.RowCount         = gridDescriptor.RowCount;

                ImportRates(task, gridDescriptor, rasterPrescription);
            }
            return(rasterPrescription);
        }
        public VectorPrescription ImportVectorPrescription(ISOTask task, WorkItem workItem)
        {
            VectorPrescription vectorRx = new VectorPrescription();

            ImportSharedPrescriptionProperties(task, workItem, vectorRx);
            vectorRx.RxShapeLookups = new List <RxShapeLookup>();
            foreach (ISOTreatmentZone treatmentZone in task.TreatmentZones)
            {
                RxShapeLookup shapeLookup = new RxShapeLookup();

                //Rates
                shapeLookup.Rates = new List <RxRate>();
                foreach (ISOProcessDataVariable pdv in treatmentZone.ProcessDataVariables)
                {
                    int?productID = TaskDataMapper.InstanceIDMap.GetADAPTID(pdv.ProductIdRef);
                    if (productID.HasValue)
                    {
                        shapeLookup.Rates.Add(PrescriptionMapper.ImportAndConvertRate(productID.Value, pdv, vectorRx));
                    }
                }

                //Shapes
                PolygonMapper polygonMapper = new PolygonMapper(TaskDataMapper);
                shapeLookup.Shape          = new MultiPolygon();
                shapeLookup.Shape.Polygons = polygonMapper.ImportPolygons(treatmentZone.Polygons).ToList();

                //Add to the collection
                vectorRx.RxShapeLookups.Add(shapeLookup);
            }

            return(vectorRx);
        }
示例#8
0
        public ISOConnection ExportConnection(int loggedDataOrWorkItemID, EquipmentConfiguration adaptConnection)
        {
            ISOConnection isoConnection = new ISOConnection();

            //First Connector
            Connector connector1 = DataModel.Catalog.Connectors.FirstOrDefault(c => c.Id.ReferenceId == adaptConnection.Connector1Id);

            if (connector1 != null)
            {
                DeviceElementConfiguration config = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(c => c.Id.ReferenceId == connector1.DeviceElementConfigurationId);
                if (config != null)
                {
                    string        isoDeviceElementID = TaskDataMapper.InstanceIDMap.GetISOID(config.DeviceElementId);
                    DeviceElement deviceElement      = DataModel.Catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == config.DeviceElementId);
                    if (deviceElement != null)
                    {
                        string isoDeviceID = TaskDataMapper.InstanceIDMap.GetISOID(deviceElement.DeviceModelId);
                        if (!string.IsNullOrEmpty(isoDeviceElementID) && !string.IsNullOrEmpty(isoDeviceElementID))
                        {
                            isoConnection.DeviceIdRef_0        = isoDeviceID;
                            isoConnection.DeviceElementIdRef_0 = TaskDataMapper.InstanceIDMap.GetISOID(connector1.Id.ReferenceId); //We want to refer to the Connector DeviceElement, not its parent referred by the config element
                        }
                    }
                }
            }

            //Second Connector
            Connector connector2 = DataModel.Catalog.Connectors.FirstOrDefault(c => c.Id.ReferenceId == adaptConnection.Connector2Id);

            if (connector2 != null)
            {
                DeviceElementConfiguration config = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(c => c.Id.ReferenceId == connector2.DeviceElementConfigurationId);
                if (config != null)
                {
                    string        isoDeviceElementID = TaskDataMapper.InstanceIDMap.GetISOID(config.DeviceElementId);
                    DeviceElement deviceElement      = DataModel.Catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == config.DeviceElementId);
                    if (deviceElement != null)
                    {
                        string isoDeviceID = TaskDataMapper.InstanceIDMap.GetISOID(deviceElement.DeviceModelId);
                        if (!string.IsNullOrEmpty(isoDeviceElementID) && !string.IsNullOrEmpty(isoDeviceElementID))
                        {
                            isoConnection.DeviceIdRef_1        = isoDeviceID;
                            isoConnection.DeviceElementIdRef_1 = TaskDataMapper.InstanceIDMap.GetISOID(connector2.Id.ReferenceId);
                        }
                    }
                }
            }

            //DataLogTriggers
            if (adaptConnection.DataLogTriggers.Any())
            {
                string  taskID = TaskDataMapper.InstanceIDMap.GetISOID(loggedDataOrWorkItemID);
                ISOTask task   = TaskDataMapper.ISOTaskData.ChildElements.OfType <ISOTask>().First(t => t.TaskID == taskID);
                DataLogTriggerMapper dltMapper = new DataLogTriggerMapper(TaskDataMapper);
                task.DataLogTriggers = dltMapper.ExportDataLogTriggers(adaptConnection.DataLogTriggers).ToList();
            }

            return(isoConnection);
        }
示例#9
0
        private IEnumerable <OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLog isoTimeLog, int?prescriptionID)
        {
            WorkingDataMapper           workingDataMapper = new WorkingDataMapper(new EnumeratedMeterFactory(), TaskDataMapper);
            SectionMapper               sectionMapper     = new SectionMapper(workingDataMapper, TaskDataMapper);
            SpatialRecordMapper         spatialMapper     = new SpatialRecordMapper(new RepresentationValueInterpolator(), sectionMapper, workingDataMapper);
            IEnumerable <ISOSpatialRow> isoRecords        = ReadTimeLog(isoTimeLog, this.TaskDataPath);

            if (isoRecords != null)
            {
                isoRecords = isoRecords.ToList(); //Avoids multiple reads
                ISOTime time = isoTimeLog.GetTimeElement(this.TaskDataPath);

                //Identify unique devices represented in this TimeLog data
                IEnumerable <string> deviceElementIDs = time.DataLogValues.Where(d => d.ProcessDataDDI != "DFFF" && d.ProcessDataDDI != "DFFE").Select(d => d.DeviceElementIdRef);
                Dictionary <ISODevice, HashSet <string> > loggedDeviceElementsByDevice = new Dictionary <ISODevice, HashSet <string> >();
                foreach (string deviceElementID in deviceElementIDs)
                {
                    ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(deviceElementID);
                    if (isoDeviceElement != null)
                    {
                        ISODevice device = isoDeviceElement.Device;
                        if (!loggedDeviceElementsByDevice.ContainsKey(device))
                        {
                            loggedDeviceElementsByDevice.Add(device, new HashSet <string>());
                        }
                        loggedDeviceElementsByDevice[device].Add(deviceElementID);
                    }
                }

                //Split all devices in the same TimeLog into separate OperationData objects to handle multi-implement scenarios
                //This will ensure implement geometries/DeviceElementUse Depths & Orders do not get confused between implements
                List <OperationData> operationDatas = new List <OperationData>();
                foreach (ISODevice dvc in loggedDeviceElementsByDevice.Keys)
                {
                    OperationData operationData = new OperationData();

                    //This line will necessarily invoke a spatial read in order to find
                    //1)The correct number of CondensedWorkState working datas to create
                    //2)Any Widths and Offsets stored in the spatial data
                    IEnumerable <DeviceElementUse> sections = sectionMapper.Map(time, isoRecords, operationData.Id.ReferenceId, loggedDeviceElementsByDevice[dvc]);

                    var workingDatas = sections != null?sections.SelectMany(x => x.GetWorkingDatas()).ToList() : new List <WorkingData>();

                    var sectionsSimple = sectionMapper.ConvertToBaseTypes(sections.ToList());

                    operationData.GetSpatialRecords    = () => spatialMapper.Map(isoRecords, workingDatas);
                    operationData.MaxDepth             = sections.Count() > 0 ? sections.Select(s => s.Depth).Max() : 0;
                    operationData.GetDeviceElementUses = x => x == 0 ? sectionsSimple : new List <DeviceElementUse>();
                    operationData.PrescriptionId       = prescriptionID;
                    operationData.OperationType        = GetOperationTypeFromLoggingDevices(time);
                    operationData.ProductId            = GetProductIDForOperationData(loggedTask, dvc);
                    operationData.SpatialRecordCount   = isoRecords.Count();
                    operationDatas.Add(operationData);
                }

                return(operationDatas);
            }
            return(null);
        }
 public override IEnumerable <OperationData> ImportTimeLogs(ISOTask loggedTask, IEnumerable <ISOTimeLog> timeLogs, int?prescriptionID)
 {
     _timeLogs = timeLogs;
     // Combine ISOTime elements from each TimeLog into one.
     _combinedTime = CreateCombinedTime();
     // Read data from all timelogs as if it was a single file.
     // Pass first available TimeLog to avoid breaking base class.
     return(ImportTimeLog(loggedTask, timeLogs.First(), prescriptionID));
 }
示例#11
0
        public EquipmentConfiguration ImportConnection(ISOTask task, ISOConnection isoConnection)
        {
            EquipmentConfiguration equipConfig        = new EquipmentConfiguration();
            StringBuilder          descriptionBuilder = new StringBuilder();

            //First Device Element
            int?      connectorID     = TaskDataMapper.InstanceIDMap.GetADAPTID(isoConnection.DeviceElementIdRef_0);
            Connector adaptConnector1 = null;

            if (connectorID.HasValue)
            {
                adaptConnector1 = DataModel.Catalog.Connectors.SingleOrDefault(d => d.Id.ReferenceId == connectorID.Value);
                if (adaptConnector1 != null)
                {
                    equipConfig.Connector1Id = adaptConnector1.Id.ReferenceId;

                    ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(isoConnection.DeviceElementIdRef_0);
                    descriptionBuilder.Append(isoDeviceElement.Device.DeviceDesignator);
                    descriptionBuilder.Append(":");
                    descriptionBuilder.Append(isoDeviceElement.DeviceElementDesignator);
                }
            }
            if (adaptConnector1 == null)
            {
                descriptionBuilder.Append("Unknown");
            }

            descriptionBuilder.Append("<->");

            //Second Device Element
            Connector adaptConnector2 = null;

            connectorID = TaskDataMapper.InstanceIDMap.GetADAPTID(isoConnection.DeviceElementIdRef_1);
            if (connectorID.HasValue)
            {
                adaptConnector2 = DataModel.Catalog.Connectors.SingleOrDefault(d => d.Id.ReferenceId == connectorID.Value);
                if (adaptConnector2 != null)
                {
                    equipConfig.Connector2Id = adaptConnector2.Id.ReferenceId;

                    ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(isoConnection.DeviceElementIdRef_1);
                    descriptionBuilder.Append(isoDeviceElement.Device.DeviceDesignator);
                    descriptionBuilder.Append(":");
                    descriptionBuilder.Append(isoDeviceElement.DeviceElementDesignator);
                }
            }
            if (adaptConnector2 == null)
            {
                descriptionBuilder.Append("Unknown");
            }

            equipConfig.Description = descriptionBuilder.ToString();

            return(equipConfig);
        }
示例#12
0
        public IEnumerable <ISOConnection> ExportConnections(ISOTask task, IEnumerable <EquipmentConfiguration> adaptConnections)
        {
            List <ISOConnection> connections = new List <ISOConnection>();

            foreach (EquipmentConfiguration adaptConnection in adaptConnections)
            {
                ISOConnection isoConnection = ExportConnection(task, adaptConnection);
                connections.Add(isoConnection);
            }
            return(connections);
        }
示例#13
0
        public IEnumerable <EquipmentConfiguration> ImportConnections(ISOTask isoTask)
        {
            List <EquipmentConfiguration> equipConfigs = new List <EquipmentConfiguration>();

            foreach (ISOConnection connection in isoTask.Connections)
            {
                EquipmentConfiguration equipConfig = ImportConnection(isoTask, connection);
                equipConfigs.Add(equipConfig);
            }
            return(equipConfigs);
        }
示例#14
0
        public IEnumerable <ISOTask> Export(IEnumerable <LoggedData> adaptLoggedDatas)
        {
            List <ISOTask> tasks = new List <ISOTask>();

            foreach (LoggedData loggedData in adaptLoggedDatas)
            {
                ISOTask task = Export(loggedData);
                tasks.Add(task);
            }
            return(tasks);
        }
示例#15
0
        private List <TimeLogGroup> GetTimeLogGroups(ISOTask loggedTask)
        {
            var dataPath = _timeLogMapper.TaskDataPath;

            var timeLogGroups = GroupByDataLogValueCount(loggedTask, dataPath);

            timeLogGroups = HandleRollOverScenario(timeLogGroups);
            timeLogGroups = HandleDuplicateDataLogValues(timeLogGroups);

            return(timeLogGroups.Select(x => new TimeLogGroup(x.Select(y => y.ISOTimeLog).ToList())).ToList());
        }
示例#16
0
        public EquipmentConfiguration ImportConnection(ISOTask task, ISOConnection isoConnection)
        {
            EquipmentConfiguration equipConfig        = new EquipmentConfiguration();
            StringBuilder          descriptionBuilder = new StringBuilder();

            //First Device Element
            int?connectorID = TaskDataMapper.InstanceIDMap.GetADAPTID(isoConnection.DeviceElementIdRef_0);

            if (connectorID.HasValue)
            {
                Connector adaptConnector1 = DataModel.Catalog.Connectors.Single(d => d.Id.ReferenceId == connectorID.Value);
                equipConfig.Connector1Id = adaptConnector1.Id.ReferenceId;

                ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(isoConnection.DeviceElementIdRef_0);
                descriptionBuilder.Append(isoDeviceElement.Device.DeviceDesignator);
                descriptionBuilder.Append(":");
                descriptionBuilder.Append(isoDeviceElement.DeviceElementDesignator);
            }
            else
            {
                descriptionBuilder.Append("Unknown");
            }

            descriptionBuilder.Append("<->");

            //Second Device Element
            connectorID = TaskDataMapper.InstanceIDMap.GetADAPTID(isoConnection.DeviceElementIdRef_1);
            if (connectorID.HasValue)
            {
                Connector adaptConnector2 = DataModel.Catalog.Connectors.Single(d => d.Id.ReferenceId == connectorID.Value);
                equipConfig.Connector2Id = adaptConnector2.Id.ReferenceId;

                ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(isoConnection.DeviceElementIdRef_1);
                descriptionBuilder.Append(isoDeviceElement.Device.DeviceDesignator);
                descriptionBuilder.Append(":");
                descriptionBuilder.Append(isoDeviceElement.DeviceElementDesignator);
            }
            else
            {
                descriptionBuilder.Append("Unknown");
            }

            equipConfig.Description = descriptionBuilder.ToString();

            //DataLogTriggers
            if (task.DataLogTriggers.Any())
            {
                DataLogTriggerMapper dltMapper = new DataLogTriggerMapper(TaskDataMapper);
                dltMapper.ImportDataLogTriggers(task.DataLogTriggers);
            }

            return(equipConfig);
        }
示例#17
0
        private Summary ImportSummary(ISOTask isoLoggedTask, LoggedData loggedData)
        {
            //Per ISO11783-10:2015(E) 6.8.3, the last Time element contains the comprehensive task totals.
            //Earlier Time elements contain the task totals leading up to points where the Task was paused.
            //As such, the Summary.TimeScopes will include detail on various intermittent Timescopes,
            //and the Summary.SummaryData will contain totals from only the last time element.
            //Summary.SummaryData.Stamp will be set to a comprehensive time stamp from the beginning of the first time to the end of the last.
            Summary summary = null;
            IEnumerable <ISOTime> timeElements = isoLoggedTask.Times.Where(t => t.HasStart && t.HasType);

            if (timeElements.Any())
            {
                summary = new Summary();

                //TimeScopes
                summary.TimeScopes = new List <TimeScope>();
                foreach (ISOTime time in isoLoggedTask.Times.Where(t => t.HasStart && t.HasType)) //Nothing added without a Start and Type attribute
                {
                    TimeScope timeScope = new TimeScope();
                    timeScope.TimeStamp1 = time.Start;
                    if (time.Stop != null)
                    {
                        timeScope.TimeStamp2 = time.Stop;
                    }

                    if (time.Stop == null && time.Duration != null)
                    {
                        //Calculate the Stop time if missing and duration present
                        timeScope.TimeStamp2 = timeScope.TimeStamp1.Value.AddSeconds(time.Duration.Value);
                    }
                    timeScope.DateContext = time.Type == ISOEnumerations.ISOTimeType.Planned ? DateContextEnum.ProposedStart : DateContextEnum.ActualStart;
                    timeScope.Duration    = timeScope.TimeStamp2.GetValueOrDefault() - timeScope.TimeStamp1.GetValueOrDefault();
                    summary.TimeScopes.Add(timeScope);
                }

                //Summary Data - does not have a product reference
                summary.SummaryData = ImportSummaryData(timeElements);

                //Operation Summaries - includes a product reference
                summary.OperationSummaries = ImportOperationSummaries(isoLoggedTask);

                //Copy properties from LoggedData
                summary.GrowerId                    = loggedData.GrowerId;
                summary.FarmId                      = loggedData.FarmId;
                summary.FieldId                     = loggedData.FieldId;
                summary.CropZoneId                  = loggedData.CropZoneId;
                summary.PersonRoleIds               = loggedData.PersonRoleIds;
                summary.WorkItemIds                 = loggedData.WorkItemIds;
                summary.GuidanceAllocationIds       = loggedData.GuidanceAllocationIds;
                summary.EquipmentConfigurationGroup = loggedData.EquipmentConfigurationGroup;
            }
            return(summary);
        }
示例#18
0
 private void ExportRasterPrescription(ISOTask task, RasterGridPrescription rx, int gridType)
 {
     if (gridType == 1)
     {
         List <byte> treatmentZoneCodes = ExportTreatmentZonesForType1(task, rx);
         task.Grid = _gridMapper.Export(rx, null, treatmentZoneCodes);
     }
     else
     {
         ISOTreatmentZone defaultTreatmentZone = ExportTreatmentZonesForType2(task, rx);
         task.Grid = _gridMapper.Export(rx, defaultTreatmentZone);
     }
 }
示例#19
0
        public IEnumerable <OperationData> ImportTimeLogs(ISOTask loggedTask, int?prescriptionID)
        {
            var timeLogGroups = GetTimeLogGroups(loggedTask);

            var operationDatas = new List <OperationData>();

            foreach (var timeLogGroup in timeLogGroups)
            {
                operationDatas.AddRange(timeLogGroup.Count > 1
                    ? _multiFileTimeLogMapper.ImportTimeLogs(loggedTask, timeLogGroup, prescriptionID)
                    : _timeLogMapper.ImportTimeLogs(loggedTask, timeLogGroup, prescriptionID));
            }

            return(_manufacturer?.PostProcessOperationData(_taskDataMapper, operationDatas) ?? operationDatas);
        }
        public IEnumerable <OperationData> ImportTimeLogs(ISOTask loggedTask, int?prescriptionID)
        {
            List <OperationData> operations = new List <OperationData>();

            foreach (ISOTimeLog isoTimeLog in loggedTask.TimeLogs)
            {
                IEnumerable <OperationData> operationData = ImportTimeLog(loggedTask, isoTimeLog, prescriptionID);
                if (operationData != null)
                {
                    operations.AddRange(operationData);
                }
            }

            return(operations);
        }
示例#21
0
        private List <OperationSummary> ImportOperationSummaries(ISOTask isoLoggedTask)
        {
            List <OperationSummary> operationSummaries = null;

            if (isoLoggedTask.ProductAllocations.Any())
            {
                IEnumerable <ISOTime> timeElements = isoLoggedTask.Times.Where(t => t.HasStart && t.HasType);
                operationSummaries = new List <OperationSummary>();
                if (isoLoggedTask.ProductAllocations.Count == 1)
                {
                    //There is a single product allocation on the task
                    string           isoProductRef = isoLoggedTask.ProductAllocations.Single().ProductIdRef;
                    OperationSummary summary       = GetOperationSummary(timeElements, isoProductRef);
                    if (summary != null)
                    {
                        operationSummaries.Add(summary);
                    }
                }
                else if (isoLoggedTask.ProductAllocations.Select(p => p.ProductIdRef).Distinct().Count() == 1)
                {
                    //There is a single product on multiple allocations
                    string           isoProductRef = isoLoggedTask.ProductAllocations.Select(p => p.ProductIdRef).First();
                    OperationSummary summary       = GetOperationSummary(timeElements, isoProductRef);
                    if (summary != null)
                    {
                        operationSummaries.Add(summary);
                    }
                }
                else
                {
                    //There are multiple products.  Use any DeviceElements on the PANs to reconcile summaries.
                    foreach (string isoProductRef in isoLoggedTask.ProductAllocations.Select(p => p.ProductIdRef).Distinct())
                    {
                        IEnumerable <string> deviceElementIDs = isoLoggedTask.ProductAllocations.Where(p => p.ProductIdRef == isoProductRef && p.DeviceElementIdRef != null)
                                                                .Select(p => p.DeviceElementIdRef);
                        OperationSummary summary = GetOperationSummary(timeElements, isoProductRef, deviceElementIDs);
                        if (summary != null)
                        {
                            operationSummaries.Add(summary);
                        }
                    }
                }
            }

            return(operationSummaries);
        }
示例#22
0
        private void ExportManualPresciption(ISOTask task, ManualPrescription rx)
        {
            ISOTreatmentZone tzn = new ISOTreatmentZone();

            tzn.TreatmentZoneDesignator   = "Default Treatment Zone";
            tzn.TreatmentZoneCode         = 1;
            task.DefaultTreatmentZoneCode = tzn.TreatmentZoneCode;

            foreach (ProductUse productUse in rx.ProductUses)
            {
                var    isoUnit             = DetermineIsoUnit(rx.RxProductLookups.First(p => p.ProductId == productUse.ProductId).UnitOfMeasure);
                string productIDRef        = TaskDataMapper.InstanceIDMap.GetISOID(productUse.ProductId);
                ISOProcessDataVariable pdv = ExportProcessDataVariable(productUse.Rate, productIDRef, isoUnit);
                tzn.ProcessDataVariables.Add(pdv);
            }

            task.TreatmentZones.Add(tzn);
        }
示例#23
0
        private void ExportVectorPrescription(ISOTask task, VectorPrescription rx)
        {
            byte i = 0;

            foreach (RxShapeLookup shapeLookup in rx.RxShapeLookups)
            {
                ISOTreatmentZone tzn = new ISOTreatmentZone();
                tzn.TreatmentZoneCode = i++;
                foreach (RxRate rxRate in shapeLookup.Rates)
                {
                    tzn.ProcessDataVariables.Add(ExportProcessDataVariable(rxRate, rx));
                }

                PolygonMapper polygonMapper = new PolygonMapper(TaskDataMapper);
                tzn.Polygons = polygonMapper.ExportPolygons(shapeLookup.Shape.Polygons, ISOEnumerations.ISOPolygonType.TreatmentZone).ToList();
                task.TreatmentZones.Add(tzn);
            }
        }
示例#24
0
        public Prescription ImportPrescription(ISOTask task, WorkItem workItem)
        {
            Prescription prescription = null;

            if (task.HasRasterPrescription)
            {
                prescription = _gridMapper.Import(task, workItem);
            }
            else if (task.HasVectorPrescription)
            {
                prescription = ImportVectorPrescription(task, workItem);
            }
            else if (task.HasManualPrescription)
            {
                prescription = ImportManualPrescription(task, workItem);
            }

            return(prescription);
        }
示例#25
0
        private List <byte> ExportTreatmentZonesForType1(ISOTask task, RasterGridPrescription prescription)
        {
            Dictionary <string, ISOTreatmentZone> treatmentZones = new Dictionary <string, ISOTreatmentZone>();
            List <byte> rateCodePerCell = new List <byte>();

            byte tznCounter = 1;

            foreach (RxCellLookup cellRates in prescription.Rates)
            {
                string key = GetRxRatesKey(cellRates);
                if (!treatmentZones.ContainsKey(key))
                {
                    ISOTreatmentZone tzn = GetNewType1TreatmentZone(cellRates, tznCounter, prescription);
                    treatmentZones.Add(key, tzn);
                    task.TreatmentZones.Add(tzn);
                    tznCounter++;
                }
                rateCodePerCell.Add(treatmentZones[key].TreatmentZoneCode);
            }
            return(rateCodePerCell);
        }
示例#26
0
        private IEnumerable <ISOTask> Export(WorkItem workItem, int isoGridType)
        {
            List <ISOTask> tasks = new List <ISOTask>();

            if (workItem.WorkItemOperationIds.Any())
            {
                foreach (int operationID in workItem.WorkItemOperationIds)
                {
                    WorkItemOperation operation = DataModel.Documents.WorkItemOperations.FirstOrDefault(o => o.Id.ReferenceId == operationID);
                    if (operation != null && operation.PrescriptionId.HasValue)
                    {
                        Prescription prescription = DataModel.Catalog.Prescriptions.FirstOrDefault(p => p.Id.ReferenceId == operation.PrescriptionId.Value);
                        if (prescription != null)
                        {
                            ISOTask task = PrescriptionMapper.ExportPrescription(workItem, isoGridType, prescription);
                            tasks.Add(task);
                            _taskIDsByPrescription.Add(prescription.Id.ReferenceId, task.TaskID);
                        }
                    }
                }
            }
            return(tasks);
        }
        private Dictionary <string, List <ISOProductAllocation> > GetProductAllocationsByDeviceElement(ISOTask loggedTask, ISODevice dvc)
        {
            Dictionary <string, List <ISOProductAllocation> > output = new Dictionary <string, List <ISOProductAllocation> >();

            foreach (ISOProductAllocation pan in loggedTask.ProductAllocations.Where(p => !string.IsNullOrEmpty(p.DeviceElementIdRef)))
            {
                if (dvc.DeviceElements.Select(d => d.DeviceElementId).Contains(pan.DeviceElementIdRef)) //Filter PANs by this DVC
                {
                    if (!output.ContainsKey(pan.DeviceElementIdRef))
                    {
                        output.Add(pan.DeviceElementIdRef, new List <ISOProductAllocation>());
                    }
                    output[pan.DeviceElementIdRef].Add(pan);
                }
            }
            return(output);
        }
示例#28
0
        internal void ImportSharedPrescriptionProperties(ISOTask task, WorkItem workItem, Prescription prescription)
        {
            //Description
            prescription.Description = task.TaskDesignator;

            //CropZone/Field
            if (workItem.CropZoneId.HasValue)
            {
                prescription.CropZoneId = workItem.CropZoneId.Value;
            }
            else if (workItem.FieldId.HasValue)
            {
                prescription.FieldId = workItem.FieldId.Value;
            }

            //Products
            prescription.ProductIds = new List <int>();
            foreach (ISOTreatmentZone treatmentZone in task.TreatmentZones)
            {
                foreach (var dataVariable in treatmentZone.ProcessDataVariables)
                {
                    if (!string.IsNullOrEmpty(dataVariable.ProductIdRef))
                    {
                        int?productID = TaskDataMapper.InstanceIDMap.GetADAPTID(dataVariable.ProductIdRef);
                        if (productID.HasValue)
                        {
                            //ProductIDs
                            if (!prescription.ProductIds.Contains(productID.Value))
                            {
                                prescription.ProductIds.Add(productID.Value);
                            }

                            //Product Lookups
                            int ddi             = dataVariable.ProcessDataDDI.AsInt32DDI();
                            var rxProductLookup = new RxProductLookup
                            {
                                ProductId      = productID,
                                UnitOfMeasure  = UnitFactory.Instance.GetUnitByDDI(ddi).ToAdaptUnit(),
                                Representation = (NumericRepresentation)RepresentationMapper.Map(ddi)
                            };

                            if (!prescription.RxProductLookups.Any(r => r.ProductId == rxProductLookup.ProductId))
                            {
                                prescription.RxProductLookups.Add(rxProductLookup);
                            }
                        }
                    }
                }
            }

            //Connections
            if (task.Connections.Any())
            {
                IEnumerable <EquipmentConfiguration> equipConfigs = _connectionMapper.ImportConnections(task);

                workItem.EquipmentConfigurationGroup = new EquipmentConfigurationGroup();
                workItem.EquipmentConfigurationGroup.EquipmentConfigurations = equipConfigs.ToList();

                DataModel.Catalog.EquipmentConfigurations.AddRange(equipConfigs);
            }
        }
示例#29
0
        public ISOTask ExportPrescription(WorkItem workItem, int gridType, Prescription prescription)
        {
            ISOTask task = new ISOTask();

            //Task ID
            string taskID = workItem.Id.FindIsoId() ?? GenerateId();

            task.TaskID = taskID;
            ExportIDs(workItem.Id, taskID);

            //Designator
            task.TaskDesignator = prescription.Description;

            //Customer Ref
            if (workItem.GrowerId.HasValue)
            {
                task.CustomerIdRef = TaskDataMapper.InstanceIDMap.GetISOID(workItem.GrowerId.Value);
            }

            //Farm Ref
            if (workItem.FarmId.HasValue)
            {
                task.FarmIdRef = TaskDataMapper.InstanceIDMap.GetISOID(workItem.FarmId.Value);
            }

            //Partfield Ref
            if (workItem.CropZoneId.HasValue)
            {
                task.PartFieldIdRef = TaskDataMapper.InstanceIDMap.GetISOID(workItem.CropZoneId.Value);
            }
            else if (workItem.FieldId.HasValue)
            {
                task.PartFieldIdRef = TaskDataMapper.InstanceIDMap.GetISOID(workItem.FieldId.Value);
            }

            //Comments
            if (workItem.Notes.Any())
            {
                CommentAllocationMapper canMapper = new CommentAllocationMapper(TaskDataMapper);
                task.CommentAllocations = canMapper.ExportCommentAllocations(workItem.Notes).ToList();
            }

            //Worker Allocations
            if (workItem.PeopleRoleIds.Any())
            {
                WorkerAllocationMapper workerAllocationMapper = new WorkerAllocationMapper(TaskDataMapper);
                List <PersonRole>      personRoles            = new List <PersonRole>();
                foreach (int id in workItem.PeopleRoleIds)
                {
                    PersonRole personRole = DataModel.Catalog.PersonRoles.FirstOrDefault(p => p.Id.ReferenceId == id);
                    if (personRole != null)
                    {
                        personRoles.Add(personRole);
                    }
                }
                task.WorkerAllocations = workerAllocationMapper.ExportWorkerAllocations(personRoles).ToList();
            }

            //Guidance Allocations
            if (workItem.GuidanceAllocationIds.Any())
            {
                GuidanceAllocationMapper  guidanceAllocationMapper = new GuidanceAllocationMapper(TaskDataMapper);
                List <GuidanceAllocation> allocations = new List <GuidanceAllocation>();
                foreach (int id in workItem.GuidanceAllocationIds)
                {
                    GuidanceAllocation allocation = DataModel.Documents.GuidanceAllocations.FirstOrDefault(p => p.Id.ReferenceId == id);
                    if (allocation != null)
                    {
                        allocations.Add(allocation);
                    }
                }
                task.GuidanceAllocations = guidanceAllocationMapper.ExportGuidanceAllocations(allocations).ToList();
            }

            //Connections
            if (workItem.EquipmentConfigurationGroup != null)
            {
                task.Connections = _connectionMapper.ExportConnections(workItem.Id.ReferenceId, workItem.EquipmentConfigurationGroup.EquipmentConfigurations).ToList();
            }

            //Status
            if (workItem.StatusUpdates == null || workItem.StatusUpdates.Count == 0)
            {
                task.TaskStatus = ISOEnumerations.ISOTaskStatus.Planned;
            }
            else if (workItem.StatusUpdates.Count == 1)
            {
                StatusUpdate lastStatus = workItem.StatusUpdates.OrderByDescending(su => su.TimeStamp).Last();
                task.TaskStatus = ExportStatus(lastStatus.Status);
            }

            //Prescription
            if (prescription is RasterGridPrescription)
            {
                ExportRasterPrescription(task, prescription as RasterGridPrescription, gridType);
            }
            else if (prescription is VectorPrescription)
            {
                ExportVectorPrescription(task, prescription as VectorPrescription);
            }
            else if (prescription is ManualPrescription)
            {
                ExportManualPresciption(task, prescription as ManualPrescription);
            }

            return(task);
        }
示例#30
0
        private ISOTreatmentZone ExportTreatmentZonesForType2(ISOTask task, RasterGridPrescription prescription)
        {
            if (prescription.ProductIds == null)
            {
                TaskDataMapper.AddError($"No Products are present for Grid Type 2 Prescription export: {prescription.Description}", prescription.Id.ReferenceId.ToString());
                return(null);
            }

            var lossOfSignalTreatmentZone = new ISOTreatmentZone {
                TreatmentZoneDesignator = "Loss of GPS", ProcessDataVariables = new List <ISOProcessDataVariable>()
            };
            var outOfFieldTreatmentZone = new ISOTreatmentZone {
                TreatmentZoneDesignator = "Out of Field", ProcessDataVariables = new List <ISOProcessDataVariable>()
            };
            var defaultTreatmentZone = new ISOTreatmentZone {
                TreatmentZoneDesignator = "Default", ProcessDataVariables = new List <ISOProcessDataVariable>()
            };

            foreach (var productId in prescription.ProductIds)
            {
                var isoUnit = DetermineIsoUnit(prescription.RxProductLookups.First(p => p.ProductId == productId).UnitOfMeasure);

                string isoProductId            = TaskDataMapper.InstanceIDMap.GetISOID(productId) ?? string.Empty;
                ISOProcessDataVariable lossPDV = ExportProcessDataVariable(prescription.LossOfGpsRate, isoProductId, isoUnit);
                if (lossPDV != null)
                {
                    lossOfSignalTreatmentZone.ProcessDataVariables.Add(lossPDV);
                }
                ISOProcessDataVariable oofPDV = ExportProcessDataVariable(prescription.OutOfFieldRate, isoProductId, isoUnit);
                if (oofPDV != null)
                {
                    outOfFieldTreatmentZone.ProcessDataVariables.Add(oofPDV);
                }
                ISOProcessDataVariable defaultPDV = ExportProcessDataVariable(prescription.LossOfGpsRate, isoProductId, isoUnit);  //ADAPT doesn't have a separate Default Rate.  Using Loss of GPS Rate as a logical equivalent for a default rate.
                if (defaultPDV == null)
                {
                    //Add 0 as the default rate so that we have at least one PDV to reference
                    var defaultRate = new NumericRepresentationValue(null, new NumericValue(prescription.RxProductLookups.First().UnitOfMeasure, 0));
                    defaultPDV = ExportProcessDataVariable(defaultRate, isoProductId, isoUnit);
                }
                defaultTreatmentZone.ProcessDataVariables.Add(defaultPDV);
            }

            if (lossOfSignalTreatmentZone.ProcessDataVariables.Count > 0)
            {
                lossOfSignalTreatmentZone.TreatmentZoneCode = 253;
                task.TreatmentZones.Add(lossOfSignalTreatmentZone);
                task.PositionLostTreatmentZoneCode = lossOfSignalTreatmentZone.TreatmentZoneCode;
            }

            if (outOfFieldTreatmentZone.ProcessDataVariables.Count > 0)
            {
                outOfFieldTreatmentZone.TreatmentZoneCode = 254;
                task.TreatmentZones.Add(outOfFieldTreatmentZone);
                task.OutOfFieldTreatmentZoneCode = outOfFieldTreatmentZone.TreatmentZoneCode;
            }

            defaultTreatmentZone.TreatmentZoneCode = 1;
            task.TreatmentZones.Add(defaultTreatmentZone);
            task.DefaultTreatmentZoneCode = defaultTreatmentZone.TreatmentZoneCode;

            return(defaultTreatmentZone);
        }