forked from FarmMaps/FarmMapsApiClient
updated poten&nbs, both work properly again
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -6,6 +7,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;
|
||||
|
||||
@@ -24,34 +26,31 @@ namespace FarmmapsHaulmkilling
|
||||
_farmmapsApiService = farmmapsApiService;
|
||||
_generalService = generalService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of available haulmkilling agents
|
||||
/// </summary>
|
||||
/// <returns>List of haulmkilling agents</returns>
|
||||
public async Task<List<HaulmkillingAgent>> 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<List<HaulmkillingAgent>>() : null;
|
||||
return haulmkillingAgentItems.Select(item => item.Data.ToObject<HaulmkillingAgent>())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates an haulmkilling application map
|
||||
/// </summary>
|
||||
/// <param name="cropfieldItem">The context cropfield item to use</param>
|
||||
/// <param name="inputItem">The geotiff item to use</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>
|
||||
/// <returns>Haulmkilling application map item</returns>
|
||||
public async Task<Item> CalculateApplicationMapAsync(Item cropfieldItem, Item inputItem, string inputType,
|
||||
string agentName, string selectedOption)
|
||||
string selectedOption, HaulmkillingAgent agent)
|
||||
{
|
||||
var taskRequest = new TaskRequest()
|
||||
{
|
||||
@@ -59,7 +58,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";
|
||||
|
||||
@@ -71,7 +70,7 @@ namespace FarmmapsHaulmkilling
|
||||
if (itemTaskStatus.IsFinished)
|
||||
tokenSource.Cancel();
|
||||
});
|
||||
|
||||
|
||||
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, taskCode);
|
||||
if (itemTask.State == ItemTaskState.Error)
|
||||
{
|
||||
@@ -79,12 +78,12 @@ namespace FarmmapsHaulmkilling
|
||||
return null;
|
||||
}
|
||||
|
||||
var itemName = $"VRAHaulmkilling {agentName}";
|
||||
var itemName = $"VRAHaulmkilling {agent.Label}";
|
||||
var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
|
||||
GEOTIFF_PROCESSED_ITEMTYPE, itemName,
|
||||
GEOTIFF_PROCESSED_ITEMTYPE, itemName,
|
||||
i => i.Updated >= itemTask.Finished &&
|
||||
i.Name.ToLower().Contains(itemName.ToLower()));
|
||||
|
||||
|
||||
if (applianceMapItem == null)
|
||||
{
|
||||
_logger.LogError("Could not find the VRAHaulmkilling geotiff child item under cropfield");
|
||||
@@ -94,4 +93,4 @@ namespace FarmmapsHaulmkilling
|
||||
return applianceMapItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user