From 55f00da9d08adb731e4c451c53c3e18d5d88f371 Mon Sep 17 00:00:00 2001 From: abel Date: Fri, 7 Apr 2023 14:33:49 +0200 Subject: [PATCH] KPI items ophalen voor een cropfield werkt nu. wel dus een bestaand cropfield ingeven bij de settings in de BIN. Alle KPIs worden opgehaald na een minuut wachten. --- FarmmapsApi/Constants.cs | 2 +- FarmmapsApi/Services/GeneralService.cs | 16 +++++----------- FarmmapsKPI/KPIApplication.cs | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/FarmmapsApi/Constants.cs b/FarmmapsApi/Constants.cs index 51bc178..613dfde 100644 --- a/FarmmapsApi/Constants.cs +++ b/FarmmapsApi/Constants.cs @@ -14,7 +14,7 @@ namespace FarmmapsApiSamples public const string BLIGHT_ITEMTYPE = "vnd.farmmaps.itemtype.blight"; public const string CROPREC_ITEMTYPE = "vnd.farmmaps.itemtype.crprec.operation"; public const string CROPSCHEME_ITEMTYPE = "vnd.farmmaps.itemtype.croppingscheme"; // deze toegevoegd, misschien is het type van de KPI task wel een croppingscheme - + public const string KPI_ITEM = "vnd.farmmaps.itemtype.kpi.data"; public const string VRANBS_TASK = "vnd.farmmaps.task.vranbs"; public const string VRAHERBICIDE_TASK = "vnd.farmmaps.task.vraherbicide"; diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index 5cfd6a5..8215260 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -277,7 +277,7 @@ namespace FarmmapsApi.Services return bofekItem; } - public async Task RunKPITask(Item cropfieldItem) // dit is dus nieuw om de KPI task te runnen + public async Task> GetKpiItemsForCropField(Item cropfieldItem) // dit is dus nieuw om de KPI task te runnen { var taskmapRequest = new TaskRequest { TaskType = KPI_TASK }; //hier KPI request van maken taskmapRequest.attributes["processAggregateKpi"] = "false"; // zo de properties meegeven?, moet dit niet bij de KPIinput? @@ -298,20 +298,14 @@ namespace FarmmapsApi.Services _logger.LogError($"Something went wrong with task execution: {itemTask.Message}"); return null; } + await Task.Delay(60000); //wacht hier een minuut tot de KPIs berekend zijn //hier nog definieren waar in de hierarchie een KPI item is? - //the kpi data is a child of the cropfield --> is dit wel zo? - var itemName = "kpi"; - var KPIItem = await FindChildItemAsync(cropfieldItem.Code, - CROPFIELD_ITEMTYPE, itemName); //hier moet ik dus verwijzen naar waar het KPIItem zit? ik gok dat het een cropfield item type is.-> of onderdeel van een croppingscheme? net toegevoegd. - if (KPIItem == null) - { - _logger.LogError("could not find the KPI data as a child item under the cropfield"); - return null; - } + //the kpi data is a child of the cropfield --> is dit wel zo? is kpi ook de itemName? - return KPIItem; + return await _farmmapsApiService.GetItemChildrenAsync(cropfieldItem.Code, KPI_ITEM); + } public async Task RunAhnTask(Item cropfieldItem) { diff --git a/FarmmapsKPI/KPIApplication.cs b/FarmmapsKPI/KPIApplication.cs index 3130c48..c772e19 100644 --- a/FarmmapsKPI/KPIApplication.cs +++ b/FarmmapsKPI/KPIApplication.cs @@ -145,7 +145,7 @@ namespace FarmmapsKPI // Get KPI data _logger.LogInformation("Calculate KPI map for field"); - var KPIItem = await _generalService.RunKPITask(cropfieldItem);// hier dus verwijzen naar de KPI task + var KPIItem = await _generalService.GetKpiItemsForCropField(cropfieldItem);// hier dus verwijzen naar de KPI task if ((object)null == null) { _logger.LogError("Something went wrong while obtaining the KPI map");