NBSTask operations now take plantingDate and measurementDate as input.
This commit is contained in:
parent
5f854ec820
commit
dfb8a05d11
@ -27,6 +27,13 @@ namespace FarmmapsApiSamples
|
|||||||
|
|
||||||
public async Task TestFlow(List<UserRoot> roots)
|
public async Task TestFlow(List<UserRoot> roots)
|
||||||
{
|
{
|
||||||
|
var downloadFolder = "Downloads";
|
||||||
|
if (!Directory.Exists(downloadFolder))
|
||||||
|
Directory.CreateDirectory(downloadFolder);
|
||||||
|
|
||||||
|
var plantingDate = new DateTime(DateTime.UtcNow.Year, 2, 1);
|
||||||
|
var measurementDate = plantingDate.AddMonths(5);
|
||||||
|
|
||||||
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
|
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
|
||||||
if (uploadedRoot == null)
|
if (uploadedRoot == null)
|
||||||
{
|
{
|
||||||
@ -56,22 +63,22 @@ namespace FarmmapsApiSamples
|
|||||||
var isariaGeotiffItem = await ProcessIsaria(uploadedRoot.Code,"Scan_1_20190605.zip");
|
var isariaGeotiffItem = await ProcessIsaria(uploadedRoot.Code,"Scan_1_20190605.zip");
|
||||||
|
|
||||||
_logger.LogInformation($"Calculating targetN with targetYield: {60}");
|
_logger.LogInformation($"Calculating targetN with targetYield: {60}");
|
||||||
var targetN = await CalculateTargetN(cropfieldItem, 60);
|
var targetN = await CalculateTargetN(cropfieldItem, plantingDate, measurementDate, 60);
|
||||||
_logger.LogInformation($"TargetN: {targetN}");
|
_logger.LogInformation($"TargetN: {targetN}");
|
||||||
|
|
||||||
_logger.LogInformation("Calculating uptake map");
|
_logger.LogInformation("Calculating uptake map");
|
||||||
var uptakeMapItem =
|
var uptakeMapItem =
|
||||||
await CalculateUptakeMap(cropfieldItem, isariaGeotiffItem);
|
await CalculateUptakeMap(cropfieldItem, isariaGeotiffItem, plantingDate, measurementDate);
|
||||||
|
|
||||||
_logger.LogInformation("Downloading uptake map");
|
_logger.LogInformation("Downloading uptake map");
|
||||||
await _farmmapsApiService.DownloadItemAsync(uptakeMapItem.Code, $"{uptakeMapItem.Name}.zip");
|
await _farmmapsApiService.DownloadItemAsync(uptakeMapItem.Code, Path.Combine(downloadFolder, $"{uptakeMapItem.Name}.zip"));
|
||||||
|
|
||||||
_logger.LogInformation("Calculating appliance map");
|
_logger.LogInformation("Calculating appliance map");
|
||||||
var applianceMapItem =
|
var applianceMapItem =
|
||||||
await CalculateApplianceMap(cropfieldItem, isariaGeotiffItem, targetN);
|
await CalculateApplianceMap(cropfieldItem, isariaGeotiffItem, plantingDate, measurementDate, targetN);
|
||||||
|
|
||||||
_logger.LogInformation("Downloading appliance map");
|
_logger.LogInformation("Downloading appliance map");
|
||||||
await _farmmapsApiService.DownloadItemAsync(applianceMapItem.Code, $"{applianceMapItem.Name}.zip");
|
await _farmmapsApiService.DownloadItemAsync(applianceMapItem.Code, Path.Combine(downloadFolder, $"{applianceMapItem.Name}.zip"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Item> GetOrCreateCropfieldItemAsync(string parentItemCode)
|
private async Task<Item> GetOrCreateCropfieldItemAsync(string parentItemCode)
|
||||||
@ -89,9 +96,8 @@ namespace FarmmapsApiSamples
|
|||||||
ItemType = CROPFIELD_ITEMTYPE,
|
ItemType = CROPFIELD_ITEMTYPE,
|
||||||
Name = "Cropfield for VRA",
|
Name = "Cropfield for VRA",
|
||||||
DataDate = currentYear,
|
DataDate = currentYear,
|
||||||
DataEndDate = currentYear.AddYears(1),
|
DataEndDate = currentYear.AddYears(1).AddDays(-1),
|
||||||
Data = JObject.FromObject(new
|
Data = JObject.Parse("{}"),
|
||||||
{startDate = currentYear, endDate = currentYear.AddMonths(3)}),
|
|
||||||
Geometry = JObject.Parse(
|
Geometry = JObject.Parse(
|
||||||
@"{ ""type"": ""Polygon"", ""coordinates"": [ [ [ 3.40843828875524, 50.638966444680605 ], [ 3.408953272886064, 50.639197789621612 ], [ 3.409242951459603, 50.639469958681836 ], [ 3.409328782148028, 50.639612846807708 ], [ 3.409457528180712, 50.639789755314411 ], [ 3.409639918393741, 50.640014292074966 ], [ 3.409833037442765, 50.640211611372706 ], [ 3.410069071836049, 50.640395321698435 ], [ 3.410380208081761, 50.640572227259661 ], [ 3.410605513638958, 50.640715112034222 ], [ 3.411925160474145, 50.641177783561204 ], [ 3.411935889310142, 50.640728720085136 ], [ 3.412590348309737, 50.63948356709389 ], [ 3.413244807309242, 50.638224772339846 ], [ 3.413400375432099, 50.637901562841307 ], [ 3.413539850300779, 50.637449065809889 ], [ 3.413475477284437, 50.637418445552932 ], [ 3.40999396998362, 50.637449065810451 ], [ 3.409940325803365, 50.638102293212661 ], [ 3.409575545377398, 50.638483338338325 ], [ 3.409060561246574, 50.638707881340494 ], [ 3.40843828875524, 50.638966444680605 ] ] ] }")
|
@"{ ""type"": ""Polygon"", ""coordinates"": [ [ [ 3.40843828875524, 50.638966444680605 ], [ 3.408953272886064, 50.639197789621612 ], [ 3.409242951459603, 50.639469958681836 ], [ 3.409328782148028, 50.639612846807708 ], [ 3.409457528180712, 50.639789755314411 ], [ 3.409639918393741, 50.640014292074966 ], [ 3.409833037442765, 50.640211611372706 ], [ 3.410069071836049, 50.640395321698435 ], [ 3.410380208081761, 50.640572227259661 ], [ 3.410605513638958, 50.640715112034222 ], [ 3.411925160474145, 50.641177783561204 ], [ 3.411935889310142, 50.640728720085136 ], [ 3.412590348309737, 50.63948356709389 ], [ 3.413244807309242, 50.638224772339846 ], [ 3.413400375432099, 50.637901562841307 ], [ 3.413539850300779, 50.637449065809889 ], [ 3.413475477284437, 50.637418445552932 ], [ 3.40999396998362, 50.637449065810451 ], [ 3.409940325803365, 50.638102293212661 ], [ 3.409575545377398, 50.638483338338325 ], [ 3.409060561246574, 50.638707881340494 ], [ 3.40843828875524, 50.638966444680605 ] ] ] }")
|
||||||
};
|
};
|
||||||
@ -161,8 +167,11 @@ namespace FarmmapsApiSamples
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cropfieldItem">The cropfield to base the calculations on</param>
|
/// <param name="cropfieldItem">The cropfield to base the calculations on</param>
|
||||||
/// <param name="targetYield">The target yield input for the TargetN calculation</param>
|
/// <param name="targetYield">The target yield input for the TargetN calculation</param>
|
||||||
|
/// <param name="plantingDate">The date the crop is planted</param>
|
||||||
|
/// <param name="measurementDate">The date the measurements are taken</param>
|
||||||
/// <returns>The TargetN</returns>
|
/// <returns>The TargetN</returns>
|
||||||
public async Task<double> CalculateTargetN(Item cropfieldItem, int targetYield)
|
public async Task<double> CalculateTargetN(Item cropfieldItem, DateTime plantingDate,
|
||||||
|
DateTime measurementDate, int targetYield)
|
||||||
{
|
{
|
||||||
var targetNItems = await
|
var targetNItems = await
|
||||||
_farmmapsApiService.GetItemChildrenAsync(cropfieldItem.ParentCode, USERINPUT_ITEMTYPE);
|
_farmmapsApiService.GetItemChildrenAsync(cropfieldItem.ParentCode, USERINPUT_ITEMTYPE);
|
||||||
@ -182,6 +191,8 @@ namespace FarmmapsApiSamples
|
|||||||
var nbsTargetNRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
var nbsTargetNRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
||||||
nbsTargetNRequest.attributes["operation"] = "targetn";
|
nbsTargetNRequest.attributes["operation"] = "targetn";
|
||||||
nbsTargetNRequest.attributes["inputCode"] = targetNItem.Code;
|
nbsTargetNRequest.attributes["inputCode"] = targetNItem.Code;
|
||||||
|
nbsTargetNRequest.attributes["plantingDate"] = plantingDate.ToString();
|
||||||
|
nbsTargetNRequest.attributes["measurementDate"] = measurementDate.ToString();
|
||||||
nbsTargetNRequest.attributes["inputType"] = "irmi";
|
nbsTargetNRequest.attributes["inputType"] = "irmi";
|
||||||
nbsTargetNRequest.attributes["purposeType"] = "consumption";
|
nbsTargetNRequest.attributes["purposeType"] = "consumption";
|
||||||
nbsTargetNRequest.attributes["targetYield"] = targetYield.ToString();
|
nbsTargetNRequest.attributes["targetYield"] = targetYield.ToString();
|
||||||
@ -208,14 +219,25 @@ namespace FarmmapsApiSamples
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Item> CalculateUptakeMap(Item cropfieldItem, Item inputItem)
|
/// <summary>
|
||||||
|
/// Calculates the uptake map based on the given inputs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cropfieldItem">The cropfield to base the calculations on</param>
|
||||||
|
/// <param name="inputItem"></param>
|
||||||
|
/// <param name="plantingDate">The date the crop is planted</param>
|
||||||
|
/// <param name="measurementDate">The date the measurements are taken</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<Item> CalculateUptakeMap(Item cropfieldItem, Item inputItem, DateTime plantingDate,
|
||||||
|
DateTime measurementDate)
|
||||||
{
|
{
|
||||||
var nbsApplianceMapRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
var nbsUptakeMapRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
||||||
nbsApplianceMapRequest.attributes["operation"] = "uptake";
|
nbsUptakeMapRequest.attributes["operation"] = "uptake";
|
||||||
nbsApplianceMapRequest.attributes["inputCode"] = inputItem.Code;
|
nbsUptakeMapRequest.attributes["inputCode"] = inputItem.Code;
|
||||||
nbsApplianceMapRequest.attributes["inputType"] = "irmi";
|
nbsUptakeMapRequest.attributes["plantingDate"] = plantingDate.ToString();
|
||||||
|
nbsUptakeMapRequest.attributes["measurementDate"] = measurementDate.ToString();
|
||||||
|
nbsUptakeMapRequest.attributes["inputType"] = "irmi";
|
||||||
|
|
||||||
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsApplianceMapRequest);
|
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsUptakeMapRequest);
|
||||||
|
|
||||||
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
|
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
|
||||||
{
|
{
|
||||||
@ -248,15 +270,28 @@ namespace FarmmapsApiSamples
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<Item> CalculateApplianceMap(Item cropfieldItem, Item inputItem, double targetN)
|
/// <summary>
|
||||||
|
/// Creates the nitrogen appliance map based on given input data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cropfieldItem">The cropfield to base the calculations on</param>
|
||||||
|
/// <param name="inputItem">The farmmaps item containing the geotiff data</param>
|
||||||
|
/// <param name="plantingDate">The date the crop is planted</param>
|
||||||
|
/// <param name="measurementDate">The date the measurements are taken</param>
|
||||||
|
/// <param name="targetN">The target nitrogen to use for the calculations</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<Item> CalculateApplianceMap(Item cropfieldItem, Item inputItem, DateTime plantingDate,
|
||||||
|
DateTime measurementDate, double targetN)
|
||||||
{
|
{
|
||||||
var applianceMapRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
var nbsApplianceMapRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
||||||
applianceMapRequest.attributes["operation"] = "nitrogen";
|
nbsApplianceMapRequest.attributes["operation"] = "nitrogen";
|
||||||
applianceMapRequest.attributes["inputCode"] = inputItem.Code;
|
nbsApplianceMapRequest.attributes["inputCode"] = inputItem.Code;
|
||||||
applianceMapRequest.attributes["inputType"] = "irmi";
|
nbsApplianceMapRequest.attributes["plantingDate"] = plantingDate.ToString();
|
||||||
applianceMapRequest.attributes["targetN"] = targetN.ToString(CultureInfo.InvariantCulture);
|
nbsApplianceMapRequest.attributes["measurementDate"] = measurementDate.ToString();
|
||||||
|
nbsApplianceMapRequest.attributes["inputCode"] = inputItem.Code;
|
||||||
|
nbsApplianceMapRequest.attributes["inputType"] = "irmi";
|
||||||
|
nbsApplianceMapRequest.attributes["targetN"] = targetN.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, applianceMapRequest);
|
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsApplianceMapRequest);
|
||||||
|
|
||||||
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
|
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
|
||||||
{
|
{
|
||||||
@ -275,7 +310,7 @@ namespace FarmmapsApiSamples
|
|||||||
var geotiffItems = await
|
var geotiffItems = await
|
||||||
_farmmapsApiService.GetItemChildrenAsync(cropfieldItem.Code, GEOTIFF_PROCESSED_ITEMTYPE);
|
_farmmapsApiService.GetItemChildrenAsync(cropfieldItem.Code, GEOTIFF_PROCESSED_ITEMTYPE);
|
||||||
|
|
||||||
// maybe poll here to, to wait for geotiff task process to be finished?
|
// maybe poll here too, to wait for geotiff task process to be finished?
|
||||||
|
|
||||||
// how to uniquely know which item is really created!?
|
// how to uniquely know which item is really created!?
|
||||||
var applianceMapItem = geotiffItems.SingleOrDefault(i => i.Name.Contains("nitrogen") && i.Updated >= itemTask.Finished);
|
var applianceMapItem = geotiffItems.SingleOrDefault(i => i.Name.Contains("nitrogen") && i.Updated >= itemTask.Finished);
|
||||||
@ -294,8 +329,7 @@ namespace FarmmapsApiSamples
|
|||||||
{
|
{
|
||||||
ParentCode = parentItemCode,
|
ParentCode = parentItemCode,
|
||||||
ItemType = USERINPUT_ITEMTYPE,
|
ItemType = USERINPUT_ITEMTYPE,
|
||||||
Name = "TargetN",
|
Name = "TargetN"
|
||||||
DataDate = DateTime.UtcNow
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user