From 3f6667691489b52744af2cd32bd7d2aa6cc684e0 Mon Sep 17 00:00:00 2001 From: Pepijn van Oort Date: Wed, 15 Nov 2023 16:49:46 +0100 Subject: [PATCH] specify how many seconds to wait for the KPItask to be completed --- FarmmapsApi/Services/GeneralService.cs | 7 +++++-- FarmmapsKPI/KPIApplication.cs | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index ce0a792..977e8df 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -365,12 +365,13 @@ namespace FarmmapsApi.Services return bofekItem; } - public async Task> GetKpiItemsForCropField(Item cropfieldItem) + public async Task> GetKpiItemsForCropField(Item cropfieldItem, int waitsecs = 6) { TaskRequest kpiRequest = new TaskRequest { TaskType = KPI_TASK }; kpiRequest.attributes["processAggregateKpi"] = "false"; int year = cropfieldItem.DataDate.Value.Year; kpiRequest.attributes["year"] = year.ToString(); + int ms = waitsecs * 1000; string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, kpiRequest); @@ -387,7 +388,9 @@ namespace FarmmapsApi.Services _logger.LogError($"Something went wrong with task execution: {itemTask.Message}"); return null; } - await Task.Delay(6000); // wait 6000 secs for task to be completed + _logger.LogInformation($"Taking {waitsecs} seconds to look up all KPI items. The longer we wait the more KPI's we get ..." + + $""); + await Task.Delay(ms); // wait 60000ms = 60 secs for task to be completed //After the task is completed we have 1 kpiContainerItem with a code and with no data //Because the data are in the children of this kpiContainerItem. The container will have a list of children each with an "id" aand data, diff --git a/FarmmapsKPI/KPIApplication.cs b/FarmmapsKPI/KPIApplication.cs index 1fa53f6..d1a989c 100644 --- a/FarmmapsKPI/KPIApplication.cs +++ b/FarmmapsKPI/KPIApplication.cs @@ -85,8 +85,9 @@ namespace FarmmapsKPI TimeSpan tsTotalEstimated; for (int i = 0; i < fieldsInputs.Count; i++) - { - watch.Restart(); + //for (int i = 7; i < 8; i++) + { + watch.Restart(); input = fieldsInputs[i]; _logger.LogInformation(string.Format($"// FarmmapsKPI: Downloading KPI's for field {i + 1} out of {fieldsInputs.Count} to single csv file {KPIItemPathCsv}")); try @@ -262,7 +263,7 @@ namespace FarmmapsKPI if (data.area != area_ha) { double differencePercent = 100.0*(Convert.ToDouble(area_ha) / Convert.ToDouble(data.area) - 1.0); - _logger.LogWarning($"cropfield has area {area_ha}, but operation has area {data.area}" + + _logger.LogWarning($"cropfield has area {area_ha}, but in your KPIinput.json or file like that, you have an operation with area {data.area}" + $" Difference is {area_ha} / {data.area} - 100% = {differencePercent}%." + $" Is that correct? Example if operation was applied in part of field, e.g. in case of variable rate (VRA) application." + $" Or did you accidentally fill in area in the KPIinput json? To use cropfield area, omit field 'area' from json" + @@ -311,7 +312,7 @@ namespace FarmmapsKPI //Now get the KPIs for this cropfield, mounted with operations & cropyield // Get KPI data for saving it in a file, here the generalsedrvice is called to get the KPI data _logger.LogInformation($"GetKpiItemsForCropField('{cropfieldItem.Code}')"); - KPIItems = await _generalService.GetKpiItemsForCropField(cropfieldItem); + KPIItems = await _generalService.GetKpiItemsForCropField(cropfieldItem, 60); _logger.LogInformation($"Found {KPIItems.Count} KPI items"); //Download KPI's into a json output file for this specific cropfield (with unique cropfieldItem.Code)