Skip to content

Instantly share code, notes, and snippets.

@d4be4st
Last active August 29, 2015 14:01
Show Gist options
  • Save d4be4st/e97b8bec9f17a5f75e6f to your computer and use it in GitHub Desktop.
Save d4be4st/e97b8bec9f17a5f75e6f to your computer and use it in GitHub Desktop.

Revisions

  1. d4be4st revised this gist May 13, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile2.rb
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ def self.remove_too_far_away(parking_places, finish_latitude, finish_longitude,
    parking_places_good
    end

    def get_reachable_objects(route)
    def self.get_reachable_objects(route)
    url = URI.parse(CALCULATE_REACHABLE_OBJECTS_URL)
    # ... code to setup http request
    res = JSON.parse(response.body)
  2. d4be4st revised this gist May 13, 2014. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions gistfile2.rb
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,14 @@ def self.remove_too_far_away(parking_places, finish_latitude, finish_longitude,
    end

    def 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
  3. d4be4st revised this gist May 13, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile2.rb
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,7 @@ def self.remove_too_far_away(parking_places, finish_latitude, finish_longitude,
    end

    parking_places_good
    end

    def get_reachable_objects(route)
    end
  4. d4be4st created this gist May 8, 2014.
    12 changes: 12 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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
    16 changes: 16 additions & 0 deletions gistfile2.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # 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