StartDate & EndDate of cropfield. Is relevant for N fixation by leguminose crops where currently N fixation depends on day between these two dates. If not provided a whole year is assumed which leads to high N fixation

master
Pepijn van Oort 2023-11-08 13:50:37 +01:00
parent aef8c7c446
commit 0b0ec8f767
3 changed files with 38 additions and 20 deletions

View File

@ -22,14 +22,20 @@ namespace FarmmapsApi.Services
} }
public async Task<Item> CreateCropfieldItemAsync(string parentItemCode, string name, int year, public async Task<Item> CreateCropfieldItemAsync(string parentItemCode, string name, int year,
string fieldGeomJson, string data = "{}") { string fieldGeomJson, string data = "{}", DateTime startDate = new DateTime(), DateTime endDate = new DateTime() )
var currentYear = new DateTime(year, 1, 1); {
//If user provides no startDate or endDate, then set startDate and endDate to full year provided through 'year'
if (startDate == new DateTime() || endDate == new DateTime())
{
startDate = new DateTime(year, 1, 1);
endDate = new DateTime(year, 12, 31);
}
var cropfieldItemRequest = new ItemRequest() { var cropfieldItemRequest = new ItemRequest() {
ParentCode = parentItemCode, ParentCode = parentItemCode,
ItemType = CROPFIELD_ITEMTYPE, ItemType = CROPFIELD_ITEMTYPE,
Name = name, Name = name,
DataDate = currentYear, DataDate = startDate,
DataEndDate = currentYear.AddYears(1).AddDays(-1), DataEndDate = endDate,
Data = JObject.Parse(data), Data = JObject.Parse(data),
Geometry = JObject.Parse(fieldGeomJson) Geometry = JObject.Parse(fieldGeomJson)
}; };
@ -38,10 +44,14 @@ namespace FarmmapsApi.Services
} }
public async Task<Item> CreateOperationItemAsync(string cropRecordingItemCode, int year, public async Task<Item> CreateOperationItemAsync(string cropRecordingItemCode, int year,
string fieldGeomJson, string data = "{}") string fieldGeomJson, string data = "{}", DateTime startDate = new DateTime(), DateTime endDate = new DateTime())
{ {
// not sure if here we also need to specify DataDate, DataEndDate & Geometry. Do it just in case //If user provides no startDate or endDate, then set startDate and endDate to full year provided through 'year'
var currentYear = new DateTime(year, 1, 1); if (startDate == new DateTime() || endDate == new DateTime())
{
startDate = new DateTime(year, 1, 1);
endDate = new DateTime(year, 12, 31);
}
JObject jdata = JObject.Parse(data); JObject jdata = JObject.Parse(data);
string name = string.Format($"CrpRec Operation, {jdata.GetValue("name")}"); string name = string.Format($"CrpRec Operation, {jdata.GetValue("name")}");
@ -50,8 +60,8 @@ namespace FarmmapsApi.Services
ParentCode = cropRecordingItemCode, ParentCode = cropRecordingItemCode,
ItemType = CROPOP_ITEMTYPE, ItemType = CROPOP_ITEMTYPE,
Name = name, Name = name,
DataDate = currentYear, DataDate = startDate,
DataEndDate = currentYear.AddYears(1).AddDays(-1), DataEndDate = endDate,
Data = jdata, Data = jdata,
Geometry = JObject.Parse(fieldGeomJson) Geometry = JObject.Parse(fieldGeomJson)
}; };
@ -59,18 +69,23 @@ namespace FarmmapsApi.Services
return await _farmmapsApiService.CreateItemAsync(operationItemRequest); return await _farmmapsApiService.CreateItemAsync(operationItemRequest);
} }
public async Task<Item> CreateCropfieldCharacteristicItemAsync(string cropfieldItemCode, int year, public async Task<Item> CreateCropfieldCharacteristicItemAsync(string cropfieldItemCode, int year,
string fieldGeomJson, string data = "{}") string fieldGeomJson, string data = "{}", DateTime startDate = new DateTime(), DateTime endDate = new DateTime())
{ {
//If user provides no startDate or endDate, then set startDate and endDate to full year provided through 'year'
if (startDate == new DateTime() || endDate == new DateTime())
{
startDate = new DateTime(year, 1, 1);
endDate = new DateTime(year, 12, 31);
}
// not sure if here we also need to specify DataDate, DataEndDate & Geometry. Do it just in case // not sure if here we also need to specify DataDate, DataEndDate & Geometry. Do it just in case
string name = "Cropfield characteristic"; string name = "Cropfield characteristic";
var currentYear = new DateTime(year, 1, 1);
ItemRequest cropfieldCharactericsticItemRequest = new ItemRequest() ItemRequest cropfieldCharactericsticItemRequest = new ItemRequest()
{ {
ParentCode = cropfieldItemCode, ParentCode = cropfieldItemCode,
ItemType = CROPCHAR_ITEMTYPE, ItemType = CROPCHAR_ITEMTYPE,
Name = name, Name = name,
DataDate = currentYear, DataDate = startDate,
DataEndDate = currentYear.AddYears(1).AddDays(-1), DataEndDate = endDate,
Data = JObject.Parse(data), Data = JObject.Parse(data),
Geometry = JObject.Parse(fieldGeomJson) Geometry = JObject.Parse(fieldGeomJson)
}; };

View File

@ -42,11 +42,12 @@ namespace FarmmapsKPI
KPIInput input; KPIInput input;
string fnKPIinput; string fnKPIinput;
//Console.WriteLine("Type name of input json file. Example: KPIinput.json (in same directory as FarmmapsKPI.exe) or C:/temp/KPIinputChemieTmp.json"); Console.WriteLine("Type name of input json file. Example: KPIinput.json (in same directory as FarmmapsKPI.exe) or C:/temp/KPIinputChemieTmp.json");
//fnKPIinput = Console.ReadLine(); fnKPIinput = Console.ReadLine();
//if (string.IsNullOrEmpty(fnKPIinput)) if (string.IsNullOrEmpty(fnKPIinput))
{
fnKPIinput = "KPIinput.json"; fnKPIinput = "KPIinput.json";
}
var fieldsInputJson = File.ReadAllText(fnKPIinput); var fieldsInputJson = File.ReadAllText(fnKPIinput);
@ -153,7 +154,7 @@ namespace FarmmapsKPI
{ {
_logger.LogInformation($"Creating cropfield with name '{fieldName}'"); _logger.LogInformation($"Creating cropfield with name '{fieldName}'");
cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code, cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code,
$"{fieldName}", cropYear, input.GeometryJson.ToString(Formatting.None), input.DataCropfield.ToString(Formatting.None)); $"{fieldName}", cropYear, input.GeometryJson.ToString(Formatting.None), input.DataCropfield.ToString(Formatting.None), input.StartDate, input.EndDate);
_settings.CropfieldItemCode = cropfieldItem.Code; _settings.CropfieldItemCode = cropfieldItem.Code;
SaveSettings(settingsfile); SaveSettings(settingsfile);
} }

View File

@ -7,6 +7,7 @@ namespace FarmmapsKPI.Models
{ {
public bool UseExistingCropfieldWithChildren { get; set; } public bool UseExistingCropfieldWithChildren { get; set; }
public bool DeleteNewlyCreatedAfterCalc { get; set; } public bool DeleteNewlyCreatedAfterCalc { get; set; }
public string fieldName { get; set; }
public string CropfieldItemCode { get; set; } public string CropfieldItemCode { get; set; }
public JObject DataCropfield { get; set; } public JObject DataCropfield { get; set; }
public string CropRecordingItemCode { get; set; } public string CropRecordingItemCode { get; set; }
@ -17,8 +18,9 @@ namespace FarmmapsKPI.Models
public JObject DataCropfieldCharacteristic { get; set; } public JObject DataCropfieldCharacteristic { get; set; }
public string DownloadFolder { get; set; } public string DownloadFolder { get; set; }
public int CropYear { get; set; } public int CropYear { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public JObject GeometryJson { get; set; } public JObject GeometryJson { get; set; }
public string fieldName { get; set; }
} }
} }