forked from FarmMaps/FarmMapsApiClient
Added Taskmap sample code to potenAPI
This commit is contained in:
@@ -82,10 +82,52 @@ namespace FarmmapsVRApoten
|
||||
|
||||
return applianceMapItem;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// Extra task making use of the zonering task to convert the planting distance in cm to number of seeds per m2
|
||||
public async Task<Item> ConvertToCountPerAreaTroughZonering(Item cropfieldItem, Item geotiffItem, float rijBreedte_m)
|
||||
{
|
||||
var zoneringTaskRequest = new TaskRequest() { TaskType = VRAZONERING_TASK };
|
||||
zoneringTaskRequest.attributes["formula"] = $"((100/[0])/{rijBreedte_m.ToString()})";
|
||||
zoneringTaskRequest.attributes["output"] = "{\"Name\":\"CountPerAreaConversion\",\"Quantity\":\"CountPerArea\",\"Unit\":\"#/m2\"}";
|
||||
zoneringTaskRequest.attributes["inputs"] = $"{{\"ItemCode\":{geotiffItem.Code},\"LayerName\":null\"}}";
|
||||
|
||||
var taskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, zoneringTaskRequest);
|
||||
|
||||
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
|
||||
{
|
||||
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, taskCode);
|
||||
_logger.LogInformation($"Waiting on convertion to Count per area through zoneringTast; Status: {itemTaskStatus.State}");
|
||||
if (itemTaskStatus.IsFinished)
|
||||
tokenSource.Cancel();
|
||||
});
|
||||
|
||||
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, taskCode);
|
||||
if (itemTask.State == ItemTaskState.Error)
|
||||
{
|
||||
_logger.LogError($"Something went wrong with task execution: {itemTask.Message}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var itemName = $"VRAZonering";
|
||||
var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
|
||||
GEOTIFF_PROCESSED_ITEMTYPE, itemName,
|
||||
//i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) &&
|
||||
// i.Name.ToLower().Contains(itemName.ToLower()));
|
||||
i =>
|
||||
i.Name.ToLower().Contains(itemName.ToLower()));
|
||||
if (applianceMapItem == null)
|
||||
{
|
||||
_logger.LogError("Could not find the converted to count per area geotiff child item under cropfield");
|
||||
return null;
|
||||
}
|
||||
|
||||
return applianceMapItem;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user