Skip to content
Snippets Groups Projects
Commit 0a79d331 authored by Tucker Gary Siegel's avatar Tucker Gary Siegel
Browse files

Merge branch 'master' into 'swagger-implementation'

# Conflicts:
#   gddController.js
parents dc19f502 31e609bb
No related branches found
No related tags found
1 merge request!2Swagger implementation
......@@ -15,8 +15,9 @@ The data in mongodb has the following fields:
Go to ```/docs``` to view the Swagger generated API docs
#### API Endpoints
* ```POST /api/:product/:year```
* Required url params: ```product``` and ```year```. Product is the crop (corn and soybean only supported)
* Body requires latitude and longitude
* Required url params: ```product``` and ```year```. Product is the crop (supports corn, soybean, wheat, tomatoes, potatoes, peas, sunflowers, sugar beets, etc.)
* ```product``` must be singular. As in, send "soybean" not "soybeans"
* Body requires ```latitude``` and ```longitude```, ```t_base``` is an optional parameter if a farmer decides to set their own base temperater in fahrenheit
* returns the gdd calculated for that year up to the most recent date of the year. If the year is before the current, the data will cover 01/01 to 12/31. If it is the current year, 01/01 - current date. But the current year is not included
### How to run
......
......@@ -39,17 +39,6 @@ exports.year_gdd = function (req, res) {
errors = []
if (product == "soybean" || product == "corn") {
t_base = 50
t_max = 86
t_min = 50
} else {
errors.push({
parameter_error: "product",
message: product + " is not available for GDD calculations"
});
}
if (year < 1981 || year > new Date().getFullYear()) {
errors.push({
parameter_error: "year",
......@@ -62,6 +51,46 @@ exports.year_gdd = function (req, res) {
parameter_error: "latitude",
message: latitude.toString() + " is out of bounds for GDD calculations. Must be between 24.083334 - 49.916668"
});
if (req.body.hasOwnProperty("t_base")) {
t_base = parseFloat(req.body.t_base);
if (t_base < t_min) {
t_min = t_base;
}
} else {
switch (product) {
case "soybean":
case "corn":
case "sunflower":
case "tomato":
case "sugar_beat":
t_base = 50;
break;
case "potato":
t_base = 44.6;
t_min = 44.6; // NEED TO ASK ABOUT MIN AND MAX TEMPS IN DAY. SHOULD T_MIN BE SET EQUAL TO T_BASE IF IT IS LESS THAN T_BASE?
break;
case "wheat":
t_base = 41.9;
t_min = 41.9;
break;
case "peas":
t_base = 41;
t_min = 41;
break;
case "brussels_sprout":
case "parsley":
case "cabbage":
t_base = 32;
t_min = 32;
break;
default:
errors.push({
parameter_error: "product",
message: product + " is not available for GDD calculations"
});
break;
}
}
if (longitude < -125 || longitude > -66.5) {
......@@ -77,8 +106,6 @@ exports.year_gdd = function (req, res) {
})
}
Gdd.findOne(query, projection).then(function(data) {
var min_temps = data["min_temps"]
......@@ -87,7 +114,6 @@ exports.year_gdd = function (req, res) {
var min_temp = 0
var max_temp = 0
var gdd = 0
for (var i = 0; i < min_temps.length; i++) {
min_temp = min_temps[i] >= t_min ? min_temps[i] : t_min;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment