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).
yahoo_weather
Brian Marshall 13 years ago
parent 2a8a9ebe3e
commit e88d0b42b9
  1. 9
      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')];

Loading…
Cancel
Save