From 6debe8208596e97e6f52be3b2f2fa101a3f431e4 Mon Sep 17 00:00:00 2001 From: Sijbrandij Date: Mon, 1 Mar 2021 14:04:18 +0100 Subject: [PATCH 1/2] Updated Blight and Zonering --- FarmMapsBlight/BlightService.cs | 7 +++- FarmMapsBlight/FarmMapsBlight.csproj | 2 +- FarmMapsBlight/Models/Fungicide.cs | 44 ++++++++++++++++++++ FarmMapsBlight/Models/Spray.cs | 3 +- FarmmapsApi/Services/GeneralService.cs | 8 ++-- FarmmapsZonering/Models/ZoneringInput.cs | 2 +- FarmmapsZonering/Services/ZoneringService.cs | 21 ++++++---- FarmmapsZonering/ZoneringApplication.cs | 24 +++++------ 8 files changed, 80 insertions(+), 31 deletions(-) create mode 100644 FarmMapsBlight/Models/Fungicide.cs diff --git a/FarmMapsBlight/BlightService.cs b/FarmMapsBlight/BlightService.cs index 578a134..cead99f 100644 --- a/FarmMapsBlight/BlightService.cs +++ b/FarmMapsBlight/BlightService.cs @@ -36,8 +36,13 @@ namespace FarmMapsBlight taskRequest.attributes["plantingDate"] = plantingDate.ToUniversalTime().ToString("o"); taskRequest.attributes["emergeDate"] = emergeDate.ToUniversalTime().ToString("o"); + var fungicide1 = "{\"ai1\": \"propamocarb\", \"ai2\": \"fluopicolide\", \"ai3\": \"cymoxanil\", \"code\": \"infinito12curz\", \"name\": \"infinito 1,2 l + curzate partner 0,2 kg\", \"maxdose\": \"1\", \"mindose\": \"1\", \"safedays\": \"14\", \"emergence\": true, \"newgrowth\": \"1\", \"contentai1\": \"525.2\", \"contentai2\": \"62.5\", \"contentai3\": \"600\", \"fastgrowth\": true, \"contentunit\": \"l/ha + kg/ha\", \"rainfastness\": \"2.5\", \"tuberfilling\": true, \"aidescription\": \"(propamocarb + fluopicolide) 1.2 l/ha + cymoxanil 0.2 kg/ha\", \"curativescore\": \"2\", \"dryingtimemax\": \"2\", \"dryingtimemin\": \"2\", \"vracompatible\": false, \"maxapplications\": \"4\", \"preventivescore\": \"3\", \"recommendeddose\": \"1\", \"tuberprotection\": \"3.3\", \"eradicativescore\": \"2\", \"earlytubersetting\": true, \"protectioncategory\": \"2\", \"applicationrateunit\": null, \"ctgbregistrationnumber\": \"12927 n + 12755 n\"}"; + var fungicide2 = "{\"ai1\": \"fluazinam\", \"ai2\": \"cymoxanil\", \"ai3\": null, \"code\": \"kunshi\", \"name\": \"kunshi\", \"maxdose\": \"0.5\", \"mindose\": \"0.4\", \"safedays\": \"1\", \"emergence\": false, \"newgrowth\": \"1\", \"contentai1\": \"375\", \"contentai2\": \"250\", \"contentai3\": \"0\", \"fastgrowth\": true, \"contentunit\": \"g/kg\", \"rainfastness\": \"2.5\", \"tuberfilling\": false, \"aidescription\": \"(fluazinam + cymoxanil) 0.5 kg/ha\", \"curativescore\": \"2\", \"dryingtimemax\": \"2\", \"dryingtimemin\": \"1\", \"vracompatible\": true, \"maxapplications\": \"5\", \"preventivescore\": \"2.9\", \"recommendeddose\": \"0.5\", \"tuberprotection\": \"3.3\", \"eradicativescore\": \"1\", \"earlytubersetting\": false, \"protectioncategory\": \"1\", \"applicationrateunit\": \"kg/ha\", \"ctgbregistrationnumber\": \"14371 n\"}"; + List sprays = new List(); - sprays.Add(new Spray() { fungicideCode = "FLEX", SprayTime = new DateTime(2020, 7, 1), dose = 0.6, isVRA = false }); + sprays.Add(new Spray() { fungicide = JsonConvert.DeserializeObject(fungicide1), sprayTime = new DateTime(2020, 6, 24), dose = 0.6, isVRA = false }); + sprays.Add(new Spray() { fungicide = JsonConvert.DeserializeObject(fungicide2), sprayTime = new DateTime(2020, 7, 2), dose = 0.6, isVRA = false }); + //sprays.Add(new Spray() { fungicideCode = "FLEX", SprayTime = new DateTime(2020, 7, 1), dose = 0.6, isVRA = false }); taskRequest.attributes["sprays"] = JsonConvert.SerializeObject(sprays); List irrigations = new List(); diff --git a/FarmMapsBlight/FarmMapsBlight.csproj b/FarmMapsBlight/FarmMapsBlight.csproj index 37ce34b..666c07d 100644 --- a/FarmMapsBlight/FarmMapsBlight.csproj +++ b/FarmMapsBlight/FarmMapsBlight.csproj @@ -11,7 +11,7 @@ - always + >always diff --git a/FarmMapsBlight/Models/Fungicide.cs b/FarmMapsBlight/Models/Fungicide.cs new file mode 100644 index 0000000..1ca71fe --- /dev/null +++ b/FarmMapsBlight/Models/Fungicide.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FarmMapsBlight.Models { + public class Fungicide { + public string code { get; set; } + public string name { get; set; } + public string ctgbregistrationnumber { get; set; } + public string ai1 { get; set; } + public string ai2 { get; set; } + public string ai3 { get; set; } + public double contentai1 { get; set; } + public double contentai2 { get; set; } + public double contentai3 { get; set; } + public string contentunit { get; set; } + public string aidescription { get; set; } + public int protectioncategory { get; set; } + public double preventivescore { get; set; } + public double curativescore { get; set; } + public string applicationrateunit { get; set; } + public double recommendeddose { get; set; } + public double newgrowth { get; set; } + public double tuberprotection { get; set; } + public double dryingtimemin { get; set; } + public double dryingtimemax { get; set; } + public double rainfastness { get; set; } + public double mindose { get; set; } + public double maxdose { get; set; } + public int? maxapplications { get; set; } + public bool vracompatible { get; set; } + public double eradicativescore { get; set; } + public bool emergence { get; set; } + public bool fastgrowth { get; set; } + public bool earlytubersetting { get; set; } + public bool tuberfilling { get; set; } + public int? safedays { get; set; } + public double takeback { + get { + return curativescore * 6; + } + } + } +} \ No newline at end of file diff --git a/FarmMapsBlight/Models/Spray.cs b/FarmMapsBlight/Models/Spray.cs index f0d2f29..206b849 100644 --- a/FarmMapsBlight/Models/Spray.cs +++ b/FarmMapsBlight/Models/Spray.cs @@ -4,8 +4,9 @@ namespace FarmMapsBlight.Models { public class Spray { - public DateTime SprayTime { get; set; } + public DateTime sprayTime { get; set; } public string fungicideCode { get; set; } + public Fungicide fungicide { get; set; } public double dose { get; set; } public bool isVRA { get; set; } } diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index 6bb9c76..728ed78 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -38,7 +38,7 @@ namespace FarmmapsApi.Services } public async Task UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName) { - var startUpload = DateTime.UtcNow; + var startUpload = DateTime.UtcNow.AddSeconds(-3); var result = await _farmmapsApiService.UploadFile(filePath, root.Code, progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); @@ -90,9 +90,9 @@ namespace FarmmapsApi.Services return null; } - //the taskmap is a child of the input tiff + //the taskmap is a child of the input tiff *** Update feb 2021: it is a child of the cropfield. var itemName = "Taskmap"; - var taskMapItem = await FindChildItemAsync(tiffItem.Code, + var taskMapItem = await FindChildItemAsync(tiffItem.ParentCode, SHAPE_PROCESSED_ITEMTYPE, itemName); if (taskMapItem == null) { _logger.LogError("Could not find the shape taskmap as a child item under the input"); @@ -131,8 +131,6 @@ namespace FarmmapsApi.Services await PollTask(TimeSpan.FromSeconds(3), async source => { _logger.LogInformation($"Trying to get {containsName} data"); var uploadedFilesChildren = await _farmmapsApiService.GetItemChildrenAsync(parentCode, itemType); - - Func func = filter ?? (i => i.Name.ToLower().Contains(containsName.ToLower())); dataItem = uploadedFilesChildren.FirstOrDefault(func); if (dataItem != null || tries == maxTries) { diff --git a/FarmmapsZonering/Models/ZoneringInput.cs b/FarmmapsZonering/Models/ZoneringInput.cs index 5856ef7..ceed93c 100644 --- a/FarmmapsZonering/Models/ZoneringInput.cs +++ b/FarmmapsZonering/Models/ZoneringInput.cs @@ -10,7 +10,7 @@ namespace FarmmapsZonering.Models public string Formula { get; set; } public string OutputFileName { get; set; } public string CropFieldName { get; set; } - public string LayerName { get; set; } + public string CalculatedLayerName { get; set; } public string CalculatedQuantity { get; set; } public string CalculatedUnit { get; set; } public bool CreateNewCropfield { get; set; } diff --git a/FarmmapsZonering/Services/ZoneringService.cs b/FarmmapsZonering/Services/ZoneringService.cs index d379122..ce1cfd3 100644 --- a/FarmmapsZonering/Services/ZoneringService.cs +++ b/FarmmapsZonering/Services/ZoneringService.cs @@ -48,14 +48,19 @@ namespace FarmmapsZonering.Services _logger.LogError($"Something went wrong with task execution: {itemTask.Message}"); return null; } - - var itemName = $"VRAZonering"; - var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code, - GEOTIFF_PROCESSED_ITEMTYPE, itemName, - //i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) && - // i.Name.ToLower().Contains(itemName.ToLower())); - i => - i.Name.ToLower().Contains(itemName.ToLower())); + + var uploadedFilesChildren = await _farmmapsApiService.GetItemChildrenAsync(cropfieldItem.Code); + //int last = uploadedFilesChildren.Count - 1; + //var applianceMapItem = uploadedFilesChildren[last]; + + + var itemName = output.Name; + //var itemName = $"VRAZonering"; + var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code, + GEOTIFF_PROCESSED_ITEMTYPE, itemName, + i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) && + i.Name.ToLower().Contains(itemName.ToLower())); + if (applianceMapItem == null) { _logger.LogError("Could not find the VRAZonering geotiff child item under cropfield"); diff --git a/FarmmapsZonering/ZoneringApplication.cs b/FarmmapsZonering/ZoneringApplication.cs index d53fd46..2519944 100644 --- a/FarmmapsZonering/ZoneringApplication.cs +++ b/FarmmapsZonering/ZoneringApplication.cs @@ -73,7 +73,7 @@ namespace FarmmapsZonering return; } - bool useCreatedCropfield = true; + bool useCreatedCropfield = false; bool GetWatBal = input.GetWatBal; bool getVanDerSat = input.GetVanDerSat; bool StoreVanDerSatStatistics = input.storeVanDerSatStatistics; @@ -102,11 +102,6 @@ namespace FarmmapsZonering _settings.CropfieldName = cropfieldItem.Name; _settings.CropfieldItemCode = cropfieldItem.Code; SaveSettings(settingsfile); - - cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, "Cropfield VRA Zonering", 2020, - @"{ ""type"": ""Polygon"", ""coordinates"": [ [ [ 5.670991253771027, 52.796788997702613 ], [ 5.671526456638633, 52.797291618546666 ], [ 5.671275936147413, 52.797422436717852 ], [ 5.671959173850738, 52.798269302728798 ], [ 5.670649634919365, 52.798778791408822 ], [ 5.671503682048522, 52.799591206957416 ], [ 5.675159003761311, 52.798193567415474 ], [ 5.673029579585948, 52.796024727480535 ], [ 5.670991253771027, 52.796788997702613 ] ] ] }"); - _settings.CropfieldItemCode = cropfieldItem.Code; - SaveSettings(settingsfile); } else { @@ -163,7 +158,7 @@ namespace FarmmapsZonering var outputItem = await _zoneringService.CreateApplicationMapAsync(cropfieldItem, input.Formula, new Output() { - Name = input.LayerName, + Name = input.CalculatedLayerName, Quantity = input.CalculatedQuantity, Unit = input.CalculatedUnit, @@ -175,17 +170,18 @@ namespace FarmmapsZonering }, new InputParameter() { - ItemCode = inputOneItem.Code, - LayerName = inputOneItem.Data["layers"][0]["name"].ToString() + ItemCode = inputTwoItem.Code, + LayerName = inputTwoItem.Data["layers"][0]["name"].ToString() }); - _logger.LogInformation("Downloading output"); - - - + _logger.LogInformation("Downloading output"); + _logger.LogInformation($"outputitem: {outputItem} with code {outputItem.Code} and date {outputItem.DataDate}"); + //_logger.LogInformation($"Data: {outputItem.Data}"); + await _farmmapsApiService.DownloadItemAsync(outputItem.Code, - Path.Combine(DownloadFolder, $"{input.OutputFileName}.zip")); + Path.Combine(DownloadFolder, $"{input.OutputFileName}.zoning.zip")); + } // Functions to save previously created cropfields From cf5ac33b3fa24968aeb1c93cc3a7b6d5336d4055 Mon Sep 17 00:00:00 2001 From: Sijbrandij Date: Mon, 1 Mar 2021 14:33:29 +0100 Subject: [PATCH 2/2] added updaten zoning input --- FarmmapsZonering/ZoneringInput.json | 61 ++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/FarmmapsZonering/ZoneringInput.json b/FarmmapsZonering/ZoneringInput.json index dc23cc3..705c5a7 100644 --- a/FarmmapsZonering/ZoneringInput.json +++ b/FarmmapsZonering/ZoneringInput.json @@ -1,4 +1,4 @@ -[ +//[ //Formule kan meerdere inputs aan // Met blokhaken en een nummer specificeer je een input: @@ -39,33 +39,64 @@ // ] // }, +[ + + //{ + // "InputItemOne": "20210127_L2A_B08_(Raw).tiff", + // "InputItemTwo": "20210127_L2A_B04_(Raw).tiff", + // "Formula": "([0]-[1])/([0]+[1])+0.3", + // "CalculatedLayerName": "Biomassa", + // "CalculatedQuantity": "NDVI", + // "CalculatedUnit": "wdviValue", + // "OutputFileName": "20210212_NDVI-test", + // "CropFieldName": "Mahindra-Hapreet_Singh-2", + // "UseShadow": false, + // "GetWatBal": false, + // "GetVanDerSat": false, + // "storeVanDerSatStatistics": false, + // "CropYear": 2020, + // "geometryJson": { + // "type": "Polygon", + // "coordinates": [ + // [ + // [ 31.63887936537028, 75.92907261717566 ], + // [ 31.63895684173582, 75.93143281072912 ], + // [ 31.63940906549488, 75.93135348937818 ], + // [ 31.63931497834855, 75.9290907801773 ], + // [ 31.63887936537028, 75.92907261717566 ] + // ] + // ] + + // } + //} + { - "InputItemOne": "data_9001.tif", - "InputItemTwo": "data_times_two_4326.tiff", - "Formula": "if [0] >= 1.28 then [1] else 0", - "CreatedLayerName": "Biomassa", + "InputItemOne": "2020-04-22_sentinel-2_l2a_b08.tiff", + "InputItemTwo": "2020-04-22_sentinel-2_l2a_b04.tiff", + "Formula": "([0]-[1])/([0]+[1])", + "CalculatedLayerName": "Biomassa", "CalculatedQuantity": "NDVI", "CalculatedUnit": "ndviValue", - "OutputFileName": "Zoning", - "CropFieldName": "Data_whole", + "OutputFileName": "20210212_NDVI-test_FS", + "CropFieldName": "MestSiloAduard", "UseShadow": false, "GetWatBal": false, - "GetVanDerSat": true, - "storeVanDerSatStatistics": true, + "GetVanDerSat": false, + "storeVanDerSatStatistics": false, "CropYear": 2020, "geometryJson": { "type": "Polygon", "coordinates": [ [ - [ 5.66886041703652044, 52.52929999060298627 ], - [ 5.6716230923214912, 52.52946316399909676 ], - [ 5.67185376229668581, 52.5280565894154563 ], - [ 5.66903207841337231, 52.52790646510525363 ], - [ 5.66886041703652044, 52.52929999060298627 ] + [ 6.48274677, 53.25861525 ], + [ 6.48740108, 53.25799841 ], + [ 6.48756130, 53.25934424 ], + [ 6.48285892, 53.25953650 ], + [ 6.48274677, 53.25861525 ] ] ] } } - + ]