Pest Models

In this part we will focus on two endpoint:

  1. “AFS/ListPestModels” endpoint, which allow you to get a zone management map in geojson file format in wgs 84 coordinate reference system
  2. “AFS/ActualPestModelsRiskLevel” endpoint, which allow you to get a zone management map in zip file format, where within the zip file you will find the shapefile of zone management in wgs 84 coordinate reference system

ListPestModels

Python

In order to use this endpoint you need to set the following parameters:

  1. USEREMAIL
  2. APIKEY
# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/ListPestModels"

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Set the headers for the request
headers = {
    "Content-Type": "application/json"
}

# Make the POST request

response = requests.get(url, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))

# Convert from response to json

data = response.json()

# Convert from json to pandas

df = pd.DataFrame(data)

# Let's see the first 5 agricultural products

df.head()

R

In order to use this endpoint you need to set the following parameters:

  1. USEREMAIL
  2. APIKEY
# import libraries

library(tictoc)
library(httr)
library(gt)
library(tidyverse)

# Define the url of the API

api_url <- "https://www.api.automaticfarmsolutionwebapp.com/AFS/ListPestModels?"

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Get the start time to API Call

tic()

# Make the GET request

r <- GET(
  api_url,
  httr::authenticate(
    user = Sys.getenv(USEREMAIL),
    password = Sys.getenv(APIKEY)
  )
)

# Print out the seconds needed to create the prescription map

print("The API needed:")
[1] "The API needed:"
toc()
0.71 sec elapsed
# Get the status of the request

httr::status_code(r)
[1] 200
# Print out the list of the Phytofarmaceutical products

cont <- httr::content(r, as = "text", type = "application/json", encoding="UTF-8")
cont<-jsonlite::fromJSON(cont) %>% as.data.frame
cont[1:5,]
[1] "gddAlfalfaWeevil"                "gddAlmondNavelOrangewormMummy"  
[3] "gddAlmondNavelOrangewormNewCrop" "gddAmericanPlumBorer"           
[5] "gddAppleMaggotEmergence"        

Node.js

In order to use this endpoint you need to set the following parameters:

  1. USEREMAIL
  2. APIKEY
// load libraries

const axios = require('axios');

// Set username e apikey

const username = 'XXXXXXXXXXXXXX';
const password = 'XXXXXXXXXXXXXX';

// set the apiurl

const url='https://www.api.automaticfarmsolutionwebapp.com/AFS/ListPestModels';

const options = {
  method: 'get',
  url: url,
  auth: {
    username: username,
    password: password,
  },
};

axios(options)
  .then(response => {
    console.log('Risposta JSON:', response.data);
  })
  .catch(error => {
    console.error('Errore:', error.message);
  });

ActualPestModelsRiskLevel

Python

In order to use this endpoint you need to set the following parameters:

  1. USEREMAIL
  2. APIKEY
  3. long, longitude of the request field
  4. lat, latitude of the request field
  5. pestmodel, the pest model that you would like to have. Must be on of the list, that ca be obtained by the “AFS/ListPestModels” endpoint
# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd

# Define the API parameters setting

longi="13.3123"
lat="42.4560"
pestmodel="gddAlfalfaWeevil"

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/ActualPestModelsRiskLevel?long="+longi+"&lat="+lat+"&pestmodel="+pestmodel

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Set the headers for the request
headers = {
    "Content-Type": "application/json"
}

# Make the POST request

response = requests.post(url, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))

# Convert from response to json

data = response.json()

# Convert from json to pandas

df = pd.DataFrame(data)

# Let's see the first 5 agricultural products

df.head()

R

In order to use this endpoint you need to set the following parameters:

  1. USEREMAIL
  2. APIKEY
  3. long, longitude of the request field
  4. lat, latitude of the request field
  5. pestmodel, the pest model that you would like to have. Must be on of the list, that ca be obtained by the “AFS/ListPestModels” endpoint
# import libraries

library(tictoc)
library(httr)
library(gt)
library(tidyverse)

# Define the API parameters setting

longi<-"13.3123"
lat<-"42.4560"
pestmodel<-"gddAlfalfaWeevil"

# Define the url of the API

api_url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/ActualPestModelsRiskLevel?long=", longi, "&lat=",lat, "&pestmodel=", pestmodel)

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Get the start time to API Call

tic()

# Make the POST request

r <- POST(
  api_url,
  httr::authenticate(
    user = Sys.getenv(USEREMAIL),
    password = Sys.getenv(APIKEY)
  )
)

# Print out the seconds needed to create the prescription map

print("The API needed:")
[1] "The API needed:"
toc()
2.94 sec elapsed
# Get the status of the request

httr::status_code(r)
[1] 200
# Print out the list of the Phytofarmaceutical products

cont <- httr::content(r, as = "text", type = "application/json", encoding="UTF-8")
cont<-jsonlite::fromJSON(cont) %>% as.data.frame
gt(cont)
risk_level current_pest_situation current_suggested_operation
0 Adult / Eggs Adults are active.
0 Adult / Eggs Adults have begun to lay eggs.

Node.js

In order to use this endpoint you need to set the following parameters:

  1. USEREMAIL
  2. APIKEY
  3. long, longitude of the request field
  4. lat, latitude of the request field
  5. pestmodel, the pest model that you would like to have. Must be on of the list, that ca be obtained by the “AFS/ListPestModels” endpoint
// load libraries

const axios = require('axios');

// Set username e apikey

const username = 'XXXXXXXXXXXXXX';
const password = 'XXXXXXXXXXXXXX';

// set the apiurl

const apiurl='https://www.api.automaticfarmsolutionwebapp.com/AFS/ActualPestModelsRiskLevel?long=';

// set the product_name parameter

const longi="13.3123";
const lat="42.4560";
const pestmodel="gddAlfalfaWeevil";

// set the apiendpoint

const url = apiurl.concat(longi, "&lat=", lat, "&pestmodel=", pestmodel)

const options = {
  method: 'post',
  url: url,
  auth: {
    username: username,
    password: password,
  },
};

axios(options)
  .then(response => {
    console.log('Risposta JSON:', response.data);
  })
  .catch(error => {
    console.error('Errore:', error.message);
  });

Easy - Fast - Customizable

Back to top