Page 1 of 1

OpenWeather Fahrenheit Calcularion Incorrect?

Posted: 30 Jul 2014 02:21
by islipfd19
I selected the OpenWeather module and entered my desired info and selected Fahrenheit as the display type. I noticed that the temperarure was off by a few degrees. I looked into the index.js file itself and found it odd on how the calculation was being performed. The line below is from the original index.js file

Code: Select all

var temp = Math.round((self.config.units === "celsius" ? res.data.main.temp - 273.15 : res.data.main.temp) * 10) / 10,
Now, OpenWeather.org provides the temperature in measurement of Kelvin, the formula to convert Kelvin to Celsius is straight forward. K - 273.15. And as you see in the above line of code; if Celsius is selected it performs that math correctly. But the Fahrenheit formula being used here is (K * 10) / 10 when the actual formula is (K * 9) / 5 - 459.67 (yes I did google it and there are a couple of ways to convert Kelvin to Fahrenheit but I found this method to implement to be the easiest).

My new line of code is provided below.

Code: Select all

var temp = Math.round(self.config.units === "celsius" ? res.data.main.temp - 273.15 : res.data.main.temp * 9) / 5 - 459.67,
I did make PoltoS aware of this. It will be verified, he also wanted me to share it here.

Re: OpenWeather Fahrenheit Calcularion Incorrect?

Posted: 30 Jul 2014 11:54
by PoltoS
If OpenWeather always provide data in Kelvin degrees, the correct formula would be:

Code: Select all

var temp = Math.round((res.data.main.temp - 273.15) * (self.config.units === "celsius" ? 1.0 : 1.8) * 10) / 10

Re: OpenWeather Fahrenheit Calcularion Incorrect?

Posted: 04 Aug 2014 11:52
by n0ahg
OpenWeatherMap can provide the temperature in the correct format with no client side conversion required. I had a fix if you want me to submit it to github.

Re: OpenWeather Fahrenheit Calcularion Incorrect?

Posted: 09 Aug 2014 16:55
by PoltoS
Why not. But as far as I see, current version should work OK.