start & end date & geometry added to operations item and to cropfield characteristics item

master
Pepijn van Oort 2023-10-11 17:00:25 +02:00
parent fedd363075
commit 1cc36422a4
3 changed files with 20 additions and 9 deletions

View File

@ -37,8 +37,11 @@ namespace FarmmapsApi.Services
return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest);
}
public async Task<Item> CreateOperationItemAsync(string cropRecordingItemCode, string data = "{}")
public async Task<Item> 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<Item> CreateCropfieldCharacteristicItemAsync(string cropfieldItemCode, string data = "{}")
public async Task<Item> 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);

View File

@ -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)

View File

@ -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",