diff --git a/FarmmapsApi/Services/FarmmapsApiService.cs b/FarmmapsApi/Services/FarmmapsApiService.cs
index 1a2770b..6c18202 100644
--- a/FarmmapsApi/Services/FarmmapsApiService.cs
+++ b/FarmmapsApi/Services/FarmmapsApiService.cs
@@ -284,6 +284,7 @@ namespace FarmmapsApi.Services
///
///
public async Task UploadFile(string filePath, string parentItemCode,
+ string geoJsonString = null,
Action progressCallback = null)
{
if (!File.Exists(filePath))
@@ -300,7 +301,8 @@ namespace FarmmapsApi.Services
{
Name = Path.GetFileName(filePath),
ParentCode = parentItemCode,
- Size = uploadStream.Length
+ Size = uploadStream.Length,
+ Geometry = string.IsNullOrEmpty(geoJsonString) ? null : JObject.Parse(geoJsonString)
};
using var httpClient = CreateConfigurableHttpClient(_httpClient);
diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs
index a415c07..9e55854 100644
--- a/FarmmapsApi/Services/GeneralService.cs
+++ b/FarmmapsApi/Services/GeneralService.cs
@@ -41,10 +41,10 @@ namespace FarmmapsApi.Services
return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest);
}
- public async Task- UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName)
+ public async Task
- UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName, string geoJsonString = null)
{
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}"));
if (result.Progress.Status == UploadStatus.Failed)
@@ -55,10 +55,10 @@ namespace FarmmapsApi.Services
i.Name.ToLower().Contains(itemName.ToLower()));
}
- public async Task
- UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName)
+ public async Task
- UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName, string geoJsonString = null)
{
- var startUpload = DateTime.UtcNow;
- var result = await _farmmapsApiService.UploadFile(filePath, root.Code,
+ var startUpload = DateTime.UtcNow.AddSeconds(-3);
+ var result = await _farmmapsApiService.UploadFile(filePath, root.Code, geoJsonString,
progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}"));
if (result.Progress.Status == UploadStatus.Failed)
diff --git a/FarmmapsHaulmkilling/HaulmkillingApplication.cs b/FarmmapsHaulmkilling/HaulmkillingApplication.cs
index 272873d..bf57ac8 100644
--- a/FarmmapsHaulmkilling/HaulmkillingApplication.cs
+++ b/FarmmapsHaulmkilling/HaulmkillingApplication.cs
@@ -132,11 +132,11 @@ namespace FarmmapsHaulmkilling
}
var selectedAgent = agents[0];
- var selectedOption = selectedAgent.SupportedOptions[0];
+ var selectedOption = selectedAgent.ValidOptions[0];
_logger.LogInformation("Calculating application map");
var applianceMapItem = await _haulmkillingService.CalculateApplicationMapAsync(cropfieldItem,
- firstSatelliteItem, inputType, selectedAgent.Name, selectedOption);
+ firstSatelliteItem, inputType, selectedOption, selectedAgent);
if (applianceMapItem == null)
{
return;
diff --git a/FarmmapsHaulmkilling/HaulmkillingService.cs b/FarmmapsHaulmkilling/HaulmkillingService.cs
index 98bd4d9..ff6f31e 100644
--- a/FarmmapsHaulmkilling/HaulmkillingService.cs
+++ b/FarmmapsHaulmkilling/HaulmkillingService.cs
@@ -6,6 +6,7 @@ using FarmmapsApi.Models;
using FarmmapsApi.Services;
using FarmmapsHaulmkilling.Models;
using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
using static FarmmapsApi.Extensions;
using static FarmmapsApiSamples.Constants;
@@ -31,14 +32,11 @@ namespace FarmmapsHaulmkilling
/// List of haulmkilling agents
public async Task
> GetHaulmkillingAgents()
{
- var itemType = "vnd.farmmaps.package.vra.haulmkilling";
- var vraHerbicideDataItems = await _farmmapsApiService.GetItemsAsync(string.Empty, itemType);
+ var itemType = "vnd.farmmaps.itemtype.codelist.fm005";
+ var haulmkillingAgentItems = await _farmmapsApiService.GetItemsAsync(string.Empty, itemType);
- var item = vraHerbicideDataItems.FirstOrDefault();
- if (item == null)
- return null;
-
- return item.Data.ContainsKey("agents") ? item.Data["agents"].ToObject>() : null;
+ return haulmkillingAgentItems.Select(item => item.Data.ToObject())
+ .ToList();
}
///
@@ -47,11 +45,11 @@ namespace FarmmapsHaulmkilling
/// The context cropfield item to use
/// The geotiff item to use
/// WDVI or NDVI
- /// One of the available agents
+ /// code of one of the available agents
/// One of the available options
/// Haulmkilling application map item
public async Task- CalculateApplicationMapAsync(Item cropfieldItem, Item inputItem, string inputType,
- string agentName, string selectedOption)
+ string selectedOption, HaulmkillingAgent agent)
{
var taskRequest = new TaskRequest()
{
@@ -59,7 +57,7 @@ namespace FarmmapsHaulmkilling
};
taskRequest.attributes["inputCode"] = inputItem.Code;
taskRequest.attributes["inputType"] = inputType;
- taskRequest.attributes["agentName"] = agentName;
+ taskRequest.attributes["agentCode"] = agent.Code;
taskRequest.attributes["selectedOption"] = selectedOption;
taskRequest.attributes["minPercentile"] = "0.0";
@@ -79,7 +77,7 @@ namespace FarmmapsHaulmkilling
return null;
}
- var itemName = $"VRAHaulmkilling {agentName}";
+ var itemName = $"VRAHaulmkilling {agent.Label}";
var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
GEOTIFF_PROCESSED_ITEMTYPE, itemName,
i => i.Updated >= itemTask.Finished &&
diff --git a/FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs b/FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs
index 929197a..4f645f6 100644
--- a/FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs
+++ b/FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs
@@ -5,26 +5,11 @@ namespace FarmmapsHaulmkilling.Models
{
public class HaulmkillingAgent
{
- public string Name { get; set; }
- public List SupportedOptions { get; set; }
- public Dictionary> Values { get; set; }
+ public string Cl { get; set; }
+ public string Code { get; set; }
+ public string Label { get; set; }
+ public string Options { get; set; }
- public HaulmkillingAgentValue? GetAgentValue(string inputName, string optionKey)
- {
- 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; }
+ public List ValidOptions => Options.Split(',').ToList();
}
}
\ No newline at end of file