-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* livebook working * write to tmp dir * use name for bus * cleanup * remove file * change puts to inspect * readme * add dates * rename file for consistency * ...
- Loading branch information
1 parent
0f01196
commit 46ebf9e
Showing
6 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# USING LIVEBOOK | ||
|
||
1. [Download, install, and run Livebook](https://livebook.dev/#install) | ||
2. [Start the app and connect to it](https://fly.io/docs/elixir/advanced-guides/interesting-things-with-livebook/#connect-to-your-project) | ||
3. Click "Open" at the top right to open the relevant Livebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- 2024-06-11T08:00 | ||
- 2024-06-12T12:00 | ||
- 2024-06-13T16:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Evaluate Open Trip Planner | ||
|
||
## Section | ||
|
||
```elixir | ||
defmodule EvaluateOpenTripPlanner.Helpers do | ||
@moduledoc false | ||
|
||
def attach_itineraries_to_plan(%{"from" => from, "to" => to} = plan, datetime) do | ||
itineraries = | ||
plan(from, to, depart_at: datetime) | ||
|> Kernel.elem(1) | ||
|> itineraries_to_strings() | ||
|
||
plan | ||
|> Map.put("datetime", Timex.format!(datetime, "%FT%H:%M", :strftime)) | ||
|> Map.put("itineraries", itineraries) | ||
end | ||
|
||
defp address_to_named_position(address) do | ||
address | ||
|> LocationService.geocode() | ||
|> Kernel.elem(1) | ||
|> List.first() | ||
|> TripPlan.NamedPosition.new() | ||
end | ||
|
||
defp itineraries_to_strings(itineraries) when is_binary(itineraries) do | ||
[itineraries] | ||
end | ||
|
||
defp itineraries_to_strings(itineraries) when is_list(itineraries) do | ||
Enum.map(itineraries, &itinerary_to_string/1) | ||
end | ||
|
||
defp itinerary_to_string(itinerary) do | ||
Enum.map(itinerary.legs, &leg_to_string/1) | ||
end | ||
|
||
defp leg_to_string(%{description: "WALK"} = leg) do | ||
"#{leg.description} FROM #{leg.from.name} TO #{leg.to.name}" | ||
end | ||
|
||
defp leg_to_string(%{description: "BUS"} = leg) do | ||
"TAKE #{leg.name} #{leg.description} FROM #{leg.from.name} TO #{leg.to.name}" | ||
end | ||
|
||
defp leg_to_string(leg) do | ||
"TAKE #{leg.long_name} #{leg.description} FROM #{leg.from.name} TO #{leg.to.name}" | ||
end | ||
|
||
defp plan(from, to, opts) do | ||
TripPlan.Api.OpenTripPlanner.plan( | ||
address_to_named_position(from), | ||
address_to_named_position(to), | ||
opts | ||
) | ||
end | ||
end | ||
|
||
alias EvaluateOpenTripPlanner.Helpers | ||
``` | ||
|
||
```elixir | ||
Application.start(:yamerl) | ||
|
||
write_path = | ||
System.tmp_dir!() | ||
|> Path.join("itineraries.yml") | ||
|> IO.inspect() | ||
|
||
datetimes = | ||
File.cwd!() | ||
|> Path.join("/livebooks/datetimes.yml") | ||
|> YamlElixir.read_from_file!() | ||
|> Enum.map(fn datetime -> | ||
datetime | ||
|> Timex.parse!("%Y-%m-%dT%H:%M", :strftime) | ||
|> Timex.to_datetime("America/New_York") | ||
end) | ||
|
||
plans = | ||
File.cwd!() | ||
|> Path.join("/livebooks/plans.yml") | ||
|> YamlElixir.read_from_file!() | ||
|> Enum.map(fn plan -> | ||
Enum.map(datetimes, fn datetime -> | ||
Helpers.attach_itineraries_to_plan(plan, datetime) | ||
end) | ||
end) | ||
|> List.flatten() | ||
|
||
yaml = Ymlr.document!(plans) | ||
|
||
File.write!(write_path, yaml) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
- name: Origin between two subway lines | ||
from: 115 College Ave, Somerville, MA 02144 | ||
to: Tremont St & Park Street &, Winter St, Boston, MA 02108 | ||
- name: Origin along a bus route & walkable to station | ||
from: 7 Walk Hill St, Jamaica Plain, MA 02130 | ||
to: 393 Massachusetts Ave, Boston, MA 02118 | ||
- name: Parallel subway & commuter rail | ||
from: 186 Canal St, Boston, MA 02114 | ||
to: Commercial St &, Pleasant St, Malden, MA 02148 | ||
- name: Walking-only itineraries | ||
from: 700 Atlantic Ave, Boston, MA 02110 | ||
to: 630 Washington St, Boston, MA 02111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters