Fix bugs incorporating cached value of yesterday's humidity
This commit is contained in:
@@ -132,7 +132,8 @@
|
|||||||
location = location.join( "," );
|
location = location.join( "," );
|
||||||
|
|
||||||
Cache.findOne( { location: location }, function( err, record ) {
|
Cache.findOne( { location: location }, function( err, record ) {
|
||||||
if ( record && record.hasOwnProperty( "yesterdayHumidity" ) ) {
|
|
||||||
|
if ( record && record.yesterdayHumidity !== null ) {
|
||||||
weather.yesterdayHumidity = record.yesterdayHumidity;
|
weather.yesterdayHumidity = record.yesterdayHumidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,16 +184,20 @@
|
|||||||
|
|
||||||
// If a record is found update the data and save it
|
// If a record is found update the data and save it
|
||||||
if ( record ) {
|
if ( record ) {
|
||||||
|
|
||||||
record.currentHumidityTotal += weather.observation.imperial.rh;
|
record.currentHumidityTotal += weather.observation.imperial.rh;
|
||||||
record.currentHumidityCount++;
|
record.currentHumidityCount++;
|
||||||
record.save();
|
record.save();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// If no cache record is found, generate a new one and save it
|
// If no cache record is found, generate a new one and save it
|
||||||
new Cache( {
|
new Cache( {
|
||||||
|
location: location,
|
||||||
currentHumidityTotal: weather.observation.imperial.rh,
|
currentHumidityTotal: weather.observation.imperial.rh,
|
||||||
currentHumidityCount: 1
|
currentHumidityCount: 1
|
||||||
} ).save();
|
} ).save();
|
||||||
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
@@ -204,7 +209,7 @@
|
|||||||
var temp = ( weather.observation.imperial.temp_max_24hour + weather.observation.imperial.temp_min_24hour ) / 2,
|
var temp = ( weather.observation.imperial.temp_max_24hour + weather.observation.imperial.temp_min_24hour ) / 2,
|
||||||
|
|
||||||
// Relative humidity and if unavailable default to 0
|
// Relative humidity and if unavailable default to 0
|
||||||
rh = weather.observation.imperial.rh || 0,
|
rh = weather.yesterdayHumidity || weather.observation.imperial.rh || 0,
|
||||||
|
|
||||||
// The absolute precipitation in the past 48 hours
|
// The absolute precipitation in the past 48 hours
|
||||||
precip = weather.observation.imperial.precip_2day || weather.observation.imperial.precip_24hour;
|
precip = weather.observation.imperial.precip_2day || weather.observation.imperial.precip_24hour;
|
||||||
|
|||||||
Reference in New Issue
Block a user