Exemplo n.º 1
0
 def find_route(self, request, *args, **kwargs):
     if request:
         body = json.loads(request.body)
         # print body
         location = str(body['lat']) + ',' + str(body['lng'])
         resp = find_route(location, destination)
         if resp:
             print resp
             return self.create_response(request, {'status': "success"})
Exemplo n.º 2
0
def get_cost(code_pairs, city_data, routes):
  """Calculate the cost of a set of routes."""
  distances = \
    [ utils.find_route(routes, pair[0], pair[1])[2] for pair in code_pairs ]

  cost = 0.0
  rate = 0.35
  for leg in distances:
    cost += leg * rate
    rate -= 0.05
    rate = max(rate, 0.0)

  return cost
Exemplo n.º 3
0
def check_path(code_pairs, city_data, routes):
  """Check whether a list of source-destination pairs is possible."""
  for pair in code_pairs:
    if utils.find_route(routes, pair[0], pair[1]) is None:
      raise ValueError('There is no route from %s to %s.' % pair)
Exemplo n.º 4
0
def get_distance(code_pairs, city_data, routes):
  distance = 0
  for source, dest in code_pairs:
    distance += utils.find_route(routes, source, dest)[2]
  return distance