def test_ten_time_steps(): for i, step in enumerate(gen_steps()): request = [ Person( item['name'], Location(item['start'][0], item['start'][1]), Location(item['end'][0], item['end'][1]), PersonStatus.REQUESTED_VEHICLE) for item in step ] vehicle_location, passengers, dropped_off, picked_up, destinations = time_step_single_vehicle( request, people_service, vehicle_service, map_service ) message = f'Vehicle is at {vehicle_location} with passengers {", ".join(passengers) if passengers else None} | ' if dropped_off: message += f'Dropped off {", ".join(p.name for p in dropped_off)} ' if picked_up: message += f'Picked up {", ".join(p.name for p in picked_up)} ' print(message) if len(destinations) <= 0: break
def person_serialize(dict_obj): pickup = dict_obj['start'] dropoff = dict_obj['end'] p = Person(name=dict_obj['name'], pickup=Location(pickup[0], pickup[1]), dropoff=Location(dropoff[0], dropoff[1]), status=PersonStatus.REQUESTED_VEHICLE) return p
def get_address_location(self, address: str) -> Location: """ Convenience method for converting an address to a Location type :param address: :return: """ result: dict = self._client.geocode(address) x, y = result[0]['geometry']['location'].values() return Location(x, y)
from domain.models import Person, Location, PersonStatus from infrastructure.persistence import InMemPeopleRepository, InMemVehicleRepository, InMemLocationMapRepository people_repo = InMemPeopleRepository() vehicle_repo = InMemVehicleRepository() map_repo = InMemLocationMapRepository() me = Person(name='Alex Arias', pickup=Location(1, 0), dropoff=Location(4, 5), status=PersonStatus.REQUESTED_VEHICLE) def test_inmem_add_person(): people_repo.add(me) def test_inmem_get_person(): repo_me = people_repo.get('Alex Arias') assert repo_me == me def test_in_assertion(): assert me in people_repo.get_all() def test_inmem_remove_person(): people_repo.remove('Alex Arias') assert me not in people_repo.get_all()
def __init__(self, repo: VehicleRepository): self._repo = repo if len(self._repo.get_all()) == 0: self._repo.add(Vehicle('default', None, Location(0, 0)))
def shortest_path_to_destination(self, origin: Location, destination: Location) -> List[Location]: path: List[Tuple[int]] = shortest_paths.shortest_path( self._graph, origin.coordinates, destination.coordinates) return [Location(node[0], node[1]) for node in path]
def test_networkx_gateway_next_destination(): gateway = NetworkXGateway(lattice.grid_2d_graph(10, 10)) origin = Location(0, 0) destinations = [Location(1, 1), Location(2, 5), Location(2, 4)] next_destination = gateway.get_next_destination(origin, destinations) assert next_destination == Location(1, 1)