handles existing cropfielditemcode

This commit is contained in:
Pepijn van Oort 2023-06-27 14:08:27 +02:00
parent b99191b7b1
commit 8a770a1762
4 changed files with 20 additions and 12 deletions

View File

@ -299,11 +299,9 @@ namespace FarmmapsApi.Services
return null; return null;
} }
await Task.Delay(60000); //wacht hier een minuut tot de KPIs berekend zijn await Task.Delay(60000); //wacht hier een minuut tot de KPIs berekend zijn
//PO20230627 Je zou hier ook om de 10 sec eens kunnen kijken of we al zo ver zijn? Iets in trant van while KPI_ITEM is null?
//hier nog definieren waar in de hierarchie een KPI item is? //hier nog definieren waar in de hierarchie een KPI item is?
//the kpi data is a child of the cropfield --> is dit wel zo? is kpi ook de itemName?
return await _farmmapsApiService.GetItemChildrenAsync(cropfieldItem.Code, KPI_ITEM); return await _farmmapsApiService.GetItemChildrenAsync(cropfieldItem.Code, KPI_ITEM);
} }

View File

@ -98,18 +98,27 @@ namespace FarmmapsKPI
// Use already created cropfield or create new one, added a Data input, with field specific data for the KPI calculation // Use already created cropfield or create new one, added a Data input, with field specific data for the KPI calculation
Item cropfieldItem; Item cropfieldItem;
if (useCreatedCropfield == true || string.IsNullOrEmpty(_settings.CropfieldItemCode)) //1 useCreatedCropfield = false -> get new
//2 useCreatedCropfield = true && CropfieldItemCode = "" or absent -> read from settings json
//2 useCreatedCropfield = true && CropfieldItemCode like "deb48a74c5b54299bb852f17288010e9" in KPIinput -> use this one
if (useCreatedCropfield == false || string.IsNullOrEmpty(_settings.CropfieldItemCode))
{ {
_logger.LogInformation("Creating cropfield"); _logger.LogInformation("Creating cropfield, writting to settings file");
cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code, cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code,
$"DataCropfield {input.OutputFileName}", cropYear, input.GeometryJson.ToString(Formatting.None), input.Data.ToString(Formatting.None)); $"DataCropfield {input.OutputFileName}", cropYear, input.GeometryJson.ToString(Formatting.None), input.Data.ToString(Formatting.None));
_settings.CropfieldItemCode = cropfieldItem.Code; _settings.CropfieldItemCode = cropfieldItem.Code;
SaveSettings(settingsfile); SaveSettings(settingsfile);
} }
else if (string.IsNullOrEmpty(input.CropfieldItemCode))
{
_logger.LogInformation("CropfieldItemCode not in json input, reading from settings json");
cropfieldItem = await _farmmapsApiService.GetItemAsync(_settings.CropfieldItemCode);
}
else else
{ {
_logger.LogInformation("Cropfield already exists, trying to get it"); _logger.LogInformation("CropfieldItemCode not in json input, reading from settings json");
cropfieldItem = await _farmmapsApiService.GetItemAsync(_settings.CropfieldItemCode); cropfieldItem = await _farmmapsApiService.GetItemAsync(input.CropfieldItemCode);
} }
//Get croprecordings //Get croprecordings
@ -143,11 +152,10 @@ namespace FarmmapsKPI
} }
// Get KPI data for saving it in a file, here the generalsedrvice is called to get the KPI data // Get KPI data for saving it in a file, here the generalsedrvice is called to get the KPI data
_logger.LogInformation($"Trying to get the cropfielditem: {cropfieldItem}"); _logger.LogInformation($"Trying to get the cropfielditem: {cropfieldItem.Code}");
var KPIItem = await _generalService.GetKpiItemsForCropField(cropfieldItem); var KPIItem = await _generalService.GetKpiItemsForCropField(cropfieldItem);
var KPIItemPath = Path.Combine(downloadFolder, $"KPIItems_{cropfieldItem.Code}.json");
var KPIItemPath = Path.Combine(downloadFolder, $"KPIItems_{KPIItem}.json");
_logger.LogInformation($"Found {KPIItem.Count} KPI items"); _logger.LogInformation($"Found {KPIItem.Count} KPI items");
var count = 0; var count = 0;
await Task.Delay(50); await Task.Delay(50);

View File

@ -1,6 +1,7 @@
[ [
{ {
"UseCreatedCropfield": false, "UseCreatedCropfield": true,
"CropfieldItemCode": "38870d5ff9b54b12877b5b01018b6fec",
"outputFileName": "TestData", "outputFileName": "TestData",
//"fieldName": "aardappelveld_test", //"fieldName": "aardappelveld_test",
//"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\ //"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\
@ -14,7 +15,7 @@
"final": true, "final": true,
//"soilCode": "5", //"soilCode": "5",
"soilName": "Loam", "soilName": "Loam",
"cropTypeCode": "1010101", // make a table/list with possible inputs. "cropTypeCode": "1010101", // make a table/list with possible inputs.
"cropTypeName": "Potato", "cropTypeName": "Potato",
//"rootDepthMax": 45, //"rootDepthMax": 45,
//"emergenceDate": "2022-05-16T00:00:00", //"emergenceDate": "2022-05-16T00:00:00",

View File

@ -6,6 +6,7 @@ namespace FarmmapsKPI.Models
public class KPIInput public class KPIInput
{ {
public bool UseCreatedCropfield { get; set; } public bool UseCreatedCropfield { get; set; }
public string CropfieldItemCode { get; set; }
public string File { get; set; } public string File { get; set; }
public string InputVariable { get; set; } public string InputVariable { get; set; }
public string OutputFileName { get; set; } public string OutputFileName { get; set; }