Merge pull request #5 from PeteBa/zimm2
Added ability to set reference weather conditions (Temp, Rain, Humidity) to the Zimmerman adjustment method
This commit is contained in:
14
routes/weather.js
Normal file → Executable file
14
routes/weather.js
Normal file → Executable file
@@ -305,16 +305,24 @@ function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) {
|
|||||||
|
|
||||||
// Zimmerman method
|
// Zimmerman method
|
||||||
if ( adjustmentMethod === 1 ) {
|
if ( adjustmentMethod === 1 ) {
|
||||||
|
var humidityBase = 30, tempBase = 70, precipBase = 0;
|
||||||
|
|
||||||
// Check to make sure valid data exists for all factors
|
// Check to make sure valid data exists for all factors
|
||||||
if ( !validateValues( [ "temp", "humidity", "precip" ], weather ) ) {
|
if ( !validateValues( [ "temp", "humidity", "precip" ], weather ) ) {
|
||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get baseline conditions for 100% water level, if provided
|
||||||
|
if ( adjustmentOptions ) {
|
||||||
|
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,
|
var temp = ( ( weather.maxTemp + weather.minTemp ) / 2 ) || weather.temp,
|
||||||
humidityFactor = ( 30 - weather.humidity ),
|
humidityFactor = ( humidityBase - weather.humidity ),
|
||||||
tempFactor = ( ( temp - 70 ) * 4 ),
|
tempFactor = ( ( temp - tempBase ) * 4 ),
|
||||||
precipFactor = ( weather.precip * -200 );
|
precipFactor = ( (precipBase - weather.precip ) * 200 );
|
||||||
|
|
||||||
// Apply adjustment options, if provided, by multiplying the percentage against the factor
|
// Apply adjustment options, if provided, by multiplying the percentage against the factor
|
||||||
if ( adjustmentOptions ) {
|
if ( adjustmentOptions ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user