Correctly clamp precipitation value to 0 when negative
This commit is contained in:
@@ -73,20 +73,22 @@ function getWeatherUndergroundData( location, weatherUndergroundKey, callback )
|
|||||||
try {
|
try {
|
||||||
data = JSON.parse( data );
|
data = JSON.parse( data );
|
||||||
|
|
||||||
var weather = {
|
var currentPrecip = parseFloat( data.current_observation.precip_today_in ),
|
||||||
icon: data.current_observation.icon,
|
yesterdayPrecip = parseFloat( data.history.dailysummary[ 0 ].precipi ),
|
||||||
timezone: data.current_observation.local_tz_offset,
|
weather = {
|
||||||
sunrise: parseInt( data.sun_phase.sunrise.hour ) * 60 + parseInt( data.sun_phase.sunrise.minute ),
|
icon: data.current_observation.icon,
|
||||||
sunset: parseInt( data.sun_phase.sunset.hour ) * 60 + parseInt( data.sun_phase.sunset.minute ),
|
timezone: data.current_observation.local_tz_offset,
|
||||||
maxTemp: parseInt( data.history.dailysummary[ 0 ].maxtempi ),
|
sunrise: parseInt( data.sun_phase.sunrise.hour ) * 60 + parseInt( data.sun_phase.sunrise.minute ),
|
||||||
minTemp: parseInt( data.history.dailysummary[ 0 ].mintempi ),
|
sunset: parseInt( data.sun_phase.sunset.hour ) * 60 + parseInt( data.sun_phase.sunset.minute ),
|
||||||
temp: parseInt( data.current_observation.temp_f ),
|
maxTemp: parseInt( data.history.dailysummary[ 0 ].maxtempi ),
|
||||||
humidity: ( parseInt( data.history.dailysummary[ 0 ].maxhumidity ) + parseInt( data.history.dailysummary[ 0 ].minhumidity ) ) / 2,
|
minTemp: parseInt( data.history.dailysummary[ 0 ].mintempi ),
|
||||||
precip: ( parseFloat( data.current_observation.precip_today_in ) || 0 ) + ( parseFloat( data.history.dailysummary[ 0 ].precipi ) || 0 ),
|
temp: parseInt( data.current_observation.temp_f ),
|
||||||
solar: parseInt( data.current_observation.UV ),
|
humidity: ( parseInt( data.history.dailysummary[ 0 ].maxhumidity ) + parseInt( data.history.dailysummary[ 0 ].minhumidity ) ) / 2,
|
||||||
wind: parseInt( data.history.dailysummary[ 0 ].meanwindspdi ),
|
precip: ( currentPrecip < 0 ? 0 : currentPrecip ) + ( yesterdayPrecip < 0 ? 0 : yesterdayPrecip ),
|
||||||
elevation: parseInt( data.current_observation.observation_location.elevation )
|
solar: parseInt( data.current_observation.UV ),
|
||||||
};
|
wind: parseInt( data.history.dailysummary[ 0 ].meanwindspdi ),
|
||||||
|
elevation: parseInt( data.current_observation.observation_location.elevation )
|
||||||
|
};
|
||||||
|
|
||||||
callback( weather );
|
callback( weather );
|
||||||
|
|
||||||
@@ -322,7 +324,7 @@ function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) {
|
|||||||
var temp = ( ( weather.maxTemp + weather.minTemp ) / 2 ) || weather.temp,
|
var temp = ( ( weather.maxTemp + weather.minTemp ) / 2 ) || weather.temp,
|
||||||
humidityFactor = ( humidityBase - weather.humidity ),
|
humidityFactor = ( humidityBase - weather.humidity ),
|
||||||
tempFactor = ( ( 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
|
||||||
if ( adjustmentOptions ) {
|
if ( adjustmentOptions ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user