Heads-I-Lose

Check-in [c4d0b2bbec]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Calculate wind-type percentages and use to determine win/lose

In other words: done for now. Those are pretty much the changes I
wanted to do. Sure they will be much room for improvements to the code,
but it works!

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | origin/master
Files: files | file ages | folders
SHA3-256: c4d0b2bbecadf5829f13b90b329c63b45e01f53b593c7a89ba1624d3dcb008bf
User & Date: base@atomicules.co.uk 2014-12-05 23:51:43
Context
2014-12-11
22:37
Handle the reverse route

I don't want to have to query OSRM for th ereverse route - it's
pointless. Instead reverse the route we already have - because I don't
actually need a properly ordered reverse route, just a list of
directions and distances.

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
reverse route or normal route is also dependent on time of day
- Don't convert to distances and compass directions in one swoop since
it is easier to reverse the heading angles rather than compass points check-in: 935d1fbeae user: base@atomicules.co.uk tags: origin/master, trunk

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
wanted to do. Sure they will be much room for improvements to the code,
but it works! check-in: c4d0b2bbec user: base@atomicules.co.uk tags: origin/master, trunk

20:43
Housekeeping: Formatting, variable naming consistency, etc

- Get rid of the mixed up mess of CamelCase, underscores, prefixes,
suffixes, abbreviations, full names, etc.
- Make indenting of lists:map functions consistent
- Remove spurious whitespace check-in: 301914a6a1 user: base@atomicules.co.uk tags: origin/master, trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to headsilose.erl.

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
			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 ->







<







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
239














240

241
242
243
244
245
			lists:foldl(
				fun({Distance, _Wind}, Sum) ->
					Distance + Sum
				end,
				0,
				Wind_type)
		end,
		[Headwind_distances, Sidewind_distances, Tailwind_distances]).














	%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).







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>





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).