can now specify geojson bounds for upload.
changed how to get agents for haulmkilling.
This commit is contained in:
		| @@ -284,6 +284,7 @@ namespace FarmmapsApi.Services | |||||||
|         /// <returns></returns> |         /// <returns></returns> | ||||||
|         /// <exception cref="FileNotFoundException"></exception> |         /// <exception cref="FileNotFoundException"></exception> | ||||||
|         public async Task<UploadResults> UploadFile(string filePath, string parentItemCode, |         public async Task<UploadResults> UploadFile(string filePath, string parentItemCode, | ||||||
|  |             string geoJsonString = null, | ||||||
|             Action<IUploadProgress> progressCallback = null) |             Action<IUploadProgress> progressCallback = null) | ||||||
|         { |         { | ||||||
|             if (!File.Exists(filePath)) |             if (!File.Exists(filePath)) | ||||||
| @@ -300,7 +301,8 @@ namespace FarmmapsApi.Services | |||||||
|             { |             { | ||||||
|                 Name = Path.GetFileName(filePath), |                 Name = Path.GetFileName(filePath), | ||||||
|                 ParentCode = parentItemCode, |                 ParentCode = parentItemCode, | ||||||
|                 Size = uploadStream.Length |                 Size = uploadStream.Length, | ||||||
|  |                 Geometry = string.IsNullOrEmpty(geoJsonString) ? null : JObject.Parse(geoJsonString) | ||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             using var httpClient = CreateConfigurableHttpClient(_httpClient); |             using var httpClient = CreateConfigurableHttpClient(_httpClient); | ||||||
|   | |||||||
| @@ -41,10 +41,10 @@ namespace FarmmapsApi.Services | |||||||
|             return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest); |             return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public async Task<Item> UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName) |         public async Task<Item> UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName, string geoJsonString = null) | ||||||
|         { |         { | ||||||
|             var startUpload = DateTime.UtcNow.AddSeconds(-3); |             var startUpload = DateTime.UtcNow.AddSeconds(-3); | ||||||
|             var result = await _farmmapsApiService.UploadFile(filePath, root.Code, |             var result = await _farmmapsApiService.UploadFile(filePath, root.Code, geoJsonString, | ||||||
|                 progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); |                 progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); | ||||||
|  |  | ||||||
|             if (result.Progress.Status == UploadStatus.Failed) |             if (result.Progress.Status == UploadStatus.Failed) | ||||||
| @@ -55,10 +55,10 @@ namespace FarmmapsApi.Services | |||||||
|                      i.Name.ToLower().Contains(itemName.ToLower())); |                      i.Name.ToLower().Contains(itemName.ToLower())); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public async Task<Item> UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName) |         public async Task<Item> UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName, string geoJsonString = null) | ||||||
|         { |         { | ||||||
|             var startUpload = DateTime.UtcNow; |             var startUpload = DateTime.UtcNow.AddSeconds(-3); | ||||||
|             var result = await _farmmapsApiService.UploadFile(filePath, root.Code, |             var result = await _farmmapsApiService.UploadFile(filePath, root.Code, geoJsonString, | ||||||
|                 progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); |                 progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); | ||||||
|  |  | ||||||
|             if (result.Progress.Status == UploadStatus.Failed) |             if (result.Progress.Status == UploadStatus.Failed) | ||||||
|   | |||||||
| @@ -132,11 +132,11 @@ namespace FarmmapsHaulmkilling | |||||||
|             } |             } | ||||||
|              |              | ||||||
|             var selectedAgent = agents[0]; |             var selectedAgent = agents[0]; | ||||||
|             var selectedOption = selectedAgent.SupportedOptions[0]; |             var selectedOption = selectedAgent.ValidOptions[0]; | ||||||
|              |              | ||||||
|             _logger.LogInformation("Calculating application map"); |             _logger.LogInformation("Calculating application map"); | ||||||
|             var applianceMapItem = await _haulmkillingService.CalculateApplicationMapAsync(cropfieldItem,  |             var applianceMapItem = await _haulmkillingService.CalculateApplicationMapAsync(cropfieldItem,  | ||||||
|                 firstSatelliteItem, inputType, selectedAgent.Name, selectedOption); |                 firstSatelliteItem, inputType, selectedOption, selectedAgent); | ||||||
|             if (applianceMapItem == null) |             if (applianceMapItem == null) | ||||||
|             { |             { | ||||||
|                 return; |                 return; | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ using FarmmapsApi.Models; | |||||||
| using FarmmapsApi.Services; | using FarmmapsApi.Services; | ||||||
| using FarmmapsHaulmkilling.Models; | using FarmmapsHaulmkilling.Models; | ||||||
| using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||||
|  | using Newtonsoft.Json; | ||||||
| using static FarmmapsApi.Extensions; | using static FarmmapsApi.Extensions; | ||||||
| using static FarmmapsApiSamples.Constants; | using static FarmmapsApiSamples.Constants; | ||||||
|  |  | ||||||
| @@ -31,14 +32,11 @@ namespace FarmmapsHaulmkilling | |||||||
|         /// <returns>List of haulmkilling agents</returns> |         /// <returns>List of haulmkilling agents</returns> | ||||||
|         public async Task<List<HaulmkillingAgent>> GetHaulmkillingAgents() |         public async Task<List<HaulmkillingAgent>> GetHaulmkillingAgents() | ||||||
|         { |         { | ||||||
|             var itemType = "vnd.farmmaps.package.vra.haulmkilling"; |             var itemType = "vnd.farmmaps.itemtype.codelist.fm005"; | ||||||
|             var vraHerbicideDataItems = await _farmmapsApiService.GetItemsAsync(string.Empty, itemType); |             var haulmkillingAgentItems = await _farmmapsApiService.GetItemsAsync(string.Empty, itemType); | ||||||
|  |  | ||||||
|             var item = vraHerbicideDataItems.FirstOrDefault(); |             return haulmkillingAgentItems.Select(item => item.Data.ToObject<HaulmkillingAgent>()) | ||||||
|             if (item == null) |                 .ToList(); | ||||||
|                 return null; |  | ||||||
|  |  | ||||||
|             return item.Data.ContainsKey("agents") ? item.Data["agents"].ToObject<List<HaulmkillingAgent>>() : null; |  | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -47,11 +45,11 @@ namespace FarmmapsHaulmkilling | |||||||
|         /// <param name="cropfieldItem">The context cropfield item to use</param> |         /// <param name="cropfieldItem">The context cropfield item to use</param> | ||||||
|         /// <param name="inputItem">The geotiff item to use</param> |         /// <param name="inputItem">The geotiff item to use</param> | ||||||
|         /// <param name="inputType">WDVI or NDVI</param> |         /// <param name="inputType">WDVI or NDVI</param> | ||||||
|         /// <param name="agentName">One of the available agents</param> |         /// <param name="agentCode">code of one of the available agents</param> | ||||||
|         /// <param name="selectedOption">One of the available options</param> |         /// <param name="selectedOption">One of the available options</param> | ||||||
|         /// <returns>Haulmkilling application map item</returns> |         /// <returns>Haulmkilling application map item</returns> | ||||||
|         public async Task<Item> CalculateApplicationMapAsync(Item cropfieldItem, Item inputItem, string inputType, |         public async Task<Item> CalculateApplicationMapAsync(Item cropfieldItem, Item inputItem, string inputType, | ||||||
|             string agentName, string selectedOption) |             string selectedOption, HaulmkillingAgent agent) | ||||||
|         { |         { | ||||||
|             var taskRequest = new TaskRequest() |             var taskRequest = new TaskRequest() | ||||||
|             { |             { | ||||||
| @@ -59,7 +57,7 @@ namespace FarmmapsHaulmkilling | |||||||
|             }; |             }; | ||||||
|             taskRequest.attributes["inputCode"] = inputItem.Code; |             taskRequest.attributes["inputCode"] = inputItem.Code; | ||||||
|             taskRequest.attributes["inputType"] = inputType; |             taskRequest.attributes["inputType"] = inputType; | ||||||
|             taskRequest.attributes["agentName"] = agentName; |             taskRequest.attributes["agentCode"] = agent.Code; | ||||||
|             taskRequest.attributes["selectedOption"] = selectedOption; |             taskRequest.attributes["selectedOption"] = selectedOption; | ||||||
|             taskRequest.attributes["minPercentile"] = "0.0"; |             taskRequest.attributes["minPercentile"] = "0.0"; | ||||||
|  |  | ||||||
| @@ -79,7 +77,7 @@ namespace FarmmapsHaulmkilling | |||||||
|                 return null; |                 return null; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             var itemName = $"VRAHaulmkilling {agentName}"; |             var itemName = $"VRAHaulmkilling {agent.Label}"; | ||||||
|             var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code, |             var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code, | ||||||
|                 GEOTIFF_PROCESSED_ITEMTYPE, itemName,  |                 GEOTIFF_PROCESSED_ITEMTYPE, itemName,  | ||||||
|                 i => i.Updated >= itemTask.Finished && |                 i => i.Updated >= itemTask.Finished && | ||||||
|   | |||||||
| @@ -5,26 +5,11 @@ namespace FarmmapsHaulmkilling.Models | |||||||
| { | { | ||||||
|     public class HaulmkillingAgent |     public class HaulmkillingAgent | ||||||
|     { |     { | ||||||
|         public string Name { get; set; } |         public string Cl { get; set; } | ||||||
|         public List<string> SupportedOptions { get; set; } |         public string Code { get; set; } | ||||||
|         public Dictionary<string, List<HaulmkillingAgentValue>> Values { get; set; } |         public string Label { get; set; } | ||||||
|  |         public string Options { get; set; } | ||||||
|  |  | ||||||
|         public HaulmkillingAgentValue? GetAgentValue(string inputName, string optionKey) |         public List<string> ValidOptions => Options.Split(',').ToList(); | ||||||
|         { |  | ||||||
|             if (!Values.ContainsKey(inputName)) |  | ||||||
|                 return null; |  | ||||||
|  |  | ||||||
|             var agentDataValues = Values[inputName]; |  | ||||||
|             return agentDataValues.FirstOrDefault(v => v.Option.Equals(optionKey)); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public struct HaulmkillingAgentValue |  | ||||||
|     { |  | ||||||
|         public string Option { get; set; } |  | ||||||
|         public float Min { get; set; } |  | ||||||
|         public float Max { get; set; } |  | ||||||
|         public float FMul { get; set; } |  | ||||||
|         public float FExp { get; set; } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user