From d0ed63ad61287539f7d4f0f369880af7a1aac31a Mon Sep 17 00:00:00 2001 From: tuckersiegel <siegel.tucker@gmail.com> Date: Thu, 11 Mar 2021 16:23:04 -0500 Subject: [PATCH] new base/min values for crops --- controllers/gddAccumulatedController.js | 16 +++++++------- controllers/gddController.js | 12 +++++------ controllers/gddNormalController.js | 8 +++---- lib/utils.js | 28 ++++++++++++++++++------- swagger_definition.yaml | 8 +++---- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/controllers/gddAccumulatedController.js b/controllers/gddAccumulatedController.js index 5be4c73..cb2f905 100644 --- a/controllers/gddAccumulatedController.js +++ b/controllers/gddAccumulatedController.js @@ -1,6 +1,6 @@ -gdd = require('../models/gdd.js'); -gdd_current = require('../models/gdd_current.js'); -gdd_normal = require('../models/normals.js'); +gdd_collection = require('../models/gdd.js'); +gdd_current_collection = require('../models/gdd_current.js'); +gdd_normal_collection = require('../models/normals.js'); utils = require('../lib/utils'); function send_response(message, gdds, data, res) { @@ -27,8 +27,8 @@ function find(collection, query, projection, temps, res) { var gdd_sum = 0; for (var i = 0; i < min_temps.length; i++) { - gdd = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base); - gdd_sum += gdd + gdd_value = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base); + gdd_sum += gdd_value gdds.push(gdd_sum) } send_response("Accumulated GDDs", gdds, data, res); @@ -117,9 +117,9 @@ exports.accumulated_gdd = function (req, res) { } if (year != new Date().getFullYear()) { - find(gdd, query, projection, temps, res); + find(gdd_collection, query, projection, temps, res); } else { - find(gdd_current, query, projection, temps, res); + find(gdd_current_collection, query, projection, temps, res); } }; @@ -194,5 +194,5 @@ exports.accumulated_normal_gdd = function (req, res) { t_min: t_min, } - find(gdd_normal, query, projection, temps, res); + find(gdd_normal_collection, query, projection, temps, res); }; \ No newline at end of file diff --git a/controllers/gddController.js b/controllers/gddController.js index 095c684..86a8c35 100644 --- a/controllers/gddController.js +++ b/controllers/gddController.js @@ -1,5 +1,5 @@ -gdd = require('../models/gdd.js'); -gdd_current = require('../models/gdd_current.js'); +gdd_collection = require('../models/gdd.js'); +gdd_current_collection = require('../models/gdd_current.js'); utils = require('../lib/utils'); @@ -26,8 +26,8 @@ function find(collection, query, projection, temps, res) { var max_temp = 0 for (var i = 0; i < min_temps.length; i++) { - gdd = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base); - gdds.push(gdd) + gdd_value = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base); + gdds.push(gdd_value) } send_response("GDDs", gdds, data, res); }, function(err) { @@ -114,9 +114,9 @@ exports.year_gdd = function (req, res) { } if (year != new Date().getFullYear()) { - find(gdd, query, projection, temps, res); + find(gdd_collection, query, projection, temps, res); } else { - find(gdd_current, query, projection, temps, res); + find(gdd_current_collection, query, projection, temps, res); } }; \ No newline at end of file diff --git a/controllers/gddNormalController.js b/controllers/gddNormalController.js index 638e871..52cd6b9 100644 --- a/controllers/gddNormalController.js +++ b/controllers/gddNormalController.js @@ -1,4 +1,4 @@ -normals = require('../models/normals.js'); +normals_collection = require('../models/normals.js'); utils = require('../lib/utils'); function find(collection, query, projection, temps, res) { @@ -13,9 +13,9 @@ function find(collection, query, projection, temps, res) { var max_temp = 0 for (var i = 0; i < min_temps.length; i++) { - gdd = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base); + gdd_value = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base); - gdds.push(gdd) + gdds.push(gdd_value) } res.json({ @@ -98,5 +98,5 @@ exports.normal = function (req, res) { t_min: t_min, } - find(normals, query, projection, temps, res); + find(normals_collection, query, projection, temps, res); }; \ No newline at end of file diff --git a/lib/utils.js b/lib/utils.js index b450a8f..b85d520 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -5,10 +5,15 @@ function product_base_switch(product, errors, t_base, t_min) { case "corn": case "sunflower": case "tomato": - case "sugar_beat": + case "sugar_beet": + case "peanut": t_base = 50; t_min = 50; break; + case "cotton": + t_base = 57.2; + t_min = 57.2; + 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? @@ -17,16 +22,23 @@ function product_base_switch(product, errors, t_base, t_min) { t_base = 41.9; t_min = 41.9; break; - case "peas": - t_base = 41; - t_min = 41; + case "pea": + case "oat": + t_base = 40.1; + t_min = 40.1; break; - case "brussels_sprout": - case "parsley": - case "cabbage": - t_base = 32; + case "spring_wheat": + t_base= 32; t_min = 32; break; + case "rice": + t_base = 46.4; + t_min = 46.4; + break; + case "sorghum": + t_base = 46.4; + t_min = 46.4; + break; default: errors.push({ parameter_error: "product", diff --git a/swagger_definition.yaml b/swagger_definition.yaml index 71b8d7d..4633b9b 100644 --- a/swagger_definition.yaml +++ b/swagger_definition.yaml @@ -14,7 +14,7 @@ paths: description: Agricultural product to calculate gdd for schema: type: string - enum: [corn, soybean, sugar_beet, sunflower, tomato, potato, wheat, peas, parsley, brussels_sprouts, cabbage] + enum: [corn, cotton, oat, peanut, pea, potato, rice, soybean, sorghum, spring_wheat, sugar_beet, sunflower, tomato, wheat] - in: path name: year required: true @@ -107,7 +107,7 @@ paths: description: Agricultural product to calculate gdd for schema: type: string - enum: [corn, soybean, sugar_beet, sunflower, tomato, potato, wheat, peas, parsley, brussels_sprouts, cabbage] + enum: [corn, cotton, oat, peanut, pea, potato, rice, soybean, sorghum, spring_wheat, sugar_beet, sunflower, tomato, wheat] requestBody: content: application/json: @@ -188,7 +188,7 @@ paths: description: Agricultural product to calculate gdd for schema: type: string - enum: [corn, soybean, sugar_beet, sunflower, tomato, potato, wheat, peas, parsley, brussels_sprouts, cabbage] + enum: [corn, cotton, oat, peanut, pea, potato, rice, soybean, sorghum, spring_wheat, sugar_beet, sunflower, tomato, wheat] requestBody: content: application/json: @@ -273,7 +273,7 @@ paths: description: Agricultural product to calculate gdd for schema: type: string - enum: [corn, soybean, sugar_beet, sunflower, tomato, potato, wheat, peas, parsley, brussels_sprouts, cabbage] + enum: [corn, cotton, oat, peanut, pea, potato, rice, soybean, sorghum, spring_wheat, sugar_beet, sunflower, tomato, wheat] - in: path name: year required: true -- GitLab