Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
| Comment: | Add basic implementation for selecting between route geometries
Not a great implementation, but it works. If no route geometry choice is |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk | refs/stash |
| Files: | files | file ages | folders |
| SHA3-256: |
6807958aadf3a1b312feef694c3f3dae |
| User & Date: | base@atomicules.co.uk 2014-12-17 22:46:39 |
|
2014-12-26
| ||
| 12:40 | WIP on osrm: 2a14782 Add basic implementation for selecting between route geometries Leaf check-in: 6463b2f68f user: base@atomicules.co.uk tags: refs/stash, trunk | |
| 12:40 | index on osrm: 2a14782 Add basic implementation for selecting between route geometries check-in: 8438b5c356 user: base@atomicules.co.uk tags: refs/stash, trunk | |
|
2014-12-17
| ||
| 22:46 |
Add basic implementation for selecting between route geometries
Not a great implementation, but it works. If no route geometry choice is | |
|
2014-12-14
| ||
| 21:54 | Remove some redundant comments check-in: 0c4224822a user: base@atomicules.co.uk tags: origin/master, trunk | |
Changes to headsilose.erl.
1 2 3 4 5 |
-module(headsilose).
-export([get_locations/0, get_locations/1, headsilose/1]).
-include_lib("xmerl/include/xmerl.hrl").
-import(weather_types, [weather_type/1]).
-import(polyline, [decode/1]).
| | | 1 2 3 4 5 6 7 8 9 10 11 12 13 |
-module(headsilose).
-export([get_locations/0, get_locations/1, headsilose/1]).
-include_lib("xmerl/include/xmerl.hrl").
-import(weather_types, [weather_type/1]).
-import(polyline, [decode/1]).
-import(osrm, [read_route/1]).
%Supply a direction and location and work out if head wind or not
%For now "know the location id" upfront, but ideally need to search for it at some point or present a choice.
%Initially based on: http://pragdave.pragprog.com/pragdave/2007/04/a_first_erlang_.html
-define(BASE_URL,
|
| ︙ | ︙ | |||
227 228 229 230 231 232 233 | sidewind; Tailwind -> tailwind end. %Something like that? | > > > > > | > > > > | | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
sidewind;
Tailwind ->
tailwind
end.
%Something like that?
%First two for command line usage
headsilose([Location]) ->
headsilose_(Location);
headsilose([Location, Route_choice]) ->
headsilose_(Location, Route_choice).
headsilose_(Location) ->
%If route choice not specified default to default!
%The other choice is "alternative_geometries", for now I think there is only ever one alternative so pick this first.
headsilose_(Location, "route_geometry").
headsilose_(Location, Route_choice) ->
Date_today = erlang:localtime(),
{ Date_formatted, Rep } = date_and_rep(Date_today),
{Direction, Speed, Gust, Weather, Temperature} = get_weather(Location, { Date_formatted, Rep }),
Weather_type = weather_types:weather_type(erlang:list_to_integer(Weather)),
[Headwinds, Sidewinds, Tailwinds] = build_list_of_wind_directions(Direction),
{_Checksum, Polyline} = osrm:read_route(Route_choice),
Polyline_decoded = polyline:decode(Polyline),
Distances_and_headings_list = convert_lats_longs_to_distance_heading(Polyline_decoded),
%A better representation than 360 or 1080 would be better now this is used here as well.
Journey = if Rep =:= "360" ->
journey(Distances_and_headings_list);
Rep =:= "1080" ->
reverse_journey(Distances_and_headings_list)
|
| ︙ | ︙ |
Changes to osrm.erl.
1 | -module(osrm). | | | 1 2 3 4 5 6 7 8 9 | -module(osrm). -export([get_route/1, get_route/2, read_route/1]). -import(polyline, [decode/1]). %https://github.com/Project-OSRM/osrm-backend/wiki/Server-api %For now, get weather for one location (probably good enough as relatively short distances weather wise; ultimately consider time as well?) %To get lats and longs could also do a query for here: http://www.uk-postcodes.com/ (json again) -define(BASE_URL, |
| ︙ | ︙ | |||
34 35 36 37 38 39 40 |
io:format("API Might be down~n"),
Reason
after
maybe_quit()
end.
| | > | > > > > > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
io:format("API Might be down~n"),
Reason
after
maybe_quit()
end.
read_route(Route_choice) ->
{_Status, Route} = file:read_file(os:getenv("HOME") ++ "/.headsilose_route"),
%Use jiffy
%http://www.snip2code.com/Snippet/51463/how-to-support-chinese-in-http-request-b/
{ Props } = jiffy:decode(Route),
Route_geometry = if Route_choice =:= "route_geometry" ->
proplists:get_value(binary:list_to_bin(Route_choice), Props);
Route_choice =:= "alternative_geometries" ->
%hd only if alternative though!
%for now I think there is only ever one alternative so that is why we pick hd
hd(proplists:get_value(binary:list_to_bin(Route_choice), Props))
end,
%That is all for now? Because...
%And these don't seem to actually be returned, hence having to go down the route of polyline decoding
%Route_Instructions = proplists:get_value(<<"route_instructions">>, Props),
%Total_Distance = proplists:get_value(<<"total_distance">>, proplists:get_value(<<"route_summary">>, Props)),
%And need to figure out how to get nested values. I.e like xpath. Just nest the queries? Nope that doesn't work
%Like so:
{Hint_data} = proplists:get_value(<<"hint_data">>, Props),
|
| ︙ | ︙ |