From e88d0b42b9c7bfef100b00c49e17e9e3a51c1743 Mon Sep 17 00:00:00 2001 From: Brian Marshall Date: Fri, 9 Dec 2011 22:38:34 -0800 Subject: [PATCH] Convert wind degrees to compass direction Yahoo supplies the wind direction as degrees from north, but we need to convert that into a human-readable compass direction. This converts it into one of 8 directions (N, NE, E, etc). --- src/extension.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/extension.js b/src/extension.js index 6406a8c..9c5584d 100644 --- a/src/extension.js +++ b/src/extension.js @@ -447,6 +447,11 @@ WeatherMenuButton.prototype = { return days[this.parse_day(abr)]; }, + get_compass_direction: function(deg) { + let directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; + return _(directions[Math.round(deg / 45)]); + }, + load_json_async: function(url, fun) { let here = this; let session = new Soup.SessionAsync(); @@ -506,7 +511,7 @@ WeatherMenuButton.prototype = { let humidity = weather.get_object_member('atmosphere').get_string_member('humidity') + ' %'; let pressure = weather.get_object_member('atmosphere').get_string_member('pressure'); let pressure_unit = weather.get_object_member('units').get_string_member('pressure'); - let wind_direction = weather.get_object_member('wind').get_string_member('direction'); + let wind_direction = this.get_compass_direction(weather.get_object_member('wind').get_string_member('direction')); let wind = weather.get_object_member('wind').get_string_member('speed'); let wind_unit = weather.get_object_member('units').get_string_member('speed'); let iconname = this.get_weather_icon_safely(weather_c.get_string_member('code')); @@ -523,7 +528,7 @@ WeatherMenuButton.prototype = { this._currentWeatherTemperature.text = temperature + ' ' + this.unit_to_unicode(); this._currentWeatherHumidity.text = humidity; this._currentWeatherPressure.text = pressure + ' ' + pressure_unit; - this._currentWeatherWind.text = (wind_direction ? wind_direction + ' ' : '') + wind + ' ' + wind_unit; + this._currentWeatherWind.text = (wind_direction && wind > 0 ? wind_direction + ' ' : '') + wind + ' ' + wind_unit; // Refresh forecast let date_string = [_('Today'), _('Tomorrow')];