Skip to content

Commit

Permalink
Reactivate poyline generation for geojsons
Browse files Browse the repository at this point in the history
  • Loading branch information
senhalil committed Oct 12, 2021
1 parent b7fbc60 commit a95d4f3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
6 changes: 3 additions & 3 deletions api/v01/entities/vrp_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ module VrpConfiguration
end

params :vrp_request_restitution do
# TODO : when we find a good way to return polylines in geojson result, add authorized values here
# (we do not want users to send :polylines, :encoded_polylines for now)
optional(:geometry, type: Array[Symbol], default: [],
coerce_with: ->(value) { GeometryType.type_cast(value) },
desc: 'Specifies the geometry structures to be returned. Can be a subset of `[partitions]` or a boolean value to output all or no geometry. Polylines and encoded_polylines are not compatible.')
desc: ENV['OPTIM_GENERATE_GEOJSON_POLYLINES'] ?
'Specifies the geometry structures to be returned. Can be a subset of `[polylines encoded_polylines partitions]` or a boolean value to output all or no geometry. Polylines and encoded_polylines are not compatible together.' :
'Specifies the geometry structures to be returned. Can be `partitions` to generate geometry structure for each partition or `true` for generating the geometry structure under each route.')
optional(:geometry_polyline, type: Boolean, documentation: { hidden: true }, desc: '[DEPRECATED] Use geometry instead, with :polylines or :encoded_polylines')
optional(:intermediate_solutions, type: Boolean, desc: 'Return intermediate solutions if available')
optional(:csv, type: Boolean, desc: 'The output is a CSV file if you do not specify api format')
Expand Down
3 changes: 1 addition & 2 deletions lib/output_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ def self.generate_geometry(solution)

geojson[:partitions] = generate_partitions_geometry(result) if expected_geometry.include?(:partitions)
geojson[:points] = generate_points_geometry(result)
# TODO : re-activate this function call when we find a good way to return polylines in result
# geojson[:polylines] = generate_polylines_geometry(result) if expected_geometry.include?(:polylines)
geojson[:polylines] = generate_polylines_geometry(result) if expected_geometry.include?(:polylines) && ENV['OPTIM_GENERATE_GEOJSON_POLYLINES']
geojson
}
end
Expand Down
6 changes: 2 additions & 4 deletions models/types/geometry_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ def self.type_cast(value)
if value.is_a?(FalseClass)
[]
elsif value.is_a?(TrueClass)
# ALL_TYPES
%i[polylines encoded_polylines] # ensures old behaviour is respected when geometry is true
ALL_TYPES
elsif value.is_a?(Array)
to_return = []
value.each{ |geometry_type|
unless ALL_TYPES.include?(geometry_type.to_sym)
raise ArgumentError.new("Invalid geometry value: #{geometry_type}")
end

# to_return << geometry_type.to_sym
to_return << geometry_type.to_sym unless %i[polylines encoded_polylines].include?(geometry_type.to_sym)
to_return << geometry_type.to_sym
}

if (to_return & [:polylines, :encoded_polylines]).size == 2
Expand Down
6 changes: 0 additions & 6 deletions test/api/v01/output_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,6 @@ def test_geojsons_returned
refute(result['geojsons'].first['partitions'].key?('work_day'))
# points should always be returned
refute_empty(result['geojsons'].first['points'])

# TODO : remove when returning polylines is more performant and we allow this field in geometry :
vrp[:configuration][:restitution] = { geometry: [:partitions, :polylines] }
@job_id = submit_vrp api_key: 'ortools', vrp: vrp
result = wait_status @job_id, 'completed', api_key: 'ortools'
refute(result['geojsons'].first.key?('polylines'))
end

skip 'Remaining part of this test is skipped because at the moment POST does not return the same result as GET ' \
Expand Down
10 changes: 4 additions & 6 deletions test/api/v01/vrp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,12 @@ def test_ask_for_geometry
case case_index
when 0
assert_empty services_vrps.first[:vrp].restitution_geometry
when 1
assert_equal %i[polylines], services_vrps.first[:vrp].restitution_geometry
when 1 || 5 || 8
assert_equal %i[polylines partitions], services_vrps.first[:vrp].restitution_geometry
when 2
assert_equal %i[encoded_polylines], services_vrps.first[:vrp].restitution_geometry
when 5 || 8
assert_equal %i[partitions], services_vrps.first[:vrp].restitution_geometry
assert_equal %i[encoded_polylines partitions], services_vrps.first[:vrp].restitution_geometry
when 3 || 4
assert_empty services_vrps.first[:vrp].restitution_geometry
assert_equal %i[polylines], services_vrps.first[:vrp].restitution_geometry
when 7
assert_equal %i[partitions], services_vrps.first[:vrp].restitution_geometry
end
Expand Down

0 comments on commit a95d4f3

Please sign in to comment.