From 44cde0fe15650241fe5864a00158e50db6721a98 Mon Sep 17 00:00:00 2001 From: Sijbrandij Date: Thu, 24 Feb 2022 16:32:51 +0100 Subject: [PATCH] added download of all crop recordings of 1 field - using a manual croprecording itemcode --- FarmmapsApi/Constants.cs | 1 + .../DataDownloadApplication.cs | 32 ++++++++++++++++--- FarmmapsDataDownload/DataDownloadInput.json | 14 ++++---- .../Models/DataDownloadInput.cs | 4 +-- FarmmapsNbs/NbsApplication.cs | 1 - FarmmapsNbs/NitrogenInput.json | 4 +-- Secrets/appsettings.json | 22 ++++++------- 7 files changed, 51 insertions(+), 27 deletions(-) diff --git a/FarmmapsApi/Constants.cs b/FarmmapsApi/Constants.cs index 08b271c..1546edb 100644 --- a/FarmmapsApi/Constants.cs +++ b/FarmmapsApi/Constants.cs @@ -12,6 +12,7 @@ namespace FarmmapsApiSamples public const string SHAPE_ITEMTYPE = "vnd.farmmaps.itemtype.shape"; public const string GEOJSON_ITEMTYPE = "vnd.farmmaps.itemtype.geojson"; public const string BLIGHT_ITEMTYPE = "vnd.farmmaps.itemtype.blight"; + public const string CROPREC_ITEMTYPE = "vnd.farmmaps.itemtype.crprec.operation"; public const string VRANBS_TASK = "vnd.farmmaps.task.vranbs"; public const string VRAHERBICIDE_TASK = "vnd.farmmaps.task.vraherbicide"; diff --git a/FarmmapsDataDownload/DataDownloadApplication.cs b/FarmmapsDataDownload/DataDownloadApplication.cs index c0faa10..6fe7831 100644 --- a/FarmmapsDataDownload/DataDownloadApplication.cs +++ b/FarmmapsDataDownload/DataDownloadApplication.cs @@ -112,9 +112,34 @@ namespace FarmmapsDataDownload cropfieldItem = await _farmmapsApiService.GetItemAsync(_settings.CropfieldItemCode); } + //Get croprecordings + if (input.GetCropRecordings) + { + var crprecItem = input.CrprecItem; + //Item cropfieldItem = ; + _logger.LogInformation($"Trying to get crop recordings of croprecording: {crprecItem}"); + + var cropRec = await _farmmapsApiService.GetItemChildrenAsync(crprecItem, CROPREC_ITEMTYPE); + if (cropRec == null) + { + _logger.LogError("Something went wrong while obtaining the croprecordings"); + return; + } + + var cropRecPath = Path.Combine(downloadFolder, $"croprecordings_{crprecItem}.json"); + _logger.LogInformation($"Found {cropRec.Count} crop recordings"); + var count = 0; + TimeSpan.FromSeconds(0.5); + foreach (var item in cropRec) + { + Console.WriteLine($"Crop recording #{count}: {item.Name}"); + File.AppendAllText(cropRecPath, item.Data +Environment.NewLine); + count++; + } + _logger.LogInformation($"Downloaded file {cropRecPath}"); + } // Get shadow data - if (input.GetShadowData) { _logger.LogInformation("Calculate shadow map for field"); @@ -220,10 +245,7 @@ namespace FarmmapsDataDownload } // Select a particular satellite item from satelliteTask - Item vanDerSatItem = await _generalService.FindVanDerSatItem(cropfieldItem, _settings.VanDerSatTaskCode, fieldName, input.StoreVanDerSatStatistics); - - - + Item vanDerSatItem = await _generalService.FindVanDerSatItem(cropfieldItem, _settings.VanDerSatTaskCode, fieldName, input.StoreVanDerSatStatistics); } diff --git a/FarmmapsDataDownload/DataDownloadInput.json b/FarmmapsDataDownload/DataDownloadInput.json index 4081f5b..a675294 100644 --- a/FarmmapsDataDownload/DataDownloadInput.json +++ b/FarmmapsDataDownload/DataDownloadInput.json @@ -1,14 +1,16 @@ [ { "UseCreatedCropfield": true, - "outputFileName": "testSatData2", - "fieldName": "test_satData2", - "DownloadFolder": "C:\\workdir\\groenmonitor\\", //"C:\\workdir\\groenmonitor\\", // "Downloads", -> if you just put "Downloads" the program will download to somewhere in ..\FarmMapsApiClient_WURtest\FarmmapsDataDownload\bin\Debug\netcoreapp3.1\Downloads\ + "outputFileName": "TestData", + "fieldName": "TestField", + "DownloadFolder": "Downloads", //"C:\\workdir\\groenmonitor\\", // "Downloads", -> if you just put "Downloads" the program will download to somewhere in ..\FarmMapsApiClient_WURtest\FarmmapsDataDownload\bin\Debug\netcoreapp3.1\Downloads\ + "GetCropRecordings": true, + "CrprecItem": "...", //item code of de crop recording parrent - can be found by opening the crop recording page of a field. "GetShadowData": false, - "GetSatelliteData": true, + "GetSatelliteData": false, "SatelliteBand": "wdvi", // "natural", "ndvi" or "wdvi" - "StoreSatelliteStatisticsSingleImage": true, - "StoreSatelliteStatisticsCropYear": true, + "StoreSatelliteStatisticsSingleImage": false, + "StoreSatelliteStatisticsCropYear": false, "GetVanDerSatData": false, "StoreVanDerSatStatistics": false, "CropYear": 2020, diff --git a/FarmmapsDataDownload/Models/DataDownloadInput.cs b/FarmmapsDataDownload/Models/DataDownloadInput.cs index 82d8eef..19f1bd1 100644 --- a/FarmmapsDataDownload/Models/DataDownloadInput.cs +++ b/FarmmapsDataDownload/Models/DataDownloadInput.cs @@ -21,8 +21,8 @@ namespace FarmmapsDataDownload.Models public bool StoreSatelliteStatisticsCropYear { get; set; } public bool StoreVanDerSatStatistics { get; set; } public bool GetShadowData { get; set; } - - + public bool GetCropRecordings { get; set; } + public string CrprecItem { get; set; } } } \ No newline at end of file diff --git a/FarmmapsNbs/NbsApplication.cs b/FarmmapsNbs/NbsApplication.cs index 36963f8..87e642c 100644 --- a/FarmmapsNbs/NbsApplication.cs +++ b/FarmmapsNbs/NbsApplication.cs @@ -188,7 +188,6 @@ namespace FarmmapsNbs { ////End shape to geotiff transformation } - _logger.LogInformation($"Calculating targetN with targetYield: {input.TargetYield}"); var targetNItem = await _nitrogenService.CreateTargetNItem(cropfieldItem); var targetNData = await _nitrogenService.CalculateTargetN(cropfieldItem, targetNItem, plantingDate, diff --git a/FarmmapsNbs/NitrogenInput.json b/FarmmapsNbs/NitrogenInput.json index aac8bd5..8793867 100644 --- a/FarmmapsNbs/NitrogenInput.json +++ b/FarmmapsNbs/NitrogenInput.json @@ -1,11 +1,11 @@ [ { - "UseCreatedCropfield": false, + "UseCreatedCropfield": true, "file": "Scan1_20190605_sample.json", "inputVariable": "irmi", "inputLayerName": "irmi", "outputFileName": "vranbs_sample", - "fieldName": "sampleJson_irmi", + "fieldName": "sampleJson_irmi-usertest", "storeSatelliteStatistics": true, "plantingDate": "2019-04-18", "measurementDate": "2019-06-05", diff --git a/Secrets/appsettings.json b/Secrets/appsettings.json index 46059a6..2aff27f 100644 --- a/Secrets/appsettings.json +++ b/Secrets/appsettings.json @@ -2,11 +2,11 @@ //There are three farmmaps environments, uncomment the environemnt you want to use with this sample client //test environment -// "Authority": "https://accounts.test.farmmaps.eu/", -// "Endpoint": "https://test.farmmaps.eu/", -// "BasePath": "api/v1", -// "DiscoveryEndpointUrl": "https://accounts.test.farmmaps.eu/.well-known/openid-configuration", -// "GrantClientId": "farmmapstesteu", + "Authority": "https://accounts.test.farmmaps.eu/", + "Endpoint": "https://test.farmmaps.eu/", + "BasePath": "api/v1", + "DiscoveryEndpointUrl": "https://accounts.test.farmmaps.eu/.well-known/openid-configuration", + "GrantClientId": "farmmapstesteu", ////acceptance environment //"Authority": "https://accounts.acc.farmmaps.eu/", @@ -15,12 +15,12 @@ //"DiscoveryEndpointUrl": "https://accounts.acc.farmmaps.eu/.well-known/openid-configuration", //"GrantClientId": "farmmapsacceu", - //production environment - "authority": "https://accounts.farmmaps.eu/", - "endpoint": "https://farmmaps.eu/", - "basepath": "api/v1", - "discoveryendpointurl": "https://accounts.farmmaps.eu/.well-known/openid-configuration", - "GrantClientId": "farmmaps", + ////production environment + //"authority": "https://accounts.farmmaps.eu/", + //"endpoint": "https://farmmaps.eu/", + //"basepath": "api/v1", + //"discoveryendpointurl": "https://accounts.farmmaps.eu/.well-known/openid-configuration", + //"GrantClientId": "farmmaps", //overige info "RedirectUri": "http://example.nl/api",