WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: Hugh Whalen on September 09, 2021, 09:14:53 AM

Title: NaN for Barometer
Post by: Hugh Whalen on September 09, 2021, 09:14:53 AM
I am setting up a new Weather Site and I am using the Saratoga templates. The site is www.flowers-cove.ca/wxindex.php

Most everything is working except for the Barometer.  It shows NaN, which I assume means Not a Number.

I am using the Base Canada template and WeatherCat software.

Anybody have any idea what is going on here? [ You are not allowed to view attachments ]
Title: Re: NaN for Barometer
Post by: Hugh Whalen on September 09, 2021, 12:02:03 PM
I have been trying to figure out what is going on here.

If I look at the WCT_realtime.txt file on the server it shows some strange things. The current pressure is 1,012.0

In fact, all the pressure readings (min today, max today, etc) are recorded as x,xxx.x That is, there is a comma there. Shouldn't it be xxxx.x eg no comma?
Title: Re: NaN for Barometer
Post by: Jasiu on September 09, 2021, 12:37:40 PM
The javascript code (ajaxWCTwx.js) expects no comma in the data. You hit the multiply by 1.0 below as your UOM is "mb" and that is what results in the NaN.

Code: [Select]
function cBaroToHPA ( rawbaro ) {
// convert input pressure to hPa if need be    
var cpat=/mb|hpa/i;
if(cpat.test(rBaroUOM)) { // baro already in mb/hPa
return rawbaro * 1.0;
} else { // convert inHg to mb/hPa
return rawbaro * 33.86;
}
   
}

Title: Re: NaN for Barometer
Post by: Jasiu on September 09, 2021, 12:39:20 PM
Also note on http://www.flowers-cove.ca/wxstatus.php (http://www.flowers-cove.ca/wxstatus.php) that the realtime file status is Not Current.
Title: Re: NaN for Barometer
Post by: saratogaWX on September 09, 2021, 12:55:01 PM
It appears that your locale settings on your mac has 'use commas in thousands' displays for numbers.  You need to turn that off so the barometer will show without embedded commas.  That should fix the issue.

example in WCTtags.php
Quote
STAT:PRESSURE:CURRENT|1,011.7|// Current Pressure:|:
STAT:PRESSURE:DELTA1|-0.4|// Current Pressure change over 1 hour.:|:
STAT:PRESSURE:DELTA24|-2.4|// Current Pressure change over 24 hours.:|:
STAT:PRESSURE:24HRSAGO|1,014.2|// Current Pressure value 24 hours ago.:|:
Title: Re: NaN for Barometer
Post by: Hugh Whalen on September 09, 2021, 01:05:40 PM
That fixed the problem. Thank you very much for your help.

Hugh