Skip to content

Commit

Permalink
Walking duration added to travel time service object; distance remove…
Browse files Browse the repository at this point in the history
…d from object for all travel modes
  • Loading branch information
dp-daly committed Oct 18, 2024
1 parent 2ae7347 commit 351763e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions app/decorators/school_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class SchoolDecorator < OrganisationDecorator
attribute :transit_travel_duration
attribute :transit_travel_distance
attribute :walk_travel_duration
attribute :drive_travel_duration
attribute :drive_travel_distance

def formatted_inspection_date
return "" if last_inspection_date.blank?
Expand Down
6 changes: 4 additions & 2 deletions app/services/placements/travel_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def call

DRIVE_TRAVEL_MODE = "DRIVE".freeze
TRANSIT_TRAVEL_MODE = "TRANSIT".freeze
WALK_TRAVEL_MODE = "WALK".freeze

def routes_client
@routes_client ||= Google::RoutesApi.new
Expand All @@ -22,16 +23,17 @@ def routes_client
def combine_destinations_with_travel_data
drive_travel_data = travel_data(travel_mode: DRIVE_TRAVEL_MODE)
transit_travel_data = travel_data(travel_mode: TRANSIT_TRAVEL_MODE)
walk_travel_data = travel_data(travel_mode: WALK_TRAVEL_MODE)

destinations.map.with_index do |destination, index|
drive_travel_datum = drive_travel_data.find { |datum| datum["destinationIndex"] == index }
transit_travel_datum = transit_travel_data.find { |datum| datum["destinationIndex"] == index }
walk_travel_datum = walk_travel_data.find { |datum| datum["destinationIndex"] == index }

destination.assign_attributes(
drive_travel_duration: drive_travel_datum.dig("localizedValues", "duration", "text"),
drive_travel_distance: drive_travel_datum.dig("localizedValues", "distance", "text"),
transit_travel_duration: transit_travel_datum.dig("localizedValues", "duration", "text"),
transit_travel_distance: transit_travel_datum.dig("localizedValues", "distance", "text"),
walk_travel_duration: walk_travel_datum.dig("localizedValues", "duration", "text"),
)
end

Expand Down
3 changes: 1 addition & 2 deletions config/analytics_blocklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ shared:
- locked_at
:schools:
- transit_travel_duration
- transit_travel_distance
- walk_travel_duration
- drive_travel_duration
- drive_travel_distance
:school_contacts:
- name
- email_address
Expand Down
5 changes: 3 additions & 2 deletions spec/decorators/school_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
subject(:school) { build(:school).decorate }

it {
expect(school).to have_attributes(drive_travel_duration: nil, drive_travel_distance: nil,
transit_travel_duration: nil, transit_travel_distance: nil)
expect(school).to have_attributes(drive_travel_duration: nil,
transit_travel_duration: nil,
walk_travel_duration: nil)
}
end

Expand Down
3 changes: 1 addition & 2 deletions spec/services/placements/travel_time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
it "returns the school collection, with the travel data appended" do
results = service
expect(results.pluck(:drive_travel_duration)).to eq ["36 mins", "42 mins", "46 mins"]
expect(results.pluck(:drive_travel_distance)).to eq ["17.5 mi", "20 mi", "22 mi"]
expect(results.pluck(:transit_travel_duration)).to eq ["36 mins", "42 mins", "46 mins"]
expect(results.pluck(:transit_travel_distance)).to eq ["17.5 mi", "20 mi", "22 mi"]
expect(results.pluck(:walk_travel_duration)).to eq ["36 mins", "42 mins", "46 mins"]
end

it "returns the school collection, sorted by travel duration" do
Expand Down

0 comments on commit 351763e

Please sign in to comment.