Viewing 5 replies - 1 through 5 (of 5 total)
  • If we take a look at the Yahoo! Weather API there you can see that Beaufort Scale isn’t available:

    speed: wind speed, in the units specified in the speed attribute of the yweather:units element (mph or kph). (integer)

    Since the plugin doesn’t have implemented it you must do it manually on your own. If you open alfie.weather.js you can see that wind direction is transformed from integer values into the string orientation:

    var wd = result.wind.direction;
                    if (wd >= 348.75 && wd <= 360) {
                        wd = "N"
                    }
                    if (wd >= 0 && wd < 11.25) {
                        wd = "N"
                    }
                    if (wd >= 11.25 && wd < 33.75) {
                        wd = "NNE"
                    }
                    if (wd >= 33.75 && wd < 56.25) {
                        wd = "NE"
                    }
                    if (wd >= 56.25 && wd < 78.75) {
                        wd = "ENE"
                    }
                    if (wd >= 78.75 && wd < 101.25) {
                        wd = "E"
                    }
                    if (wd >= 101.25 && wd < 123.75) {
                        wd = "ESE"
                    }
                    if (wd >= 123.75 && wd < 146.25) {
                        wd = "SE"
                    }
                    if (wd >= 146.25 && wd < 168.75) {
                        wd = "SSE"
                    }
                    if (wd >= 168.75 && wd < 191.25) {
                        wd = "S"
                    }
                    if (wd >= 191.25 && wd < 213.75) {
                        wd = "SSW"
                    }
                    if (wd >= 213.75 && wd < 236.25) {
                        wd = "SW"
                    }
                    if (wd >= 236.25 && wd < 258.75) {
                        wd = "WSW"
                    }
                    if (wd >= 258.75 && wd < 281.25) {
                        wd = "W"
                    }
                    if (wd >= 281.25 && wd < 303.75) {
                        wd = "WNW"
                    }
                    if (wd >= 303.75 && wd < 326.25) {
                        wd = "NW"
                    }
                    if (wd >= 326.25 && wd < 348.75) {
                        wd = "NNW"
                    }

    In a similar way you can convert km/h into the bft.
    Add variable (var ws = result.units.speed;) Convert integer values into the bft with if statement(according to Beaufort scale) and replace
    .replace(/{{speed_unit}}/ig, result.units.speed)
    with
    .replace(/{{speed_unit}}/ig, ws)

    It should work in this way.

    Thread Starter jeroen733

    (@jeroen733)

    Hi CroModder,

    Thanks for your reply. I changed the values like this, is that correct?

    var ws = result.units.speed;
    if (ws >= 0.00 && ws <= 0.99) {
    ws = "0 bft."
    }
    if (ws >= 1.00 && ws < 4.99) {
    ws = "1 bft."
    }
    if (ws >= 5.01 && ws < 11.99) {
    ws = "2 bft."
    }
    if (ws >= 12.00 && ws < 19.99) {
    ws = "3 bft."
    }
    if (ws >= 20.00 && ws < 28.99) {
    ws = "4 bft."
    }
    if (ws >= 29.00 && ws < 38.99) {
    ws = "5 bft."
    }
    if (ws >= 39.00 && ws < 49.99) {
    ws = "6 bft."
    }
    if (ws >= 50.00 && ws < 61.99) {
    ws = "7 bft."
    }
    if (ws >= 62.00 && ws < 74.99) {
    ws = "8 bft."
    }
    if (ws >= 75.00 && ws < 88.99) {
    ws = "9 bft."
    }
    if (ws >= 89.00 && ws < 102.99) {
    ws = "10 bft."
    }
    if (ws >= 103.00 && ws < 117.99) {
    ws = "11 bft."
    }
    if (ws >= 118.00 && ws < 200.00) {
    ws = "12 bft."
    }

    Then I was wondering where to change:
    .replace(/{{speed_unit}}/ig, result.units.speed)
    with
    .replace(/{{speed_unit}}/ig, ws)

    Can you help me with that?

    Maybe you didn’t understand me because you don’t change values that I posted here. You need to add new variable and then store in it value depending of result.units.speed value. But anyway, the code you provided should be ok.

    The

    .replace(/{{speed_unit}}/ig, result.units.speed)

    is located also in alfie.weather.js.
    I will try to implement this when I grab some time and let you know if i succeeded.

    Plugin Author appcuarium

    (@appcuarium)

    Hi,

    We will try to find a more permanent solution to this.

    Hang in there 🙂

    Best regards.
    The Alfie Team

    Hi,
    I’ve tried to change both. Both wind direction and wind speed. Replaced NW with NV etc in alfie.weather.js, and added the code for displaying wind speed according Beaufort scale. But I see no difference.

    Regards
    Trond

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘change wind speed to bft’ is closed to new replies.