Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Comment: | Calculate wind-type percentages and use to determine win/lose
In other words: done for now. Those are pretty much the changes I |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | origin/master |
Files: | files | file ages | folders |
SHA3-256: |
c4d0b2bbecadf5829f13b90b329c63b4 |
User & Date: | base@atomicules.co.uk 2014-12-05 23:51:43 |
2014-12-11
| ||
22:37 |
Handle the reverse route
I don't want to have to query OSRM for th ereverse route - it's In order to do this made sense to re-jig some of the functions a bit: - Need date and time at top level, not buried in get_weather since | |
2014-12-05
| ||
23:51 |
Calculate wind-type percentages and use to determine win/lose
In other words: done for now. Those are pretty much the changes I | |
20:43 |
Housekeeping: Formatting, variable naming consistency, etc
- Get rid of the mixed up mess of CamelCase, underscores, prefixes, | |
Changes to headsilose.erl.
︙ | ︙ | |||
84 85 86 87 88 89 90 | io:format("API Might be down~n"), Reason after maybe_quit() end. | < | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | io:format("API Might be down~n"), Reason after maybe_quit() end. date_and_rep(Date) -> {{_Year, _Month, _Day}, {Hours, _Minutes, _Seconds}} = Date, date_and_rep(Date, Hours). date_and_rep(Date, Hours) when Hours < 8 -> Rep = "360", {format_date(Date), Rep}; date_and_rep(Date, Hours) when Hours >= 8, Hours < 19 -> |
︙ | ︙ | |||
132 133 134 135 136 137 138 139 140 141 142 143 144 145 | Found = lists:keyfind(noshell, 1, Args), if Found =:= false -> dont_quit; true -> init:stop() end. build_list_of_wind_directions(Wind_direction) -> %There is only one wind direction, but can build groups of directions that will count as head, side and tail winds Compass = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"], %Quicker dirtier(?) way to do below would be: http://stackoverflow.com/a/6762191/208793 Index = length(lists:takewhile(fun(X) -> X =/= Wind_direction end, Compass))+1, %Since heading is to direction and winds are from, opposite is -2 to +2, or to make it easier to wrap, +14 +18 | > > > > > > | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | Found = lists:keyfind(noshell, 1, Args), if Found =:= false -> dont_quit; true -> init:stop() end. %From: http://www.codecodex.com/wiki/index.php?title=Round_a_number_to_a_specific_decimal_place#Erlang round(Number, Precision) -> P = math:pow(10, Precision), round(Number * P) / P. build_list_of_wind_directions(Wind_direction) -> %There is only one wind direction, but can build groups of directions that will count as head, side and tail winds Compass = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"], %Quicker dirtier(?) way to do below would be: http://stackoverflow.com/a/6762191/208793 Index = length(lists:takewhile(fun(X) -> X =/= Wind_direction end, Compass))+1, %Since heading is to direction and winds are from, opposite is -2 to +2, or to make it easier to wrap, +14 +18 |
︙ | ︙ | |||
232 233 234 235 236 237 238 | lists:foldl( fun({Distance, _Wind}, Sum) -> Distance + Sum end, 0, Wind_type) end, | | > > > > > > > > > > > > > > | > | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | lists:foldl( fun({Distance, _Wind}, Sum) -> Distance + Sum end, 0, Wind_type) end, [Headwind_distances, Sidewind_distances, Tailwind_distances]), Total_distance = Sum_of_headwind_distances + Sum_of_sidewind_distances + Sum_of_tailwind_distances, %Determine which is worse if (Sum_of_headwind_distances > Sum_of_sidewind_distances) and (Sum_of_headwind_distances > Sum_of_tailwind_distances) -> io:format("Heads you lose!~n"); (Sum_of_tailwind_distances > Sum_of_sidewind_distances) and (Sum_of_tailwind_distances > Sum_of_headwind_distances) -> io:format("Tails you win!~n"); (Sum_of_sidewind_distances >= Sum_of_headwind_distances) and (Sum_of_sidewind_distances >= Sum_of_tailwind_distances) -> io:format("It's a draw~n") end, Headwind_percent = round((Sum_of_headwind_distances/Total_distance)*100, 2), Sidewind_percent = round((Sum_of_sidewind_distances/Total_distance)*100, 2), Tailwind_percent = round((Sum_of_tailwind_distances/Total_distance)*100, 2), io:format("~w% Headwind~n~w% Sidewind~n~w% Tailwind~n", [Headwind_percent, Sidewind_percent, Tailwind_percent]), % io:format("Direction: ~s~nSpeed: ~s mph~nGust: ~s mph~nWeather type: ~s~nTemperature: ~s deg C~n", [Direction, Speed, Gust, Weather_type, Temperature]). %Need to read API key from file readapikey() -> {_Status, Key} = file:read_file(os:getenv("HOME") ++ "/.datapoint"), string:strip(erlang:binary_to_list(Key),right,$\n). |