private List <RxCellLookup> ImportRatesFromTreatmentZones(GridDescriptor gridDescriptor, IEnumerable <ISOTreatmentZone> treatmentZones, List <int> productIds, RasterGridPrescription prescription) { var rates = new List <RxCellLookup>(); foreach (var treatmentZoneCode in gridDescriptor.TreatmentZoneCodes) { ISOTreatmentZone treatmentZone = treatmentZones.FirstOrDefault(t => t.TreatmentZoneCode == treatmentZoneCode); if (treatmentZone == null) { return(null); } var lookup = new RxCellLookup { RxRates = new List <RxRate>() }; foreach (ISOProcessDataVariable pdv in treatmentZone.ProcessDataVariables) { if (!string.IsNullOrEmpty(pdv.ProductIdRef)) { int?productID = TaskDataMapper.InstanceIDMap.GetADAPTID(pdv.ProductIdRef); if (productID.HasValue) { lookup.RxRates.Add(PrescriptionMapper.ImportAndConvertRate(productID.Value, pdv, prescription)); } } } rates.Add(lookup); } return(rates); }
private List <RxCellLookup> ImportRatesFromProducts(GridDescriptor gridDescriptor, List <int> productIds, RasterGridPrescription prescription) { var rates = new List <RxCellLookup>(); bool binaryDataMatchesDefinition = true; foreach (var productRates in gridDescriptor.ProductRates) { var lookup = new RxCellLookup { RxRates = new List <RxRate>() }; for (int productIndex = 0; productIndex < productRates.Count; productIndex++) { int adaptProductId = 0; if (productIds.Count > productIndex) { adaptProductId = productIds[productIndex]; } else if (productIds.Count > 0) { binaryDataMatchesDefinition = false; } lookup.RxRates.Add(PrescriptionMapper.ImportRate(adaptProductId, productRates[productIndex], prescription)); } rates.Add(lookup); } if (!binaryDataMatchesDefinition) { TaskDataMapper.AddError($"Binary Grid Data for Type-2 Grid {TaskDataMapper.InstanceIDMap.GetISOID(prescription.Id.ReferenceId)} does not match its definition. Product data will be omitted."); } return(rates); }
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); }
private List <RxCellLookup> ImportRatesFromProducts(GridDescriptor gridDescriptor, List <int> productIds, RasterGridPrescription prescription) { var rates = new List <RxCellLookup>(); foreach (var productRates in gridDescriptor.ProductRates) { var lookup = new RxCellLookup { RxRates = new List <RxRate>() }; for (int productIndex = 0; productIndex < productRates.Count; productIndex++) { int adaptProductId = productIds[productIndex]; lookup.RxRates.Add(PrescriptionMapper.ImportRate(adaptProductId, productRates[productIndex], prescription)); } rates.Add(lookup); } return(rates); }
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); }
public GridMapper(TaskDataMapper taskDataMapper, PrescriptionMapper prescriptionMapper) : base(taskDataMapper, "GRD") { _prescriptionMapper = prescriptionMapper; }
private WorkItem ImportWorkItem(ISOTask isoPrescribedTask) { WorkItem workItem = new WorkItem(); //Task ID ImportIDs(workItem.Id, isoPrescribedTask.TaskID); //Grower ID workItem.GrowerId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPrescribedTask.CustomerIdRef); //Farm ID workItem.FarmId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPrescribedTask.FarmIdRef); //Field/CropZone int?pfdID = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPrescribedTask.PartFieldIdRef); if (pfdID.HasValue) { if (DataModel.Catalog.CropZones.Any(c => c.Id.ReferenceId == pfdID.Value)) { workItem.CropZoneId = pfdID.Value; } else { workItem.FieldId = pfdID.Value; if (DataModel.Catalog.CropZones.Count(c => c.FieldId == pfdID) == 1) { //There is a single cropZone for the field. workItem.CropZoneId = DataModel.Catalog.CropZones.Single(c => c.FieldId == pfdID).Id.ReferenceId; } } } //Status workItem.StatusUpdates = new List <StatusUpdate>() { new StatusUpdate() { Status = ImportStatus(isoPrescribedTask.TaskStatus) } }; //Responsible Worker if (!string.IsNullOrEmpty(isoPrescribedTask.ResponsibleWorkerIdRef)) { ISOWorker worker = ISOTaskData.ChildElements.OfType <ISOWorker>().FirstOrDefault(w => w.WorkerId == isoPrescribedTask.ResponsibleWorkerIdRef); int? personID = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPrescribedTask.ResponsibleWorkerIdRef); if (personID.HasValue) { //Create a Role PersonRole role = new PersonRole() { PersonId = personID.Value }; //Add to Catalog DataModel.Catalog.PersonRoles.Add(role); if (workItem.PeopleRoleIds == null) { workItem.PeopleRoleIds = new List <int>(); } //Add to Task workItem.PeopleRoleIds.Add(role.Id.ReferenceId); } } //Worker Allocation if (isoPrescribedTask.WorkerAllocations.Any()) { WorkerAllocationMapper wanMapper = new WorkerAllocationMapper(TaskDataMapper); List <PersonRole> personRoles = wanMapper.ImportWorkerAllocations(isoPrescribedTask.WorkerAllocations).ToList(); //Add to Catalog DataModel.Catalog.PersonRoles.AddRange(personRoles); //Add to Task if (workItem.PeopleRoleIds == null) { workItem.PeopleRoleIds = new List <int>(); } workItem.PeopleRoleIds.AddRange(personRoles.Select(p => p.Id.ReferenceId)); } if (isoPrescribedTask.GuidanceAllocations.Any()) { GuidanceAllocationMapper ganMapper = new GuidanceAllocationMapper(TaskDataMapper); List <GuidanceAllocation> allocations = ganMapper.ImportGuidanceAllocations(isoPrescribedTask.GuidanceAllocations).ToList(); //Add to Catalog List <GuidanceAllocation> guidanceAllocations = DataModel.Documents.GuidanceAllocations as List <GuidanceAllocation>; if (guidanceAllocations != null) { guidanceAllocations.AddRange(allocations); } //Add to Task if (workItem.GuidanceAllocationIds == null) { workItem.GuidanceAllocationIds = new List <int>(); } workItem.GuidanceAllocationIds.AddRange(allocations.Select(p => p.Id.ReferenceId)); } //Comments if (isoPrescribedTask.CommentAllocations.Any()) { CommentAllocationMapper canMapper = new CommentAllocationMapper(TaskDataMapper); workItem.Notes = canMapper.ImportCommentAllocations(isoPrescribedTask.CommentAllocations).ToList(); } //Prescription if (isoPrescribedTask.HasPrescription) { Prescription rx = PrescriptionMapper.ImportPrescription(isoPrescribedTask, workItem); if (rx == null) { return(workItem); } //Add to the Prescription the Catalog List <Prescription> prescriptions = DataModel.Catalog.Prescriptions as List <Prescription>; prescriptions?.Add(rx); //Add A WorkItemOperation WorkItemOperation operation = new WorkItemOperation(); operation.PrescriptionId = rx.Id.ReferenceId; //Add the operation to the Documents and reference on the WorkItem List <WorkItemOperation> operations = DataModel.Documents.WorkItemOperations as List <WorkItemOperation>; operations?.Add(operation); workItem.WorkItemOperationIds.Add(operation.Id.ReferenceId); //Track any prescription IDs to map to any completed TimeLog data _rxIDsByTask.Add(isoPrescribedTask.TaskID, rx.Id.ReferenceId); } return(workItem); }