Skip to content
Snippets Groups Projects
Commit 030395e9 authored by tuckersiegel's avatar tuckersiegel
Browse files

update gdd logic

parent 5c74c0f2
No related branches found
No related tags found
No related merge requests found
...@@ -27,9 +27,8 @@ function find(collection, query, projection, temps, res) { ...@@ -27,9 +27,8 @@ function find(collection, query, projection, temps, res) {
var gdd_sum = 0; var gdd_sum = 0;
for (var i = 0; i < min_temps.length; i++) { for (var i = 0; i < min_temps.length; i++) {
min_temp = min_temps[i] >= t_min ? min_temps[i] : t_min; gdd = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base);
max_temp = max_temps[i] <= t_max ? max_temps[i] : t_max; gdd_sum += gdd
gdd_sum += ((max_temp + min_temp) / 2) - t_base
gdds.push(gdd_sum) gdds.push(gdd_sum)
} }
send_response("Accumulated GDDs", gdds, data, res); send_response("Accumulated GDDs", gdds, data, res);
......
...@@ -26,10 +26,8 @@ function find(collection, query, projection, temps, res) { ...@@ -26,10 +26,8 @@ function find(collection, query, projection, temps, res) {
var max_temp = 0 var max_temp = 0
for (var i = 0; i < min_temps.length; i++) { for (var i = 0; i < min_temps.length; i++) {
min_temp = min_temps[i] >= t_min ? min_temps[i] : t_min; gdd = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base);
max_temp = max_temps[i] <= t_max ? max_temps[i] : t_max; gdds.push(gdd)
gdds.push(((max_temp + min_temp) / 2) - t_base)
} }
send_response("GDDs", gdds, data, res); send_response("GDDs", gdds, data, res);
}, function(err) { }, function(err) {
......
...@@ -13,9 +13,9 @@ function find(collection, query, projection, temps, res) { ...@@ -13,9 +13,9 @@ function find(collection, query, projection, temps, res) {
var max_temp = 0 var max_temp = 0
for (var i = 0; i < min_temps.length; i++) { for (var i = 0; i < min_temps.length; i++) {
min_temp = min_temps[i] >= t_min ? min_temps[i] : t_min; gdd = utils.calculate_gdd(min_temps[i], t_min, max_temps[i], t_max, t_base);
max_temp = max_temps[i] <= t_max ? max_temps[i] : t_max;
gdds.push(((max_temp + min_temp) / 2) - t_base) gdds.push(gdd)
} }
res.json({ res.json({
......
...@@ -41,4 +41,14 @@ function product_base_switch(product, errors, t_base, t_min) { ...@@ -41,4 +41,14 @@ function product_base_switch(product, errors, t_base, t_min) {
} }
} }
module.exports.product_base_switch = product_base_switch;
\ No newline at end of file function calculate_gdd(min_temp, t_min, max_temp, t_max, t_base) {
min_temp = min_temp >= t_min ? min_temp : t_min;
max_temp = max_temp >= t_min ? max_temp : t_min;
max_temp = max_temp <= t_max ? max_temp : t_max;
gdd = ((max_temp + min_temp) / 2) - t_base;
return gdd
}
module.exports.product_base_switch = product_base_switch;
module.exports.calculate_gdd = calculate_gdd;
\ No newline at end of file
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