routific 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/routific.rb +14 -5
- data/lib/routific/location.rb +44 -42
- data/lib/routific/route.rb +37 -38
- data/lib/routific/vehicle.rb +46 -44
- data/lib/routific/visit.rb +43 -41
- data/lib/routific/way_point.rb +11 -8
- metadata +2 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea5df053d952f0517202e18e26493a3d986b739
|
4
|
+
data.tar.gz: 5b13d657ff00d3d4bc930a9e9f0191ac1b009226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de46d973cc679f1cfe20d1bd3fdd6a9699ba25fb8bb777da63237a8aa4d6d29315af89b8c348c721ce5a4f05ef361d77c6180688b9241ded509d7acb338d1415
|
7
|
+
data.tar.gz: 0e322fc0e842a8df2335e955ab89a66eb38349e15038aff18f570c09074a6ce7da0b971dd074d34a0880b49beb04d72c7a1d6c0bcad04ee8d45cc9d127f9dd79
|
data/README.md
CHANGED
@@ -63,6 +63,18 @@ Optional arguments in params:
|
|
63
63
|
- shift_end: this vehicle's end shift time (e.g. '17:00'). Default value is 23:59, if not specified.
|
64
64
|
- capacity: the capacity that this vehicle can load
|
65
65
|
|
66
|
+
`routific.setOptions( params )`
|
67
|
+
|
68
|
+
Sets optional options onto the route requests.
|
69
|
+
|
70
|
+
Optional arguments must be one of the following:
|
71
|
+
|
72
|
+
- traffic
|
73
|
+
- min_visits_per_vehicle
|
74
|
+
- balance
|
75
|
+
- min_vehicles
|
76
|
+
- shortest_distance
|
77
|
+
|
66
78
|
`routific.getRoute()`
|
67
79
|
|
68
80
|
Returns the route using the previously provided network, visits and fleet information
|
data/lib/routific.rb
CHANGED
@@ -6,10 +6,11 @@ require_relative './routific/visit'
|
|
6
6
|
require_relative './routific/vehicle'
|
7
7
|
require_relative './routific/route'
|
8
8
|
require_relative './routific/way_point'
|
9
|
+
require_relative './routific/options'
|
9
10
|
|
10
11
|
# Main class of this gem
|
11
12
|
class Routific
|
12
|
-
attr_reader :token, :visits, :fleet
|
13
|
+
attr_reader :token, :visits, :fleet, :options
|
13
14
|
|
14
15
|
# Constructor
|
15
16
|
# token: Access token for Routific API
|
@@ -17,20 +18,27 @@ class Routific
|
|
17
18
|
@token = token
|
18
19
|
@visits = {}
|
19
20
|
@fleet = {}
|
21
|
+
@options = {}
|
20
22
|
end
|
21
23
|
|
22
24
|
# Sets a visit for the specified location using the specified parameters
|
23
25
|
# id: ID of location to visit
|
24
26
|
# params: parameters for this visit
|
25
27
|
def setVisit(id, params={})
|
26
|
-
visits[id] = Visit.new(id, params)
|
28
|
+
visits[id] = RoutificApi::Visit.new(id, params)
|
27
29
|
end
|
28
30
|
|
29
31
|
# Sets a vehicle with the specified ID and parameters
|
30
32
|
# id: vehicle ID
|
31
33
|
# params: parameters for this vehicle
|
32
34
|
def setVehicle(id, params)
|
33
|
-
fleet[id] = Vehicle.new(id, params)
|
35
|
+
fleet[id] = RoutificApi::Vehicle.new(id, params)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sets options with the specified params
|
39
|
+
# params: parameters for these options
|
40
|
+
def setOptions(params)
|
41
|
+
@options = RoutificApi::Options.new(params)
|
34
42
|
end
|
35
43
|
|
36
44
|
# Returns the route using the previously provided visits and fleet information
|
@@ -40,6 +48,7 @@ class Routific
|
|
40
48
|
fleet: fleet
|
41
49
|
}
|
42
50
|
|
51
|
+
data[:options] = options if options
|
43
52
|
Routific.getRoute(data, token)
|
44
53
|
end
|
45
54
|
|
@@ -76,8 +85,8 @@ class Routific
|
|
76
85
|
# Parse the HTTP request response to JSON
|
77
86
|
jsonResponse = JSON.parse(response)
|
78
87
|
|
79
|
-
# Parse the JSON representation into a Route object
|
80
|
-
Route.parse(jsonResponse)
|
88
|
+
# Parse the JSON representation into a RoutificApi::Route object
|
89
|
+
RoutificApi::Route.parse(jsonResponse)
|
81
90
|
rescue => e
|
82
91
|
puts e
|
83
92
|
errorResponse = JSON.parse e.response.body
|
data/lib/routific/location.rb
CHANGED
@@ -1,52 +1,54 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
module RoutificApi
|
2
|
+
# This class represents a location in the network
|
3
|
+
class Location
|
4
|
+
attr_accessor :name, :lat, :lng
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
# Required arguments in params:
|
9
|
+
# lat: Latitude of this location
|
10
|
+
# lng: Longitude of this location
|
11
|
+
#
|
12
|
+
# Optional arguments in params:
|
13
|
+
# name: Name of this location
|
14
|
+
def initialize(params)
|
15
|
+
# Validates the parameters provided
|
16
|
+
validate(params)
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
@lat = params["lat"]
|
19
|
+
@lng = params["lng"]
|
20
|
+
@name = params["name"]
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def ==(another_location)
|
24
|
+
self.name == another_location.name &&
|
25
|
+
self.lat == another_location.lat &&
|
26
|
+
self.lng == another_location.lng
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def to_json(options = nil)
|
30
|
+
as_json(options).to_json
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
# Returns the JSON representation of this object
|
34
|
+
# def to_json(options = nil)
|
35
|
+
def as_json(options = nil)
|
36
|
+
jsonData = {}
|
37
|
+
jsonData["name"] = self.name if self.name
|
38
|
+
jsonData["lat"] = self.lat
|
39
|
+
jsonData["lng"] = self.lng
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
jsonData
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
private
|
45
|
+
# Validates the parameters being provided
|
46
|
+
# Raises an ArgumentError if any of the required parameters is not provided.
|
47
|
+
# Required parameters are: latitude and longitude
|
48
|
+
def validate(params)
|
49
|
+
if(params["lat"].nil? || params["lng"].nil?)
|
50
|
+
raise ArgumentError, "'lat' and 'lng' parameters must be provided"
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
data/lib/routific/route.rb
CHANGED
@@ -1,48 +1,47 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
module RoutificApi
|
2
|
+
# This class represents the resulting route returned by the Routific API
|
3
|
+
class Route
|
4
|
+
attr_reader :status, :fitness, :unserved, :vehicleRoutes
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
# Constructor
|
7
|
+
def initialize(status, fitness, unserved)
|
8
|
+
@status = status
|
9
|
+
@fitness = fitness
|
10
|
+
@unserved = unserved
|
11
|
+
@vehicleRoutes = Hash.new()
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
# Adds a new way point for the specified vehicle
|
15
|
+
def addWayPoint(vehicle_name, way_point)
|
16
|
+
if @vehicleRoutes[vehicle_name].nil?
|
17
|
+
# No previous way point was added for the specified vehicle, so create a new array
|
18
|
+
@vehicleRoutes[vehicle_name] = []
|
19
|
+
end
|
20
|
+
# Adds the provided way point for the specified vehicle
|
21
|
+
@vehicleRoutes[vehicle_name] << way_point
|
18
22
|
end
|
19
|
-
# Adds the provided way point for the specified vehicle
|
20
|
-
@vehicleRoutes[vehicle_name] << way_point
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
class << self
|
25
|
+
# Parse the JSON representation of a route, and return it as a Route object
|
26
|
+
def parse(routeJson)
|
27
|
+
status = routeJson["status"]
|
28
|
+
fitness = routeJson["fitness"]
|
29
|
+
unserved = routeJson["unserved"]
|
30
|
+
route = RoutificApi::Route.new(status, fitness, unserved)
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
way_point = WayPoint.new(location_id, arrival_time, finish_time)
|
40
|
-
route.addWayPoint(vehicle_name, way_point)
|
32
|
+
# Get way points for each vehicles
|
33
|
+
routeJson["solution"].each do |vehicle_name, way_points|
|
34
|
+
# Get all way points for this vehicle
|
35
|
+
way_points.each do |waypoint_info|
|
36
|
+
# Get all information for this way point
|
37
|
+
way_point = RoutificApi::WayPoint.new(waypoint_info)
|
38
|
+
route.addWayPoint(vehicle_name, way_point)
|
39
|
+
end
|
41
40
|
end
|
42
|
-
end
|
43
41
|
|
44
|
-
|
45
|
-
|
42
|
+
# Return the resulting Route object
|
43
|
+
route
|
44
|
+
end
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
data/lib/routific/vehicle.rb
CHANGED
@@ -1,55 +1,57 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
module RoutificApi
|
2
|
+
# This class represents a vehicle in the fleet
|
3
|
+
class Vehicle
|
4
|
+
attr_accessor :id, :start_location, :end_location, :shift_start, :shift_end, :capacity
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
# Required arguments in params:
|
9
|
+
# start_location: start location for this vehicle. Instance of Location
|
10
|
+
#
|
11
|
+
# Optional arguments in params:
|
12
|
+
# end_location: end location for this vehicle. Instance of Location
|
13
|
+
# shift_start: this vehicle's start shift time (e.g. '08:00'). Default value is 00:00, if not specified.
|
14
|
+
# shift_end: this vehicle's end shift time (e.g. '17:00'). Default value is 23:59, if not specified.
|
15
|
+
# capacity: the capacity that this vehicle can load
|
16
|
+
def initialize(id, params)
|
17
|
+
validate(params)
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
@id = id
|
20
|
+
@start_location = RoutificApi::Location.new(params["start_location"])
|
21
|
+
if params["end_location"]
|
22
|
+
@end_location = RoutificApi::Location.new(params["end_location"])
|
23
|
+
end
|
24
|
+
@shift_start = params["shift_start"]
|
25
|
+
@shift_end = params["shift_end"]
|
26
|
+
@capacity = params["capacity"]
|
22
27
|
end
|
23
|
-
@shift_start = params["shift_start"]
|
24
|
-
@shift_end = params["shift_end"]
|
25
|
-
@capacity = params["capacity"]
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def to_json(options=nil)
|
30
|
+
as_json(options).to_json
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
# Returns the JSON representation of this object
|
34
|
+
# def to_json(options = nil)
|
35
|
+
def as_json(options = nil)
|
36
|
+
jsonData = {}
|
37
|
+
jsonData["start_location"] = self.start_location.as_json
|
38
|
+
jsonData["end_location"] = self.end_location.as_json if self.end_location
|
39
|
+
jsonData["shift_start"] = self.shift_start if self.shift_start
|
40
|
+
jsonData["shift_end"] = self.shift_end if self.shift_end
|
41
|
+
jsonData["capacity"] = self.capacity if self.capacity
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
jsonData
|
44
|
+
end
|
44
45
|
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
private
|
48
|
+
# Validates the parameters being provided
|
49
|
+
# Raises an ArgumentError if any of the required parameters is not provided.
|
50
|
+
# Required parameters are: location
|
51
|
+
def validate(params)
|
52
|
+
if params["start_location"].nil?
|
53
|
+
raise ArgumentError, "'start-location' parameter must be provided"
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
data/lib/routific/visit.rb
CHANGED
@@ -1,49 +1,51 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
module RoutificApi
|
2
|
+
# This class represents a location to be visited
|
3
|
+
class Visit
|
4
|
+
attr_reader :id, :start, :end, :duration, :demand, :location
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
# Optional arguments in params:
|
9
|
+
# start: the earliest time for this visit. Default value is 00:00, if not specified.
|
10
|
+
# end: the latest time for this visit. Default value is 23:59, if not specified.
|
11
|
+
# duration: the length of this visit in minutes
|
12
|
+
# demand: the capacity that this visit requires
|
13
|
+
# location: the location of the visit. Instance of Location
|
14
|
+
def initialize(id, params = {})
|
15
|
+
validate(params)
|
16
|
+
@id = id
|
17
|
+
@start = params["start"]
|
18
|
+
@end = params["end"]
|
19
|
+
@duration = params["duration"]
|
20
|
+
@demand = params["demand"]
|
21
|
+
@location = RoutificApi::Location.new(params["location"])
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def to_json(options)
|
25
|
+
as_json(options).to_json
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
# Returns the JSON representation of this object
|
29
|
+
# def to_json(options = nil)
|
30
|
+
def as_json(options = nil)
|
31
|
+
jsonData = {}
|
32
|
+
jsonData["start"] = self.start if self.start
|
33
|
+
jsonData["end"] = self.end if self.end
|
34
|
+
jsonData["duration"] = self.duration if self.duration
|
35
|
+
jsonData["demand"] = self.demand if self.demand
|
36
|
+
jsonData["location"] = self.location.as_json
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
jsonData
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
private
|
42
|
+
# Validates the parameters being provided
|
43
|
+
# Raises an ArgumentError if any of the required parameters is not provided.
|
44
|
+
# Required parameters are: location
|
45
|
+
def validate(params)
|
46
|
+
if params["location"].nil?
|
47
|
+
raise ArgumentError, "'location' parameter must be provided"
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
data/lib/routific/way_point.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
module RoutificApi
|
2
|
+
# This class represents a location to visit in the route
|
3
|
+
class WayPoint
|
4
|
+
attr_reader :location_id, :arrival_time, :finish_time, :location_name
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
# Constructor
|
7
|
+
def initialize(options = {})
|
8
|
+
@location_id = options['location_id']
|
9
|
+
@arrival_time = options['arrival_time']
|
10
|
+
@finish_time = options['finish_time']
|
11
|
+
@location_name = options['location_name']
|
12
|
+
end
|
10
13
|
end
|
11
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: routific
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Kuo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -81,34 +81,6 @@ dependencies:
|
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0.11'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: byebug
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '3.5'
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '3.5'
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: pry-byebug
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - "~>"
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: '2.0'
|
105
|
-
type: :development
|
106
|
-
prerelease: false
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
108
|
-
requirements:
|
109
|
-
- - "~>"
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: '2.0'
|
112
84
|
description: Gem to use Routific API
|
113
85
|
email: asoesilo@live.com
|
114
86
|
executables: []
|