Veranderingen jits, fedde en pepijn. #9

Merged
mark merged 46 commits from jits/FarmMapsApiClient_WURtest:master into master 2021-06-10 08:25:25 +00:00
3 changed files with 122 additions and 143 deletions
Showing only changes of commit 7baf16db74 - Show all commits

View File

@ -345,7 +345,7 @@ namespace FarmmapsApi.Services
} }
public async Task<Item> FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode, string FieldName, bool StoreStatistics) { public async Task<Item> FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode) {
var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, satelliteTaskCode); var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, satelliteTaskCode);
@ -384,11 +384,6 @@ namespace FarmmapsApi.Services
} }
return selectedSatelliteItem; return selectedSatelliteItem;
} }
//VanDerSat //VanDerSat
@ -416,32 +411,6 @@ namespace FarmmapsApi.Services
return itemTask.Code; return itemTask.Code;
} }
public async Task<string> RunWatBalTask(Item cropfieldItem) {
_logger.LogInformation("Gathering WatBal information for cropfield, this might take a while!");
var taskmapRequest = new TaskRequest { TaskType = WATBAL_TASK };
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest);
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => {
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
_logger.LogInformation($"Waiting on VanDerSat data; status: {itemTaskStatus.State}");
if (itemTaskStatus.IsFinished)
tokenSource.Cancel();
});
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
if (itemTask.State == ItemTaskState.Error) {
_logger.LogError($"Something went wrong when trying to process WatBal data; {itemTask.Message}");
}
return itemTask.Code;
}
public async Task<Item> FindVanDerSatItem(Item cropfieldItem, string VanDerSatTaskCode, string FieldName, bool StoreStatistics) { public async Task<Item> FindVanDerSatItem(Item cropfieldItem, string VanDerSatTaskCode, string FieldName, bool StoreStatistics) {
var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, VanDerSatTaskCode); var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, VanDerSatTaskCode);
@ -478,7 +447,6 @@ namespace FarmmapsApi.Services
Console.WriteLine($"{numbervandersat} Van der Sat images found"); Console.WriteLine($"{numbervandersat} Van der Sat images found");
} }
var VanderSatStatistics = item.Data["layers"][0]["renderer"]["band"]["statistics"]; var VanderSatStatistics = item.Data["layers"][0]["renderer"]["band"]["statistics"];
var VanDerSatImageDate = (DateTime)item.DataDate; var VanDerSatImageDate = (DateTime)item.DataDate;
var VanderSatDate = VanDerSatImageDate.ToString("yyyy-MM-dd"); var VanderSatDate = VanDerSatImageDate.ToString("yyyy-MM-dd");
@ -512,6 +480,32 @@ namespace FarmmapsApi.Services
} }
public async Task<string> RunWatBalTask(Item cropfieldItem) {
_logger.LogInformation("Gathering WatBal information for cropfield, this might take a while!");
var taskmapRequest = new TaskRequest { TaskType = WATBAL_TASK };
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest);
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => {
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
_logger.LogInformation($"Waiting on VanDerSat data; status: {itemTaskStatus.State}");
if (itemTaskStatus.IsFinished)
tokenSource.Cancel();
});
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
if (itemTask.State == ItemTaskState.Error) {
_logger.LogError($"Something went wrong when trying to process WatBal data; {itemTask.Message}");
}
return itemTask.Code;
}
public async Task<Item> FindWatBalItem(Item cropfieldItem, string WatBalTaskCode, string FieldName, bool StoreStatistics) { public async Task<Item> FindWatBalItem(Item cropfieldItem, string WatBalTaskCode, string FieldName, bool StoreStatistics) {
@ -519,10 +513,8 @@ namespace FarmmapsApi.Services
// find WatBal data temporal // find WatBal data temporal
var temporalItem = await FindChildItemAsync(cropfieldItem.Code, TEMPORAL_ITEMTYPE, "WatBal");//, item => item.SourceTask == VANDERSAT_TASK && var temporalItem = await FindChildItemAsync(cropfieldItem.Code, TEMPORAL_ITEMTYPE, "Watbal",
// taskStatus.Finished >= item.Created && item => item.SourceTask == WATBAL_TASK && taskStatus.Finished >= item.Created && taskStatus.Finished <= item.Created.Value.AddHours(1));
// taskStatus.Finished <= item.Created.Value.AddHours(1));
if (temporalItem == null) { if (temporalItem == null) {
_logger.LogError("Temporal item not found"); _logger.LogError("Temporal item not found");

View File

@ -120,7 +120,7 @@ namespace FarmmapsNbs
// Select a particular satellite item from satelliteTask // Select a particular satellite item from satelliteTask
Item satalliteItem = await _generalService.FindSatelliteItem(cropfieldItem, _settings.SatelliteTaskCode, FieldName, StoreStatistics); Item satalliteItem = await _generalService.FindSatelliteItem(cropfieldItem, _settings.SatelliteTaskCode);
var satelliteBand = satalliteItem.Data["layers"][0]["name"]; var satelliteBand = satalliteItem.Data["layers"][0]["name"];
var satelliteStatistics = satalliteItem.Data["layers"][0]["renderer"]["band"]["statistics"]; var satelliteStatistics = satalliteItem.Data["layers"][0]["renderer"]["band"]["statistics"];
@ -130,22 +130,19 @@ namespace FarmmapsNbs
//Store data to csv //Store data to csv
if (StoreStatistics == true) if (StoreStatistics == true)
{ {
var SatelliteFile = $"\\Downloads\\DataSatellite_{FieldName}.csv";
var NewLineField = $"\"Field\":{FieldName}" + Environment.NewLine; var SatelliteStatsFile = $"{DownloadFolder}/SatelliteDataStatistics_{FieldName}_{satalliteItem.DataDate.Value:d}.csv";
var NewLineDate = $"\"date\":{satalliteItem.DataDate}" + Environment.NewLine; using var w = new StreamWriter(SatelliteStatsFile);
var i = 0; {
foreach (var item in satelliteStatistics) foreach (var item in satelliteStatistics)
{ {
//var NewLines2; var line = string.Format("{0}", item);
if (i == 0) w.WriteLine(line);
{ w.Flush();
File.AppendAllText(SatelliteFile, NewLineDate); }
i++;
} }
File.AppendAllText(SatelliteFile, $"{item}" + Environment.NewLine);
} }
}
// must be wdvi[1] // must be wdvi[1]
@ -216,22 +213,6 @@ namespace FarmmapsNbs
} }
//// check if vandersat task not yet done, do here and save taskcode
//if (useCreatedCropfield == false || string.IsNullOrEmpty(_settings.VanDerSatTaskCode)) {
// var VanDerSatTaskCode = await _generalService.RunVanDerSatTask(cropfieldItem);
// _settings.VanDerSatTaskCode = VanDerSatTaskCode;
// SaveSettings(settingsfile);
//}
//// Select a particular image item from VanDerSat
//Item VanDerSatItem = await _generalService.FindVanDerSatItem(cropfieldItem, _settings.VanDerSatTaskCode, FieldName, StoreStatistics);
//// download the geotiff
//_logger.LogInformation("Downloading geotiff file");
//await _farmmapsApiService.DownloadItemAsync(VanDerSatItem.Code,
// Path.Combine(DownloadFolder, $"nbs_VanDerSatGeotiff_{input.OutputFileName}.zip"));
_logger.LogInformation($"Calculating targetN with targetYield: {input.TargetYield}"); _logger.LogInformation($"Calculating targetN with targetYield: {input.TargetYield}");
var targetNItem = await _nitrogenService.CreateTargetNItem(cropfieldItem); var targetNItem = await _nitrogenService.CreateTargetNItem(cropfieldItem);
var targetNData = await _nitrogenService.CalculateTargetN(cropfieldItem, targetNItem, plantingDate, var targetNData = await _nitrogenService.CalculateTargetN(cropfieldItem, targetNItem, plantingDate,

View File

@ -1,83 +1,42 @@
[ [
{
"file": "Scan_1_20190605.json",
"inputVariable": "irmi",
"inputLayerName": "",
"outputFileName": "vranbs1",
"plantingDate": "2019-04-18",
"measurementDate": "2019-06-05",
"potatoPurposeType": "consumption",
"targetYield": 45,
"geometryJson": {
"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 ]
]
]
},
"GenerateTaskmap": true,
"OutputType": "shape", // "shape" or "isoxml" if isoxml also add ddiCode
"Precision": "2",
"MaximumClasses": "4",
"DdiCode": "0006",
"CellWidth": "3",
"CellHeight": "10",
"Centered": "true",
"StartPoint": {
"type": "Point",
"coordinates": [ 3.409341600000000, 50.638991900000001 ]
},
"EndPoint": { // if no angle
"type": "Point",
"coordinates": [ 3.411897000000000, 50.638981500000000 ]
}
//"Angle": "317.0" // if no endpoint
},
//{ //{
// "file": "", // keep emptpy to use satellite image // "UseCreatedCropfield": true,
// "inputVariable": "wdvi", // "file": "Scan_1_20190605.json",
// "InputLayerName": "wdvi", // "inputVariable": "irmi",
// "outputFileName": "rtest1", // "inputLayerName": "",
// "plantingDate": "2020-05-01", // "outputFileName": "vranbs1",
// "measurementDate": "2020-06-14", // "fieldName": "testJson_irmi",
// "storeSatelliteStatistics": true,
// "plantingDate": "2019-04-18",
// "measurementDate": "2019-06-05",
// "potatoPurposeType": "consumption", // "potatoPurposeType": "consumption",
// "targetYield": 60, // "targetYield": 45,
// "geometryJson": { // "geometryJson": {
// "type": "Polygon", // "type": "Polygon",
// "coordinates": [ // "coordinates": [
// [ // [
// [ 4.960707146896585, 52.800583669708487 ], // [ 3.40843828875524, 50.638966444680605 ],
// [ 4.960645975538824, 52.800470217610922 ], // [ 3.408953272886064, 50.639197789621612 ],
// [ 4.962140695752897, 52.799177147194797 ], // [ 3.409242951459603, 50.639469958681836 ],
// [ 4.967523821195745, 52.801502400041208 ], // [ 3.409328782148028, 50.639612846807708 ],
// [ 4.966336768950911, 52.802543735879809 ], // [ 3.409457528180712, 50.639789755314411 ],
// [ 4.961711880764330, 52.801009996856429 ], // [ 3.409639918393741, 50.640014292074966 ],
// [ 4.960707146896585, 52.800583669708487 ] // [ 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 ]
// ] // ]
// ] // ]
// }, // },
@ -92,14 +51,61 @@
// "Centered": "true", // "Centered": "true",
// "StartPoint": { // "StartPoint": {
// "type": "Point", // "type": "Point",
// "coordinates": [ 4.960707146896585, 52.800583669708487 ] // "coordinates": [ 3.409341600000000, 50.638991900000001 ]
// }, // },
// "EndPoint": { // if no angle // "EndPoint": { // if no angle
// "type": "Point", // "type": "Point",
// "coordinates": [ 4.961711880764330, 52.801009996856429 ] // "coordinates": [ 3.411897000000000, 50.638981500000000 ]
// } // }
// //"Angle": "317.0" // if no endpoint // //"Angle": "317.0" // if no endpoint
//}
//},
{
"UseCreatedCropfield": true,
"file": "", // keep emptpy to use satellite image
"inputVariable": "wdvi",
"InputLayerName": "wdvi",
"outputFileName": "rtest1",
"fieldName": "test_satelliteWDVI",
"storeSatelliteStatistics": true,
"plantingDate": "2020-05-01",
"measurementDate": "2020-06-14",
"potatoPurposeType": "consumption",
"targetYield": 60,
"geometryJson": {
"type": "Polygon",
"coordinates": [
[
[ 4.960707146896585, 52.800583669708487 ],
[ 4.960645975538824, 52.800470217610922 ],
[ 4.962140695752897, 52.799177147194797 ],
[ 4.967523821195745, 52.801502400041208 ],
[ 4.966336768950911, 52.802543735879809 ],
[ 4.961711880764330, 52.801009996856429 ],
[ 4.960707146896585, 52.800583669708487 ]
]
]
},
"GenerateTaskmap": true,
"OutputType": "shape", // "shape" or "isoxml" if isoxml also add ddiCode
"Precision": "2",
"MaximumClasses": "4",
"DdiCode": "0006",
"CellWidth": "3",
"CellHeight": "10",
"Centered": "true",
"StartPoint": {
"type": "Point",
"coordinates": [ 4.960707146896585, 52.800583669708487 ]
},
"EndPoint": { // if no angle
"type": "Point",
"coordinates": [ 4.961711880764330, 52.801009996856429 ]
}
//"Angle": "317.0" // if no endpoint
}
] ]