Last active
August 29, 2015 14:01
-
-
Save d4be4st/e97b8bec9f17a5f75e6f to your computer and use it in GitHub Desktop.
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
route = xRoute.get_route(params[:reference_latitude], params[:reference_longitude], params[:finish_latitude], params[:finish_longitude]) # call to xRoute /xroute/rs/XRoute/calculateRoute | |
standard_distance = route['info']['distance'].to_i | |
reachable_objects = xRoute.get_reachable_objects(route) # call to xRoute /xroute/rs/XRoute/searchForReachableObjects | |
parking_places = ParkingPlace.where(deleted: 0, id: reachable_objects.keys) # We get for our own database parking places | |
parking_places.each do |parking_place| | |
parking_place.detour_distance = reachable_objects[parking_place.id.to_s][:detour_time]) #Assign detour distance to parking places | |
end | |
parking_places = xRoute.get_driving_distance(parking_places, params[:reference_latitude], params[:reference_longitude]) # Get driving distances for all parking places | |
parking_places = remove_out_of_reach(params[:driving_time]) # We remove all parking places that are out of reach | |
parking_places = xRoute.remove_too_far_away(parking_places, params[:finish_latitude], params[:finish_longitude], standard_distance) | |
render json: parking_places.to_json |
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
# xRoute.remove_too_far_away | |
def self.remove_too_far_away(parking_places, finish_latitude, finish_longitude, standard_distance) | |
url = URI.parse(CALCULATE_DISTANCE_URL) | |
# ... code to setup http request | |
# we are asking for driving distances from all parking places to finish location | |
driving_distances = JSON.parse(response.body) | |
parking_places_good = [] | |
parking_places.each_with_index do |parking_place,index| | |
if driving_distances['matrixInfo'].present? | |
parking_places_good << parking_place if ( (parking_place.driving_distance[:distance][:value].to_i + driving_distances['matrixInfo'][index]['distance'].to_i - standard_distance.to_i ) < 6000) | |
end | |
end | |
parking_places_good | |
end | |
def self.get_reachable_objects(route) | |
url = URI.parse(CALCULATE_REACHABLE_OBJECTS_URL) | |
# ... code to setup http request | |
res = JSON.parse(response.body) | |
detours = Hash.new | |
if res['reachableObject'].present? | |
res['reachableObject'].each do |ro| | |
detours[ro['object']['id']] = {detour_time: ro['routeInfo']} | |
end | |
end | |
return detours | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment