Don't laugh at my code if you can easily see how it could be more efficiently written!
I did my best.
So here's the scenario. I am using an openweathermap.org API to pull in the weather data, specifically the wind direction and speed. The wind direction comes back from them as the degrees of a circle, so 360 is the same as zero which would be North (N) as well as the first 11.25 degrees, 180 would be due south, 45 degrees NE, and 90 degrees E. I wanted to use the appropriate abbreviation based on the degree so I did some research and I think I got it!
It took me all evening as I have never used an array, and not real familiar with math functions.
I took some javascript i found and figured out how to make it work in xbasic...
Again, what this does is display the right abbreviation based on the returned json data in the api call to openweathermaps.org.
I thought I might share...and if you do see a way to make it better let me know - it was my first stab at this!
The variable "purl" is a concatenated field to include the required URL with the lat & lon fields and my appid as required by the API
Screenshot shows the test UXweather.JPG made to build it
I did my best.
So here's the scenario. I am using an openweathermap.org API to pull in the weather data, specifically the wind direction and speed. The wind direction comes back from them as the degrees of a circle, so 360 is the same as zero which would be North (N) as well as the first 11.25 degrees, 180 would be due south, 45 degrees NE, and 90 degrees E. I wanted to use the appropriate abbreviation based on the degree so I did some research and I think I got it!
It took me all evening as I have never used an array, and not real familiar with math functions.
I took some javascript i found and figured out how to make it work in xbasic...
Again, what this does is display the right abbreviation based on the returned json data in the api call to openweathermaps.org.
I thought I might share...and if you do see a way to make it better let me know - it was my first stab at this!
The variable "purl" is a concatenated field to include the required URL with the lat & lon fields and my appid as required by the API
Code:
function weathercall as c (e as p) 'debug(1) dim weathercall as c dim myresponse as p dim purl as c purl = e._currentRowDataNew.concat_coordinates myresponse = http_get(purl) dim pp as p pp = json_parse(myresponse.body,.t.) e.control.wind_speed = pp.wind.speed e.control.deg = pp.wind.deg dim num as n dim val as n dim mydir as c dim mydir2 as c dim numoff as n num = pp.wind.deg numoff = (num - 11.25)/22.5 val= round(numoff,0) mydir = abs(val) dim arr[16] as p arr[1].0="N" arr[1].1="NNE" arr[1].2="NE" arr[1].3="ENE" arr[1].4="E" arr[1].5="ESE" arr[1].6="SE" arr[1].7="SSE" arr[1].8="S" arr[1].9="SSW" arr[1].10="SW" arr[1].11="WSW" arr[1].12="W" arr[1].13="WNW" arr[1].14="NW" arr[1].15="NNW" mydir2 = arr.dump_properties(mydir) e.control.wind_direction = mydir2 end function
Comment