forked from FarmMaps/FarmMapsApiClient
Compare commits
2 Commits
master
...
feature/ha
Author | SHA1 | Date | |
---|---|---|---|
594c1507c3 | |||
027cdfe722 |
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
#
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmmapsNbs", "FarmmapsNbs\FarmmapsNbs.csproj", "{E08EF7E9-F09E-42D8-825C-164E458C78F4}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmmapsNbs", "FarmmapsNbs\FarmmapsNbs.csproj", "{E08EF7E9-F09E-42D8-825C-164E458C78F4}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmmapsApi", "FarmmapsApi\FarmmapsApi.csproj", "{1FA9E50B-F45E-4534-953A-37C783D03C74}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmmapsApi", "FarmmapsApi\FarmmapsApi.csproj", "{1FA9E50B-F45E-4534-953A-37C783D03C74}"
|
||||||
@ -12,6 +13,8 @@ EndProjectSection
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmmapsHerbicide", "FarmmapsHerbicide\FarmmapsHerbicide.csproj", "{731A88CD-9DC4-4969-86F2-2315830A6998}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmmapsHerbicide", "FarmmapsHerbicide\FarmmapsHerbicide.csproj", "{731A88CD-9DC4-4969-86F2-2315830A6998}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmmapsHaulmkilling", "FarmmapsHaulmkilling\FarmmapsHaulmkilling.csproj", "{DFA89D0B-5400-4374-B824-8367B76B4B6E}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -30,5 +33,9 @@ Global
|
|||||||
{731A88CD-9DC4-4969-86F2-2315830A6998}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{731A88CD-9DC4-4969-86F2-2315830A6998}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{731A88CD-9DC4-4969-86F2-2315830A6998}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{731A88CD-9DC4-4969-86F2-2315830A6998}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{731A88CD-9DC4-4969-86F2-2315830A6998}.Release|Any CPU.Build.0 = Release|Any CPU
|
{731A88CD-9DC4-4969-86F2-2315830A6998}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DFA89D0B-5400-4374-B824-8367B76B4B6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DFA89D0B-5400-4374-B824-8367B76B4B6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DFA89D0B-5400-4374-B824-8367B76B4B6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DFA89D0B-5400-4374-B824-8367B76B4B6E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
20
FarmmapsHaulmkilling/FarmmapsHaulmkilling.csproj
Normal file
20
FarmmapsHaulmkilling/FarmmapsHaulmkilling.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Data\**\*">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FarmmapsApi\FarmmapsApi.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
69
FarmmapsHaulmkilling/HaulmkillingApplication.cs
Normal file
69
FarmmapsHaulmkilling/HaulmkillingApplication.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FarmmapsApi;
|
||||||
|
using FarmmapsApi.Services;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FarmmapsHaulmkilling
|
||||||
|
{
|
||||||
|
public class HaulmkillingApplication : IApplication
|
||||||
|
{
|
||||||
|
private const string DownloadFolder = "Downloads";
|
||||||
|
|
||||||
|
private readonly ILogger<HaulmkillingApplication> _logger;
|
||||||
|
private readonly FarmmapsApiService _farmmapsApiService;
|
||||||
|
private readonly HaulmkillingService _haulmkillingService;
|
||||||
|
private readonly GeneralService _generalService;
|
||||||
|
|
||||||
|
public HaulmkillingApplication(ILogger<HaulmkillingApplication> logger, FarmmapsApiService farmmapsApiService,
|
||||||
|
GeneralService generalService, HaulmkillingService haulmkillingService)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_farmmapsApiService = farmmapsApiService;
|
||||||
|
_generalService = generalService;
|
||||||
|
_haulmkillingService = haulmkillingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RunAsync()
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(DownloadFolder))
|
||||||
|
Directory.CreateDirectory(DownloadFolder);
|
||||||
|
|
||||||
|
// !! this call is needed the first time an api is called with a fresh clientid and secret !!
|
||||||
|
await _farmmapsApiService.GetCurrentUserCodeAsync();
|
||||||
|
var roots = await _farmmapsApiService.GetCurrentUserRootsAsync();
|
||||||
|
|
||||||
|
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
|
||||||
|
if (myDrive == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Could not find a needed root item");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
|
||||||
|
if (uploadedRoot == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Could not find a needed root item");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var agents = await _haulmkillingService.GetHaulmkillingAgents();
|
||||||
|
if (agents == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("No valid agents found for haulmkilling");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// save cropfield item and check if already exists and created (this to not have to run satellite everytime)
|
||||||
|
_logger.LogInformation("Creating cropfield");
|
||||||
|
var cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, "Cropfield VRA Haulmkilling", 2020,
|
||||||
|
@"{""type"":""Polygon"",""coordinates"":[[[4.617786844284247,52.22533706956424],[4.618642601314543,52.225938364585989],[4.6192153806397,52.22563988897754],[4.619192414656403,52.2256242822442],[4.620306732153958,52.225031745661528],[4.620542019225217,52.22519855319158],[4.621157509147853,52.22487436515405],[4.623387917230182,52.22367660757213],[4.624563444939009,52.22304740241544],[4.624562779355982,52.223046635247019],[4.624534908813479,52.22302596787506],[4.627873021330343,52.221240670658399],[4.627504935938338,52.220104419135129],[4.627324878706837,52.22020569669098],[4.627320696113512,52.22020660117888],[4.626707169518044,52.22053923770041],[4.624700376420229,52.221619047547488],[4.623471571183885,52.22227447969577],[4.623471511010673,52.22227500174403],[4.623468838689317,52.22228052566992],[4.617786844284247,52.22533706956424]]]}");
|
||||||
|
|
||||||
|
// run satellite task on just added cropfield
|
||||||
|
|
||||||
|
|
||||||
|
// find ndvi or wdvi satellite data geotiffs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
FarmmapsHaulmkilling/HaulmkillingService.cs
Normal file
36
FarmmapsHaulmkilling/HaulmkillingService.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FarmmapsApi.Services;
|
||||||
|
using FarmmapsHaulmkilling.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FarmmapsHaulmkilling
|
||||||
|
{
|
||||||
|
public class HaulmkillingService
|
||||||
|
{
|
||||||
|
private readonly ILogger<HaulmkillingService> _logger;
|
||||||
|
private readonly FarmmapsApiService _farmmapsApiService;
|
||||||
|
private readonly GeneralService _generalService;
|
||||||
|
|
||||||
|
public HaulmkillingService(ILogger<HaulmkillingService> logger, FarmmapsApiService farmmapsApiService,
|
||||||
|
GeneralService generalService)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_farmmapsApiService = farmmapsApiService;
|
||||||
|
_generalService = generalService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<HaulmkillingAgent>> GetHaulmkillingAgents()
|
||||||
|
{
|
||||||
|
var itemType = "vnd.farmmaps.package.vra.haulmkilling";
|
||||||
|
var vraHerbicideDataItems = await _farmmapsApiService.GetItemsAsync(string.Empty, itemType);
|
||||||
|
|
||||||
|
var item = vraHerbicideDataItems.FirstOrDefault();
|
||||||
|
if (item == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return item.Data.ContainsKey("agents") ? item.Data["agents"].ToObject<List<HaulmkillingAgent>>() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs
Normal file
30
FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace FarmmapsHaulmkilling.Models
|
||||||
|
{
|
||||||
|
public class HaulmkillingAgent
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public List<string> SupportedOptions { get; set; }
|
||||||
|
public Dictionary<string, List<HaulmkillingAgentValue>> Values { get; set; }
|
||||||
|
|
||||||
|
public HaulmkillingAgentValue? GetAgentValue(string inputName, string optionKey)
|
||||||
|
{
|
||||||
|
if (!Values.ContainsKey(inputName))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var agentDataValues = Values[inputName];
|
||||||
|
return agentDataValues.FirstOrDefault(v => v.Option.Equals(optionKey));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct HaulmkillingAgentValue
|
||||||
|
{
|
||||||
|
public string Option { get; set; }
|
||||||
|
public float Min { get; set; }
|
||||||
|
public float Max { get; set; }
|
||||||
|
public float FMul { get; set; }
|
||||||
|
public float FExp { get; set; }
|
||||||
|
}
|
||||||
|
}
|
23
FarmmapsHaulmkilling/Program.cs
Normal file
23
FarmmapsHaulmkilling/Program.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using FarmmapsApi;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FarmmapsHaulmkilling
|
||||||
|
{
|
||||||
|
class Program : FarmmapsProgram<HaulmkillingApplication>
|
||||||
|
{
|
||||||
|
private static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
await new Program().Start(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Configure(IServiceCollection serviceCollection)
|
||||||
|
{
|
||||||
|
serviceCollection.AddLogging(opts => opts
|
||||||
|
.AddConsole()
|
||||||
|
.AddFilter("System.Net.Http", LogLevel.Warning))
|
||||||
|
.AddTransient<HaulmkillingService>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
FarmmapsHaulmkilling/appsettings.json
Normal file
10
FarmmapsHaulmkilling/appsettings.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"Authority": "https://accounts.farmmaps.awtest.nl/",
|
||||||
|
"Endpoint": "http://farmmaps.awtest.nl",
|
||||||
|
"BasePath": "api/v1",
|
||||||
|
"DiscoveryEndpointUrl": "https://accounts.farmmaps.awtest.nl/.well-known/openid-configuration",
|
||||||
|
"RedirectUri": "http://example.nl/api",
|
||||||
|
"ClientId": "",
|
||||||
|
"ClientSecret": "",
|
||||||
|
"Scopes": ["api"]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user