From 1cc36422a4dd12f1d4f6fad9e165a8486c82e72a Mon Sep 17 00:00:00 2001 From: Pepijn van Oort Date: Wed, 11 Oct 2023 17:00:25 +0200 Subject: [PATCH] start & end date & geometry added to operations item and to cropfield characteristics item --- FarmmapsApi/Services/GeneralService.cs | 17 ++++++++++++++--- FarmmapsKPI/KPIApplication.cs | 6 +++--- FarmmapsKPI/KPIInput.json | 6 +++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index a5184e8..8581455 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -37,8 +37,11 @@ namespace FarmmapsApi.Services return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest); } - public async Task CreateOperationItemAsync(string cropRecordingItemCode, string data = "{}") + public async Task CreateOperationItemAsync(string cropRecordingItemCode, int year, + string fieldGeomJson, string data = "{}") { + // not sure if here we also need to specify DataDate, DataEndDate & Geometry. Do it just in case + var currentYear = new DateTime(year, 1, 1); JObject jdata = JObject.Parse(data); string name = string.Format($"CrpRec Operation, {jdata.GetValue("name")}"); @@ -47,21 +50,29 @@ namespace FarmmapsApi.Services ParentCode = cropRecordingItemCode, ItemType = CROPOP_ITEMTYPE, Name = name, + DataDate = currentYear, + DataEndDate = currentYear.AddYears(1).AddDays(-1), Data = jdata, + Geometry = JObject.Parse(fieldGeomJson) }; return await _farmmapsApiService.CreateItemAsync(operationItemRequest); } - public async Task CreateCropfieldCharacteristicItemAsync(string cropfieldItemCode, string data = "{}") + public async Task CreateCropfieldCharacteristicItemAsync(string cropfieldItemCode, int year, + string fieldGeomJson, string data = "{}") { + // not sure if here we also need to specify DataDate, DataEndDate & Geometry. Do it just in case string name = "Cropfield characteristic"; - + var currentYear = new DateTime(year, 1, 1); ItemRequest cropfieldCharactericsticItemRequest = new ItemRequest() { ParentCode = cropfieldItemCode, ItemType = CROPCHAR_ITEMTYPE, Name = name, + DataDate = currentYear, + DataEndDate = currentYear.AddYears(1).AddDays(-1), Data = JObject.Parse(data), + Geometry = JObject.Parse(fieldGeomJson) }; return await _farmmapsApiService.CreateItemAsync(cropfieldCharactericsticItemRequest); diff --git a/FarmmapsKPI/KPIApplication.cs b/FarmmapsKPI/KPIApplication.cs index 301a3e3..7fd90b8 100644 --- a/FarmmapsKPI/KPIApplication.cs +++ b/FarmmapsKPI/KPIApplication.cs @@ -155,7 +155,7 @@ namespace FarmmapsKPI if (useCreatedOperations == false || string.IsNullOrEmpty(_settings.OperationItemCode)) { _logger.LogInformation("CreateOperationItemAsync ..."); - crpOperationItem = await _generalService.CreateOperationItemAsync(crprecItem.Code,input.DataOperation.ToString(Formatting.None)); + crpOperationItem = await _generalService.CreateOperationItemAsync(crprecItem.Code, cropYear, input.GeometryJson.ToString(Formatting.None), input.DataOperation.ToString(Formatting.None)); _settings.OperationItemCode = crpOperationItem.Code; SaveSettings(settingsfile); } @@ -181,7 +181,7 @@ namespace FarmmapsKPI if (useCreatedCropfieldCharacteristic == false) { _logger.LogInformation("CreateCropfieldCharacteristicItemAsync ..."); - cropfieldCharacteristicItem = await _generalService.CreateCropfieldCharacteristicItemAsync(cropfieldItem.Code, input.DataCropfieldCharacteristic.ToString(Formatting.None)); + cropfieldCharacteristicItem = await _generalService.CreateCropfieldCharacteristicItemAsync(cropfieldItem.Code, cropYear, input.GeometryJson.ToString(Formatting.None), input.DataCropfieldCharacteristic.ToString(Formatting.None)); _settings.CropfieldCharacteristicItemCode = cropfieldCharacteristicItem.Code; SaveSettings(settingsfile); } @@ -210,7 +210,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})"); + _logger.LogInformation($"GetKpiItemsForCropField('{cropfieldItem.Code}')"); var KPIItem = await _generalService.GetKpiItemsForCropField(cropfieldItem); //Download KPI's into a json output file for this specific cropfield (with unique cropfieldItem.Code) diff --git a/FarmmapsKPI/KPIInput.json b/FarmmapsKPI/KPIInput.json index d76e98e..c34b7f6 100644 --- a/FarmmapsKPI/KPIInput.json +++ b/FarmmapsKPI/KPIInput.json @@ -1,6 +1,6 @@ [ { - "UseCreatedCropfield": true, + "UseCreatedCropfield": false, "CropfieldItemCode": "", "dataCropfield": { //"area": 4.22, @@ -14,10 +14,10 @@ "productionPurposeCode": "003" //"productionPurposeName": "consumption" }, - "UseCreatedCropRecording": true, + "UseCreatedCropRecording": false, "CropRecordingItemCode": "", "dataCropRecording": {}, //not yet used - "UseCreatedOperation": true, + "UseCreatedOperation": false, "OperationItemCode": "", "dataOperation": { "n": "92",