From 5a71213c80304e48810ed499d1346f7fa8e525ab Mon Sep 17 00:00:00 2001 From: Peter Basham Date: Fri, 11 Mar 2016 17:57:49 +0000 Subject: [PATCH 1/3] Added ability to set reference weather conditions (Temp, Rain, Humidty) to the Zimmerman adjustment method --- routes/weather.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) mode change 100644 => 100755 routes/weather.js diff --git a/routes/weather.js b/routes/weather.js old mode 100644 new mode 100755 index 2280fa5..2f4dfdb --- a/routes/weather.js +++ b/routes/weather.js @@ -311,10 +311,17 @@ function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) { return 100; } + // Get baseline conditions for 100% water level, if provided + if ( adjustmentOptions ) { + humidityBase = adjustmentOptions.hasOwnProperty( "bh" ) ? adjustmentOptions.bh : 30; + tempBase = adjustmentOptions.hasOwnProperty( "bt" ) ? adjustmentOptions.bt : 70; + precipBase = adjustmentOptions.hasOwnProperty( "br" ) ? adjustmentOptions.br : 0; + } + var temp = ( ( weather.maxTemp + weather.minTemp ) / 2 ) || weather.temp, - humidityFactor = ( 30 - weather.humidity ), - tempFactor = ( ( temp - 70 ) * 4 ), - precipFactor = ( weather.precip * -200 ); + humidityFactor = ( humidityBase - weather.humidity ), + tempFactor = ( ( temp - tempBase ) * 4 ), + precipFactor = ( (precipBase - weather.precip ) * 200 ); // Apply adjustment options, if provided, by multiplying the percentage against the factor if ( adjustmentOptions ) { From 0b145bf936c4d2064d614d7663d5526bf2759ef4 Mon Sep 17 00:00:00 2001 From: Peter Basham Date: Fri, 11 Mar 2016 18:35:39 +0000 Subject: [PATCH 2/3] Minor change to explicitly declare variables and pass lint tests --- routes/weather.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/weather.js b/routes/weather.js index 2f4dfdb..3be2939 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -305,6 +305,7 @@ function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) { // Zimmerman method if ( adjustmentMethod === 1 ) { + var humidityBase, tempBase, precipBase; // Check to make sure valid data exists for all factors if ( !validateValues( [ "temp", "humidity", "precip" ], weather ) ) { From 9b12b2b29ee6d0aafd5894ca98266017fd7d8e1f Mon Sep 17 00:00:00 2001 From: Peter Basham Date: Fri, 11 Mar 2016 19:26:07 +0000 Subject: [PATCH 3/3] Minor changes to pass automated npm test --- routes/weather.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index 3be2939..217454d 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -305,7 +305,7 @@ function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) { // Zimmerman method if ( adjustmentMethod === 1 ) { - var humidityBase, tempBase, precipBase; + var humidityBase = 30, tempBase = 70, precipBase = 0; // Check to make sure valid data exists for all factors if ( !validateValues( [ "temp", "humidity", "precip" ], weather ) ) { @@ -314,9 +314,9 @@ function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) { // Get baseline conditions for 100% water level, if provided if ( adjustmentOptions ) { - humidityBase = adjustmentOptions.hasOwnProperty( "bh" ) ? adjustmentOptions.bh : 30; - tempBase = adjustmentOptions.hasOwnProperty( "bt" ) ? adjustmentOptions.bt : 70; - precipBase = adjustmentOptions.hasOwnProperty( "br" ) ? adjustmentOptions.br : 0; + humidityBase = adjustmentOptions.hasOwnProperty( "bh" ) ? adjustmentOptions.bh : humidityBase; + tempBase = adjustmentOptions.hasOwnProperty( "bt" ) ? adjustmentOptions.bt : tempBase; + precipBase = adjustmentOptions.hasOwnProperty( "br" ) ? adjustmentOptions.br : precipBase; } var temp = ( ( weather.maxTemp + weather.minTemp ) / 2 ) || weather.temp,