Last active
August 29, 2015 14:20
-
-
Save Jylanthas/6f3d6b4b840da703c4d3 to your computer and use it in GitHub Desktop.
routific test
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
require 'routific' | |
require 'json' | |
# Set the Routific API token | |
Routific.setToken('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfaWQiOiI1NTIwN2Q2MTRiMzYyMjBhMDAwYzhlNjEiLCJpYXQiOjE0MjgxOTI2NTl9.gzapZ2hLNwGxGBNUaXJX6xv4osfz4nPUu0KzdhwMm0s') | |
def main | |
test1 | |
# test2 | |
end | |
def test2 | |
trip_props = { | |
id: t.id, | |
arrive_by: t.arrive_by, | |
pickup: { | |
latlng: t.pickup.latlng.csv_point_str | |
}, | |
dropoff: { | |
latlng: t.dropoff.latlng.csv_point_str | |
}, | |
user: { | |
name: t.user.full_name | |
} | |
} | |
avg_by_user = Trip.fulfilled. | |
where { arrive_by > 2.weeks.ago }. | |
reduce(Hash.new(0)) { |h, t| | |
h[t.user.full_name] += t.arrive_by.unix | |
} | |
# group_by { |t| | |
# t.user.full_name | |
# } | |
avg_by_user.each { |name,t_unix_sum| | |
#puts name, t_unix_sum / | |
} | |
puts JSON.pretty_generate avg_by_user | |
end | |
# Fetch the demo data and parse it to JSON | |
def test1 | |
network = { | |
"stop_1" => { | |
"name" => "Bus Stop @ Clay St & Van Ness (SW Corner)", | |
"lat" => 37.78497950946977, | |
"lng" => -122.42141685576958 | |
}, | |
"stop_2" => { | |
"name" => "Bus Stop @ 24th St & Valencia St (Valencia Farmers Market)", | |
"lat" => 37.74943967125433, | |
"lng" => -122.4194953139052 | |
}, | |
"stop_3" => { | |
"name" => "3215 Cesar Chavez St", | |
"lat" => 37.747813, | |
"lng" => -122.42141685576958 | |
}, | |
"stop_4" => { | |
"name" => "Hillsdale & Glendora", | |
"lat" => 37.53297200000001, | |
"lng" => -122.32666300000001 | |
}, | |
"stop_5" => { | |
"name" => "3000 Sand Hill Rd", | |
"lat" => 37.42837828801787, | |
"lng" => -122.20021340019768 | |
}, | |
"stop_6" => { | |
"name" => "3333 Coyote Hill Rd", | |
"lat" => 37.39789930850007, | |
"lng" => -122.1550005276009 | |
}, | |
"depot" => { | |
"name" => "Elizar's Pad, Oakland, CA", | |
"lat" => 37.806396, | |
"lng" => -122.278225 | |
} | |
} | |
visits = { | |
"stop_2" => { }, | |
"stop_5" => { }, | |
"stop_4" => { }, | |
"stop_3" => { }, | |
"stop_1" => { | |
# "start" => "9:00", | |
# "end" => "12:00", | |
# "duration" => 10 | |
}, | |
"stop_6" => { }, | |
} | |
fleet = { | |
"vehicle_1" => { | |
"start-location" => "depot"#, | |
# "end-location" => "stop_6", | |
# "shift-start" => "6:00", | |
# "shift-end" => "9:00" | |
} | |
} | |
data = { | |
network: network, | |
visits: visits, | |
fleet: fleet | |
} | |
# Get the route | |
route = Routific.getRoute(data) | |
puts route | |
puts JSON.pretty_generate route.vehicleRoutes | |
puts JSON.pretty_generate route | |
end | |
main() |
raywu
commented
Apr 29, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment