Compare commits
	
		
			9 Commits
		
	
	
		
			5f1073b80c
			...
			a331437433
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a331437433 | |||
| 276cce1808 | |||
| 17765f17b0 | |||
| 690807a632 | |||
| f16ad90f68 | |||
| e6244ff74b | |||
| 357bcaea60 | |||
| 7565c576c1 | |||
| 262bd641a8 | 
| @@ -5,7 +5,8 @@ namespace FarmmapsNbs.Models | ||||
| { | ||||
|     public class NitrogenInput | ||||
|     { | ||||
|         public string IsariaZipFile { get; set; } | ||||
|         public string ZippedShapeFile { get; set; } | ||||
|         public string InputVariable { get; set; } | ||||
|         public string OutputFileName { get; set; } | ||||
|         public DateTime PlantingDate { get; set; } | ||||
|         public DateTime MeasurementDate { get; set; } | ||||
|   | ||||
| @@ -77,20 +77,20 @@ namespace FarmmapsNbs | ||||
|             var cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code, | ||||
|                 $"VRA NBS cropfield {input.OutputFileName}", plantingDate.Year, input.GeometryJson.ToString(Formatting.None)); | ||||
|  | ||||
|             var dataPath = Path.Combine("Data", input.IsariaZipFile); | ||||
|             var isariaShapeItem = | ||||
|                 await _generalService.UploadZipWithShapeAsync(uploadedRoot, dataPath, Path.GetFileNameWithoutExtension(input.IsariaZipFile)); | ||||
|             if (isariaShapeItem == null) | ||||
|             var dataPath = Path.Combine("Data", input.ZippedShapeFile); | ||||
|             var shapeItem = | ||||
|                 await _generalService.UploadZipWithShapeAsync(uploadedRoot, dataPath, Path.GetFileNameWithoutExtension(input.ZippedShapeFile)); | ||||
|             if (shapeItem == null) | ||||
|             { | ||||
|                 _logger.LogError("Could not find isaria shape item"); | ||||
|                 _logger.LogError("Could not find shape item"); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             _logger.LogInformation($"Converting shape to geotiff"); | ||||
|             var isariaGeotiffItem = await _generalService.ShapeToGeotiff(isariaShapeItem); | ||||
|             if (isariaGeotiffItem == null) | ||||
|             var geotiffItem = await _generalService.ShapeToGeotiff(shapeItem); | ||||
|             if (geotiffItem == null) | ||||
|             { | ||||
|                 _logger.LogError("Something went wrong with isaria shape to geotiff transformation"); | ||||
|                 _logger.LogError("Something went wrong with shape to geotiff transformation"); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
| @@ -112,21 +112,21 @@ namespace FarmmapsNbs | ||||
|  | ||||
|             _logger.LogInformation("Calculating uptake map"); | ||||
|             var uptakeMapItem = | ||||
|                 await _nitrogenService.CalculateUptakeMap(cropfieldItem, isariaGeotiffItem, plantingDate, | ||||
|                     measurementDate); | ||||
|                 await _nitrogenService.CalculateUptakeMap(cropfieldItem, geotiffItem, plantingDate, | ||||
|                     measurementDate, input.InputVariable); | ||||
|  | ||||
|             _logger.LogInformation("Downloading uptake map"); | ||||
|             await _farmmapsApiService.DownloadItemAsync(uptakeMapItem.Code, | ||||
|                 Path.Combine(DownloadFolder, $"{input.OutputFileName}.uptake.zip")); | ||||
|  | ||||
|             _logger.LogInformation("Calculating appliance map"); | ||||
|             var applianceMapItem = | ||||
|                 await _nitrogenService.CalculateApplicationMap(cropfieldItem, isariaGeotiffItem, plantingDate, | ||||
|             _logger.LogInformation("Calculating application map"); | ||||
|             var applicationMapItem = | ||||
|                 await _nitrogenService.CalculateApplicationMap(cropfieldItem, geotiffItem, plantingDate, | ||||
|                     measurementDate, | ||||
|                     "irmi", targetNData.TargetN); | ||||
|                     input.InputVariable, targetNData.TargetN); | ||||
|  | ||||
|             _logger.LogInformation("Downloading appliance map"); | ||||
|             await _farmmapsApiService.DownloadItemAsync(applianceMapItem.Code, | ||||
|             _logger.LogInformation("Downloading application map"); | ||||
|             await _farmmapsApiService.DownloadItemAsync(applicationMapItem.Code, | ||||
|                 Path.Combine(DownloadFolder, $"{input.OutputFileName}.application.zip")); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| [ | ||||
|   { | ||||
|     "isariaZipFile": "Scan_1_20190605.zip", | ||||
|     "zippedShapeFile": "Scan_1_20190605.zip", | ||||
|     "inputVariable":  "irmi", | ||||
|     "outputFileName": "vranbs1", | ||||
|     "plantingDate": "2019-04-18", | ||||
|     "measurementDate": "2019-06-05", | ||||
| @@ -9,30 +10,117 @@ | ||||
|     "geometryJson": { "type": "Polygon", "coordinates": [ [ [ 3.40843828875524, 50.638966444680605 ], [ 3.408953272886064, 50.639197789621612 ], [ 3.409242951459603, 50.639469958681836 ], [ 3.409328782148028, 50.639612846807708 ], [ 3.409457528180712, 50.639789755314411 ], [ 3.409639918393741, 50.640014292074966 ], [ 3.409833037442765, 50.640211611372706 ], [ 3.410069071836049, 50.640395321698435 ], [ 3.410380208081761, 50.640572227259661 ], [ 3.410605513638958, 50.640715112034222 ], [ 3.411925160474145, 50.641177783561204 ], [ 3.411935889310142, 50.640728720085136 ], [ 3.412590348309737, 50.63948356709389 ], [ 3.413244807309242, 50.638224772339846 ], [ 3.413400375432099, 50.637901562841307 ], [ 3.413539850300779, 50.637449065809889 ], [ 3.413475477284437, 50.637418445552932 ], [ 3.40999396998362, 50.637449065810451 ], [ 3.409940325803365, 50.638102293212661 ], [ 3.409575545377398, 50.638483338338325 ], [ 3.409060561246574, 50.638707881340494 ], [ 3.40843828875524, 50.638966444680605 ] ] ] } | ||||
|   }, | ||||
|   { | ||||
|     "isariaZipFile": "Scan_1_20190605.zip", | ||||
|     "zippedShapeFile": "Scan_1_20190605.zip", | ||||
|     "inputVariable": "irmi", | ||||
|     "outputFileName": "vranbs2", | ||||
|     "plantingDate": "2019-04-18", | ||||
|     "measurementDate": "2019-06-05", | ||||
|     "potatoPurposeType": "starch", | ||||
|     "targetYield": 45, | ||||
|     "geometryJson": { "type": "Polygon", "coordinates": [ [ [ 3.40843828875524, 50.638966444680605 ], [ 3.408953272886064, 50.639197789621612 ], [ 3.409242951459603, 50.639469958681836 ], [ 3.409328782148028, 50.639612846807708 ], [ 3.409457528180712, 50.639789755314411 ], [ 3.409639918393741, 50.640014292074966 ], [ 3.409833037442765, 50.640211611372706 ], [ 3.410069071836049, 50.640395321698435 ], [ 3.410380208081761, 50.640572227259661 ], [ 3.410605513638958, 50.640715112034222 ], [ 3.411925160474145, 50.641177783561204 ], [ 3.411935889310142, 50.640728720085136 ], [ 3.412590348309737, 50.63948356709389 ], [ 3.413244807309242, 50.638224772339846 ], [ 3.413400375432099, 50.637901562841307 ], [ 3.413539850300779, 50.637449065809889 ], [ 3.413475477284437, 50.637418445552932 ], [ 3.40999396998362, 50.637449065810451 ], [ 3.409940325803365, 50.638102293212661 ], [ 3.409575545377398, 50.638483338338325 ], [ 3.409060561246574, 50.638707881340494 ], [ 3.40843828875524, 50.638966444680605 ] ] ] } | ||||
|     "geometryJson": { | ||||
|       "type": "Polygon", | ||||
|       "coordinates": [ | ||||
|         [ | ||||
|           [ 3.40843828875524, 50.638966444680605 ], | ||||
|           [ 3.408953272886064, 50.639197789621612 ], | ||||
|           [ 3.409242951459603, 50.639469958681836 ], | ||||
|           [ 3.409328782148028, 50.639612846807708 ], | ||||
|           [ 3.409457528180712, 50.639789755314411 ], | ||||
|           [ 3.409639918393741, 50.640014292074966 ], | ||||
|           [ 3.409833037442765, 50.640211611372706 ], | ||||
|           [ 3.410069071836049, 50.640395321698435 ], | ||||
|           [ 3.410380208081761, 50.640572227259661 ], | ||||
|           [ 3.410605513638958, 50.640715112034222 ], | ||||
|           [ 3.411925160474145, 50.641177783561204 ], | ||||
|           [ 3.411935889310142, 50.640728720085136 ], | ||||
|           [ 3.412590348309737, 50.63948356709389 ], | ||||
|           [ 3.413244807309242, 50.638224772339846 ], | ||||
|           [ 3.413400375432099, 50.637901562841307 ], | ||||
|           [ 3.413539850300779, 50.637449065809889 ], | ||||
|           [ 3.413475477284437, 50.637418445552932 ], | ||||
|           [ 3.40999396998362, 50.637449065810451 ], | ||||
|           [ 3.409940325803365, 50.638102293212661 ], | ||||
|           [ 3.409575545377398, 50.638483338338325 ], | ||||
|           [ 3.409060561246574, 50.638707881340494 ], | ||||
|           [ 3.40843828875524, 50.638966444680605 ] | ||||
|         ] | ||||
|       ] | ||||
|     } | ||||
|   }, | ||||
|   { | ||||
|     "isariaZipFile": "Scan_1_20190605.zip", | ||||
|     "zippedShapeFile": "Scan_1_20190605.zip", | ||||
|     "inputVariable": "irmi", | ||||
|     "outputFileName": "vranbs3", | ||||
|     "plantingDate": "2019-04-18", | ||||
|     "measurementDate": "2019-06-20", | ||||
|     "potatoPurposeType": "starch", | ||||
|     "targetYield": 45, | ||||
|     "geometryJson": { "type": "Polygon", "coordinates": [ [ [ 3.40843828875524, 50.638966444680605 ], [ 3.408953272886064, 50.639197789621612 ], [ 3.409242951459603, 50.639469958681836 ], [ 3.409328782148028, 50.639612846807708 ], [ 3.409457528180712, 50.639789755314411 ], [ 3.409639918393741, 50.640014292074966 ], [ 3.409833037442765, 50.640211611372706 ], [ 3.410069071836049, 50.640395321698435 ], [ 3.410380208081761, 50.640572227259661 ], [ 3.410605513638958, 50.640715112034222 ], [ 3.411925160474145, 50.641177783561204 ], [ 3.411935889310142, 50.640728720085136 ], [ 3.412590348309737, 50.63948356709389 ], [ 3.413244807309242, 50.638224772339846 ], [ 3.413400375432099, 50.637901562841307 ], [ 3.413539850300779, 50.637449065809889 ], [ 3.413475477284437, 50.637418445552932 ], [ 3.40999396998362, 50.637449065810451 ], [ 3.409940325803365, 50.638102293212661 ], [ 3.409575545377398, 50.638483338338325 ], [ 3.409060561246574, 50.638707881340494 ], [ 3.40843828875524, 50.638966444680605 ] ] ] } | ||||
|     "geometryJson": { | ||||
|       "type": "Polygon", | ||||
|       "coordinates": [ | ||||
|         [ | ||||
|           [ 3.40843828875524, 50.638966444680605 ], | ||||
|           [ 3.408953272886064, 50.639197789621612 ], | ||||
|           [ 3.409242951459603, 50.639469958681836 ], | ||||
|           [ 3.409328782148028, 50.639612846807708 ], | ||||
|           [ 3.409457528180712, 50.639789755314411 ], | ||||
|           [ 3.409639918393741, 50.640014292074966 ], | ||||
|           [ 3.409833037442765, 50.640211611372706 ], | ||||
|           [ 3.410069071836049, 50.640395321698435 ], | ||||
|           [ 3.410380208081761, 50.640572227259661 ], | ||||
|           [ 3.410605513638958, 50.640715112034222 ], | ||||
|           [ 3.411925160474145, 50.641177783561204 ], | ||||
|           [ 3.411935889310142, 50.640728720085136 ], | ||||
|           [ 3.412590348309737, 50.63948356709389 ], | ||||
|           [ 3.413244807309242, 50.638224772339846 ], | ||||
|           [ 3.413400375432099, 50.637901562841307 ], | ||||
|           [ 3.413539850300779, 50.637449065809889 ], | ||||
|           [ 3.413475477284437, 50.637418445552932 ], | ||||
|           [ 3.40999396998362, 50.637449065810451 ], | ||||
|           [ 3.409940325803365, 50.638102293212661 ], | ||||
|           [ 3.409575545377398, 50.638483338338325 ], | ||||
|           [ 3.409060561246574, 50.638707881340494 ], | ||||
|           [ 3.40843828875524, 50.638966444680605 ] | ||||
|         ] | ||||
|       ] | ||||
|     } | ||||
|   }, | ||||
|   { | ||||
|     "isariaZipFile": "Scan_1_20190605.zip", | ||||
|     "zippedShapeFile": "Scan_1_20190605.zip", | ||||
|     "inputVariable": "irmi", | ||||
|     "outputFileName": "vranbs4", | ||||
|     "plantingDate": "2019-04-18", | ||||
|     "measurementDate": "2019-07-03", | ||||
|     "potatoPurposeType": "starch", | ||||
|     "targetYield": 45, | ||||
|     "geometryJson": { "type": "Polygon", "coordinates": [ [ [ 3.40843828875524, 50.638966444680605 ], [ 3.408953272886064, 50.639197789621612 ], [ 3.409242951459603, 50.639469958681836 ], [ 3.409328782148028, 50.639612846807708 ], [ 3.409457528180712, 50.639789755314411 ], [ 3.409639918393741, 50.640014292074966 ], [ 3.409833037442765, 50.640211611372706 ], [ 3.410069071836049, 50.640395321698435 ], [ 3.410380208081761, 50.640572227259661 ], [ 3.410605513638958, 50.640715112034222 ], [ 3.411925160474145, 50.641177783561204 ], [ 3.411935889310142, 50.640728720085136 ], [ 3.412590348309737, 50.63948356709389 ], [ 3.413244807309242, 50.638224772339846 ], [ 3.413400375432099, 50.637901562841307 ], [ 3.413539850300779, 50.637449065809889 ], [ 3.413475477284437, 50.637418445552932 ], [ 3.40999396998362, 50.637449065810451 ], [ 3.409940325803365, 50.638102293212661 ], [ 3.409575545377398, 50.638483338338325 ], [ 3.409060561246574, 50.638707881340494 ], [ 3.40843828875524, 50.638966444680605 ] ] ] } | ||||
|     "geometryJson": { | ||||
|       "type": "Polygon", | ||||
|       "coordinates": [ | ||||
|         [ | ||||
|           [ 3.40843828875524, 50.638966444680605 ], | ||||
|           [ 3.408953272886064, 50.639197789621612 ], | ||||
|           [ 3.409242951459603, 50.639469958681836 ], | ||||
|           [ 3.409328782148028, 50.639612846807708 ], | ||||
|           [ 3.409457528180712, 50.639789755314411 ], | ||||
|           [ 3.409639918393741, 50.640014292074966 ], | ||||
|           [ 3.409833037442765, 50.640211611372706 ], | ||||
|           [ 3.410069071836049, 50.640395321698435 ], | ||||
|           [ 3.410380208081761, 50.640572227259661 ], | ||||
|           [ 3.410605513638958, 50.640715112034222 ], | ||||
|           [ 3.411925160474145, 50.641177783561204 ], | ||||
|           [ 3.411935889310142, 50.640728720085136 ], | ||||
|           [ 3.412590348309737, 50.63948356709389 ], | ||||
|           [ 3.413244807309242, 50.638224772339846 ], | ||||
|           [ 3.413400375432099, 50.637901562841307 ], | ||||
|           [ 3.413539850300779, 50.637449065809889 ], | ||||
|           [ 3.413475477284437, 50.637418445552932 ], | ||||
|           [ 3.40999396998362, 50.637449065810451 ], | ||||
|           [ 3.409940325803365, 50.638102293212661 ], | ||||
|           [ 3.409575545377398, 50.638483338338325 ], | ||||
|           [ 3.409060561246574, 50.638707881340494 ], | ||||
|           [ 3.40843828875524, 50.638966444680605 ] | ||||
|         ] | ||||
|       ] | ||||
|     } | ||||
|   } | ||||
| ] | ||||
| @@ -84,7 +84,7 @@ namespace FarmmapsNbs | ||||
|         /// <param name="measurementDate">The date the measurements are taken</param> | ||||
|         /// <returns></returns> | ||||
|         public async Task<Item> CalculateUptakeMap(Item cropfieldItem, Item inputItem, DateTime plantingDate,  | ||||
|             DateTime measurementDate, string inputType = "irmi") | ||||
|             DateTime measurementDate, string inputType) | ||||
|         { | ||||
|             var nbsUptakeMapRequest = new TaskRequest {TaskType = VRANBS_TASK}; | ||||
|             nbsUptakeMapRequest.attributes["operation"] = "uptake"; | ||||
| @@ -125,7 +125,7 @@ namespace FarmmapsNbs | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates the nitrogen appliance map based on given input data | ||||
|         /// Creates the nitrogen application map based on given input data | ||||
|         /// </summary> | ||||
|         /// <param name="cropfieldItem">The cropfield to base the calculations on</param> | ||||
|         /// <param name="inputItem">The farmmaps item containing the geotiff data</param> | ||||
| @@ -135,18 +135,18 @@ namespace FarmmapsNbs | ||||
|         /// <param name="targetN">The target nitrogen to use for the calculations</param> | ||||
|         /// <returns></returns> | ||||
|         public async Task<Item> CalculateApplicationMap(Item cropfieldItem, Item inputItem, DateTime plantingDate,  | ||||
|             DateTime measurementDate, string inputType = "irmi", double targetN = 60.0) | ||||
|             DateTime measurementDate, string inputType, double targetN) | ||||
|         { | ||||
|             var nbsApplianceMapRequest = new TaskRequest {TaskType = VRANBS_TASK}; | ||||
|             nbsApplianceMapRequest.attributes["operation"] = "application"; | ||||
|             nbsApplianceMapRequest.attributes["inputCode"] = inputItem.Code; | ||||
|             nbsApplianceMapRequest.attributes["plantingDate"] = plantingDate.ToString(); | ||||
|             nbsApplianceMapRequest.attributes["measurementDate"] = measurementDate.ToString(); | ||||
|             nbsApplianceMapRequest.attributes["inputCode"] = inputItem.Code; | ||||
|             nbsApplianceMapRequest.attributes["inputType"] = inputType.ToLower(); | ||||
|             nbsApplianceMapRequest.attributes["targetN"] = targetN.ToString(CultureInfo.InvariantCulture); | ||||
|             var nbsApplicationMapRequest = new TaskRequest {TaskType = VRANBS_TASK}; | ||||
|             nbsApplicationMapRequest.attributes["operation"] = "application"; | ||||
|             nbsApplicationMapRequest.attributes["inputCode"] = inputItem.Code; | ||||
|             nbsApplicationMapRequest.attributes["plantingDate"] = plantingDate.ToString(); | ||||
|             nbsApplicationMapRequest.attributes["measurementDate"] = measurementDate.ToString(); | ||||
|             nbsApplicationMapRequest.attributes["inputCode"] = inputItem.Code; | ||||
|             nbsApplicationMapRequest.attributes["inputType"] = inputType.ToLower(); | ||||
|             nbsApplicationMapRequest.attributes["targetN"] = targetN.ToString(CultureInfo.InvariantCulture); | ||||
|              | ||||
|             string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsApplianceMapRequest); | ||||
|             string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsApplicationMapRequest); | ||||
|              | ||||
|             await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => | ||||
|             { | ||||
| @@ -163,17 +163,17 @@ namespace FarmmapsNbs | ||||
|             } | ||||
|  | ||||
|             var itemName = $"VRANbs application"; | ||||
|             var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code, | ||||
|             var applicationMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code, | ||||
|                 GEOTIFF_PROCESSED_ITEMTYPE, itemName,  | ||||
|                 i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) && | ||||
|                      i.Name.ToLower().Contains(itemName.ToLower())); | ||||
|             if (applianceMapItem == null) | ||||
|             if (applicationMapItem == null) | ||||
|             { | ||||
|                 _logger.LogError("Could not find the application map geotiff child item under cropfield"); | ||||
|                 return null; | ||||
|             } | ||||
|  | ||||
|             return applianceMapItem; | ||||
|             return applicationMapItem; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user