diff --git a/FarmmapsApi/Constants.cs b/FarmmapsApi/Constants.cs index 6db165b..027d98b 100644 --- a/FarmmapsApi/Constants.cs +++ b/FarmmapsApi/Constants.cs @@ -27,5 +27,6 @@ namespace FarmmapsApiSamples public const string SHADOW_TASK = "vnd.farmmaps.task.shadow"; public const string AHN_TASK = "vnd.farmmaps.task.ahn"; public const string WATBAL_TASK = "vnd.farmmaps.task.watbal"; + public const string KPI_TASK = "vnd.farmmaps.task.kpi"; // dus nieuwe taak om de KPIs te berekenen } } diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index 7027985..3d542ef 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -277,6 +277,41 @@ namespace FarmmapsApi.Services return bofekItem; } + public async Task RunKPITask(Item cropfieldItem) // dit is dus nieuw om de KPI task te runnen + { + var taskmapRequest = new TaskRequest { TaskType = KPI_TASK }; + + string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest); + + await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => { + var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); + _logger.LogInformation($"Waiting on retreiving KPI data; status: {itemTaskStatus.State}"); + if (itemTaskStatus.IsFinished) + tokenSource.Cancel(); + }); + + var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); + if (itemTask.State == ItemTaskState.Error) + { + _logger.LogError($"Something went wrong with task execution: {itemTask.Message}"); + return null; + } + + //hier nog definieren waar in de hierarchie een KPI item is? + + ////the BOFEK data is a child of the cropfield + //var itemName = "bofek"; + //var bofekItem = await FindChildItemAsync(cropfieldItem.Code, + // SHAPE_PROCESSED_ITEMTYPE, itemName); + //if (bofekItem == null) + //{ + // _logger.LogError("Could not find the BOFEK data as a child item under the cropfield"); + // return null; + //} + + return bofekItem; + } + public async Task RunAhnTask(Item cropfieldItem) { var taskmapRequest = new TaskRequest { TaskType = AHN_TASK }; diff --git a/FarmmapsKPI/KPIApplication.cs b/FarmmapsKPI/KPIApplication.cs index 0e8bac8..7a32a0e 100644 --- a/FarmmapsKPI/KPIApplication.cs +++ b/FarmmapsKPI/KPIApplication.cs @@ -146,8 +146,7 @@ namespace FarmmapsKPI //_logger.LogInformation("Calculate KPI map for field"); //var KPIItem = await _generalService.RunKPITask(cropfieldItem); - var KPIItem = null; - if (KPIItem == null) + if ((object)null == null) { _logger.LogError("Something went wrong while obtaining the KPI map"); return; diff --git a/FarmmapsKPI/KPIInput.json b/FarmmapsKPI/KPIInput.json index 84d35e8..b51d3b6 100644 --- a/FarmmapsKPI/KPIInput.json +++ b/FarmmapsKPI/KPIInput.json @@ -1,10 +1,10 @@ [ { - "UseCreatedCropfield": false, + "UseCreatedCropfield": true, "outputFileName": "TestData", "fieldName": "TestField", "DownloadFolder": "Downloads", //"C:\\workdir\\groenmonitor\\", // "Downloads", -> if you just put "Downloads" the program will download to somewhere in ..\FarmMapsApiClient_WURtest\FarmmapsDataDownload\bin\Debug\netcoreapp3.1\Downloads\ - "GetCropRecordings": true, + "GetCropRecordings": false, "CrprecItem": "...", //item code of de crop recording parrent - can be found by opening the crop recording page of a field. "GetShadowData": false, "GetSatelliteData": false, diff --git a/FarmmapsKPI/Models/KPIInput.cs b/FarmmapsKPI/Models/KPIInput.cs index 63e5c68..d21f594 100644 --- a/FarmmapsKPI/Models/KPIInput.cs +++ b/FarmmapsKPI/Models/KPIInput.cs @@ -14,12 +14,12 @@ namespace FarmmapsKPI.Models public JObject GeometryJson { get; set; } public string InputLayerName { get; set; } public string fieldName { get; set; } - public bool GetSatelliteData { get; set; } - public bool GetVanDerSatData { get; set; } - public string SatelliteBand { get; set; } - public bool StoreSatelliteStatisticsSingleImage { get; set; } - public bool StoreSatelliteStatisticsCropYear { get; set; } - public bool StoreVanDerSatStatistics { get; set; } + //public bool GetSatelliteData { get; set; } + // public bool GetVanDerSatData { get; set; } + // public string SatelliteBand { get; set; } + // public bool StoreSatelliteStatisticsSingleImage { get; set; } + // public bool StoreSatelliteStatisticsCropYear { get; set; } + //public bool StoreVanDerSatStatistics { get; set; } public bool GetShadowData { get; set; } public bool GetCropRecordings { get; set; } public string CrprecItem { get; set; }