Blight API first draft

This commit is contained in:
Wilco Krikke 2021-06-07 20:59:25 +02:00
parent b4e792e259
commit 94586342ee

View File

@ -1,30 +1,265 @@
## Blight API # Blight API
[<< Home](README.md) [<< Home](README.md)
For the currently available public FarmMaps API you can take a look at swagger: https://test.farmmaps.eu/swagger For the currently available public FarmMaps API you can take a look at swagger: https://farmmaps.eu/swagger
## Prerequisite
The blight package is added to the account which is used to authenticate.
## API flow ## API flow
* Authenticate User * Authenticate
* Create cropping scheme (if not exists) * Create cropping scheme (if not exists)
* Create crop field (if not exists) * Create crop field (if not exists)
* Get blight advice * Get blight advice
* Create blight advice * Create blight advice
* Update UserInput
* Add spray * Add spray
* Add irrigation * Add irrigation
* Get predefined fungicides
### Steps ## Steps
[Authentication](Authentication.md)
##### Optional ### Authenticate
[Create Croppingscheme] -- todo See [Authentication](Authentication.md)
[Create Cropfield](Create-Cropfield.md)
### Create cropping scheme (if not exists)
See [Create Croppingscheme](Create-Croppingscheme.md)
### Create crop field (if not exists)
See [Create Cropfield](Create-Cropfield.md)
### <a name="get-advice"></a>Get blight advice
Blight is only available for potato fields.
The advice is automatically created when new potato fields are added and is scheduled to be updated at configured times.
It is also possible to create a new advice at any time, see [Create blight advice](#create-advice).
A blight advice is a child record of a crop field.
Use the crop field code to get the latest blight advice.
> Request
```javascript
GET /api/v1/items/{code}/children?it=vnd.farmmaps.itemtype.blight
```
> Response 200 OK
```javascript
[
{
"parentCode": "string",
"geometry": ...
"data": {
"advices": [
{
"date": "2021-03-19T00:00:00",
"weather": [
{
"hh": 0,
"rain": 0.0,
"humidity": 90.0,
"irrigation": 0.0,
"temperature": 2.0,
"precipitation": 0.0
},
{
"hh": 1,
"rain": 0.0,
"humidity": 91.0,
"irrigation": 0.0,
"temperature": 1.0,
"precipitation": 0.0
},...],
"sprayTime": null,
"sprayType": 3,
"ooSporesRisk": false,
"fungicideLeftPct": 0,
"sprayEffectivity": null,
"unprotectedGrowth": 0.0,
"tuberInfectionRisk": false,
"infectionRiskPerHour": [
0,...]
...
}
```
The data object contains the advices from emergence date and weather from planting date.
The date property respresents the advice date, the weather array contains 24 objects, 1 for each hour.
> Response 404 Not Found
There is no advice available, try to create a new advice, see [Create blight advice](#create-advice).
### <a name="create-advice"></a>Create blight advice
Task 'vnd.farmmaps.task.blight' must be executed to create an advice.
This task is automatically created for potato fields and is scheduled to run at configered times to keep the advice updated. But it is possible to create this task at any time.
###### Querying predefined fungicides. Add the crop field code to the URL and execute the following request.
A list of fungicices can be requested by getting the "vnd.farmmaps.itemtype.codelist.fm005" items from farmmaps.
> Request
```javascript
POST /api/v1/items/{code}/tasks
{
"TaskType": "vnd.farmmaps.task.blight",
"Delay": null,
"attributes": {}
}
```
> Response 200
```javascript
{
"code": "{code}",
"taskType": "vnd.farmmaps.task.blight",
"attributes": {
"messagePriority": "10"
}
}
```
With the code in the response message and the code of the crop field, it is possible to check the task's state (error/ok/scheduled/processing). See [Check task status](Polling-task-status.md).
### Add spray
Sprays are stored as child item of a blight item.
This item also contains other parameters like pressure, disable/enable oospores and risc on tuber infection, wich are all used when the advice is created.
Changing these parameters will not create in a new advice automatically.
But is it possible to create an advice at any time, see [Create blight advice](#create-advice).
Get the blight advice code from [Get blight advice](#get-advice)
Use this code in the following request.
> Request
```javascript
GET api/v1/items/{code}/children?it=vnd.farmmaps.itemtype.user.input
```
> Response 200
```javascript
[
{
"code": "{code}",
// ....
"data": {
"sprays": [],
"phytoPressure": 0,
"ignoreOoSpores": true,
"ignoreTuberRisk": true,
"haulmKillingDate": null
}
}
```
Get the first objecy of the array, change the data, and push the object back.
Use the code from the response above.
```javascript
PUT /api/v1/items/{code}
{
"parentCode": "....",
// ....
"data": {
"sprays": [
{
"dose": 1,
"isVRA": false,
"fungicide": {
"ai1": "mandipropamid",
"ai2": null,
"ai3": null,
"code": "revus",
"name": "revus 0,6 l",
"maxdose": "0.6",
"mindose": "0.48",
"safedays": "3",
"emergence": true,
"newgrowth": "2",
"contentai1": "250",
"contentai2": "0",
"contentai3": "0",
"fastgrowth": true,
"contentunit": "g/l",
"rainfastness": "3",
"tuberfilling": false,
"aidescription": "mandipropamid (0.6 l/ha)",
"curativescore": "1",
"dryingtimemax": "1",
"dryingtimemin": "0.5",
"vracompatible": true,
"maxapplications": "6",
"preventivescore": "4",
"recommendeddose": "0.6",
"tuberprotection": "2",
"eradicativescore": "1.5",
"earlytubersetting": false,
"protectioncategory": "1",
"applicationrateunit": "l/ha",
"ctgbregistrationnumber": "12969 n"
},
"sprayTime": "2021-04-15T12:00:00Z"
}
],
"phytoPressure": 0,
"ignoreOoSpores": false,
"ignoreTuberRisk": true,
"haulmKillingDate": null
},
// ....
}
```
> Response 200
```javascript
{
"parentCode": "....",
// ....
}
```
### Add irrigation
Irrigations are stored as child item of a crop recording item.
First step is to get the crop recording item for the crop field.
#### 1. get the crop recording item for the crop field
> Request
```javascript
GET /api/v1/items/{code}/children?it=vnd.farmmaps.itemtype.crprec
```
> Response 200
```javascript
[
{
"code": "{code}",
// ....
"data":
{
}
}
```
#### 2. Add irrigation to the crop field
Use the crop recording code, got from the previous call, and change the desired fields (from, to, quantity, etc):
> Request
```javascript
POST /api/v1/items/
{
"data": {
"from": "2021-05-05T08:00:00.000Z",
"to": "2021-05-05T13:00:00.000Z",
"quantity": 80,
"name": "Irrigation",
"status": "3",
"method": "90100",
"contractor": false,
"operationCode": "9",
"product": "OW"
},
"parentCode": "{code}",
"itemType": "vnd.farmmaps.itemtype.crprec.operation",
"name": "CrpRec Operation, Irrigation"
}
```
### Get predefined fungicides
A list of predefined fungicides can be requested by getting the "vnd.farmmaps.itemtype.codelist.fm002" items from farmmaps.
> Request > Request
```javascript ```javascript
GET /api/v1/items/?it=vnd.farmmaps.itemtype.codelist.fm002 GET /api/v1/items/?it=vnd.farmmaps.itemtype.codelist.fm002
@ -33,8 +268,8 @@ GET /api/v1/items/?it=vnd.farmmaps.itemtype.codelist.fm002
```javascript ```javascript
[ [
{ {
"code": "....", "code": "...",
// .... // ...
"data": "data":
{ {
"ai1": "fluazinam", "ai1": "fluazinam",
@ -73,15 +308,3 @@ GET /api/v1/items/?it=vnd.farmmaps.itemtype.codelist.fm002
... ...
] ]
``` ```
* Task 'vnd.farmmaps.task.blight' must be executed to create an advice. This task is automatically created for crop fields with potato and is scheduled to run at configered times to keep the advice updated.
It is also possible to executed this task at any time through the API. This will be explained in the following chapters.
**Users can poll the task api to see if a task is completed**
**This can be achieved with the task execution id obtained from calling the 'ItemTask' API.**
[Poll task status](Polling-task-status.md)
**Users can query the API for child items of a cropfield to see what items it has.**