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

Merge branch 'multiple_bases' into 'master'

added multiple bases, as well as the ability to choose their own base

See merge request !1
parents 78fd75bc 5f015861
No related branches found
No related tags found
1 merge request!1added multiple bases, as well as the ability to choose their own base
......@@ -14,8 +14,9 @@ The data in mongodb has the following fields:
#### 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
......
......@@ -28,12 +28,42 @@ exports.year_gdd = function (req, res) {
var t_max = 86
var t_min = 50
if (product == "soybean" || product == "corn") {
t_base = 50
t_max = 86
t_min = 50
if (req.body.hasOwnProperty("t_base")) {
t_base = parseFloat(req.body.t_base);
if (t_base < t_min) {
t_min = t_base;
}
} else {
res.status(404).send(product + " is not available for GDD calculations")
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:
res.status(404).send(product + " is not available for GDD calculations");
break;
}
}
Gdd.findOne(query, projection).then(function(data) {
......@@ -44,7 +74,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