Windspeed calculation from dark sky API

Hi all, (and probably: Hi Rose and sylumer)

I’ve created a weather forecast from the dark sky API showing temperature highs, lows, sun up, sun down and windspeed in meters per second.

I’d like to re-calculate this to the Beaufort scale of windspeed.

My question:
Would I use a dictionary for that to calculate a value between a and b equals windspeed x BF?
Or if-then statements? (Or even JavaScript?)

Any ideas??

My first thought was just ‘if’ based conditionals as it isn’t a calculation, but a reference value range lookup. However, I then realised that because the Beaufort scale is totally numeric in terms of values and the scale itself is integer values … a dictionary could in fact be used with a repeat loop to make things that much simpler.

This first custom shortcut converts wind speed in m/s into a Beaufort scale rating.

This second custom shortcut asks for a windspeed in m/s, calls the first custom shortcut to carry out the conversion and then displays some information back.

Hope that’s what you were after.

Hi @sylumer, thanks for your help!
I’ll first try to create it myself using a dictionary, and if I get stuck I’ll have a look at your example.

1 Like

it’s been some time since I asked this question, and got your really great help with the solution. I’ve used your m/s to scale method until now!

The only thing is that in the beta of iOS 13 this delivers a weird result:

Let’s say the m/s is 1.93 which should calculate to 2 on the scale.
This used to work.

Now it gives

So it correctly gets to force 2, and then keeps adding the items to the variable.

Any ideas why I’m now getting an array back (looks like that) instead of a single value?

I would guess that the behaviour is different exactly because it is the beta. That’s what’s changed after all.

Can you post a screenshot of how the shortcut looks in whatever version 13/13.1 you are using? I’m not on iOS13 just yet as I need the stability and reliability of iOS12 just now, so I don’t know how this shortcut has changed.

My best guess is it will be something to do with the way the upgrade process has handled the variables. I know iOS13 has fundamentally changed the way it is working with variables, to focus on identifying them within steps rather than requiring additional steps to pass them on. To my mind that seems the most likely place for a bug to have been introduced.

this is a link to it:

I adapted it very slightly, but the error was present in both yours and my versions, checked today.
f.e. I switched a calculation around but that had no effect on the error.

As noted above, I don’t use iOS13 yet. That means links are unusable by me - Shortcuts’ file format has changed. That’s why I asked for a screenshot :man_shrugging:t2:

Here it is, language is Dutch, but should be ok to read.

Looks to me like the retrieval of the Beaufort value at the end has been removed.

oh you’re kidding me…
Will test, and if so buy you a beer some time!

problem is… iOS 13 does not seem to have that…
Looking for solutions, will update

Don’t have it in front of me to test, but I think from memory you should be able to select a “Text” or “Number” block in its place and set it to the variable you want.

I’ve rebuilt a shortcut as a subroutine that works as a string of if-then statements, and that produces the desired result. So for now I’m okay. (And tired of dragging identical blocks in 12 times…)

I like @sylumer’s solution better, it’s more elegant, but as that does not work right now I’m happy with this one.

Did you try what @Kaitlin suggested? It seems logical that having a text/number step with the magic variable in it would be the equivalent of an in-situ get variable.

I’ll test that as well. Will let you know how I got on.

I tried it today, the result is the same is without it there.
It keeps giving me all the 12 results, not just the correct one.

You’re pulling the value of just the variable Beaufort right?

If so, go though and add something to display the values of Beaufort, your speed, and the dictionary value it is checking against on each loop iteration. Then display the value of Beaufort at the very end of the shortcut.

Beaufort should be updated with the new index value when it is greater than the associated windspeed. i.e. it is only ever set equal to a single integer value at any time.

I can’t immediately see anything from the screenshots or what you should have applied that could indicate why Beaufort should contain what sounds more like a dictionary or concatenation of multiple results, rather than a single integer.