rmloeb feedback and review

This commit is contained in:
Pete ba
2019-05-06 18:35:04 +01:00
parent b4b34f392e
commit 7775b2e613
2 changed files with 20 additions and 13 deletions

View File

@@ -1,9 +1,9 @@
var CronJob = require( "cron" ).CronJob; var CronJob = require( "cron" ).CronJob,
var server = require( "../server.js" ); server = require( "../server.js" ),
var today = {}, yesterday = {}; today = {}, yesterday = {},
var count = { temp: 0, humidity: 0 }; count = { temp: 0, humidity: 0 },
var current_date = new Date(); current_date = new Date(),
var last_rain = new Date().setTime(0); last_bucket;
function sameDay(d1, d2) { function sameDay(d1, d2) {
return d1.getFullYear() === d2.getFullYear() && return d1.getFullYear() === d2.getFullYear() &&
@@ -31,14 +31,16 @@ exports.captureWUStream = function( req, res ) {
today.precip = curr; today.precip = curr;
} }
if ( ( "rainin" in req.query ) && !isNaN( curr = parseFloat( req.query.rainin ) ) && curr > 0 ) { if ( ( "rainin" in req.query ) && !isNaN( curr = parseFloat( req.query.rainin ) ) && curr > 0 ) {
last_rain = new Date(); last_bucket = new Date();
} }
console.log( "OpenSprinkler Weather Observation: %s", JSON.stringify( req.query ) );
res.send( "success\n" ); res.send( "success\n" );
}; };
exports.useLocalWeather = function() { exports.useLocalWeather = function() {
return ( server.pws !== "false" ? true : false ); return server.pws !== "none" ? true : false;
}; };
exports.getLocalWeather = function() { exports.getLocalWeather = function() {
@@ -46,9 +48,15 @@ exports.getLocalWeather = function() {
// Use today's weather if we dont have information for yesterday yet (i.e. on startup) // Use today's weather if we dont have information for yesterday yet (i.e. on startup)
Object.assign( result, today, yesterday); Object.assign( result, today, yesterday);
Object.assign( result, ( yesterday.precip && today.precip ) ? { precip: yesterday.precip + today.precip } : {} );
result.raining = ( ( Date.now() - last_rain ) / 1000 / 60 / 60 < 1 ); if ( "precip" in yesterday && "precip" in today ) {
result.precip = yesterday.precip + today.precip;
}
// PWS report "buckets" so consider it still raining if last bucket was less than an hour ago
if ( last_bucket !== undefined ) {
result.raining = ( ( Date.now() - last_bucket ) / 1000 / 60 / 60 < 1 );
}
return result; return result;
}; };

View File

@@ -168,9 +168,8 @@ function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) {
precipBase = adjustmentOptions.hasOwnProperty( "br" ) ? adjustmentOptions.br : precipBase; precipBase = adjustmentOptions.hasOwnProperty( "br" ) ? adjustmentOptions.br : precipBase;
} }
var temp = ( ( weather.maxTemp + weather.minTemp ) / 2 ) || weather.temp, var humidityFactor = ( humidityBase - weather.humidity ),
humidityFactor = ( humidityBase - weather.humidity ), tempFactor = ( ( weather.temp - tempBase ) * 4 ),
tempFactor = ( ( temp - tempBase ) * 4 ),
precipFactor = ( ( precipBase - 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