Skip to content

main

Module: Parking Lot Application.

parking_lot_app(num_entrance_panels=2, num_exit_panels=2, num_display_boards=1, find_parking_spot_strategy='nearest')

Initialize parking lot app.

Parameters:

Name Type Description Default
num_entrance_panels int

Number of entrance panels

2
num_exit_panels int

Number of exit panels

2
Source code in parking_lot/src/main.py
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@app.command()
def parking_lot_app(
    num_entrance_panels: Annotated[
        int, typer.Argument(help="Number of entrance panels")
    ] = 2,
    num_exit_panels: Annotated[
        int, typer.Argument(help="Number of entrance panels")
    ] = 2,
    num_display_boards: Annotated[
        int, typer.Argument(help="Number of dispaly boards")
    ] = 1,
    find_parking_spot_strategy: Annotated[
        str,
        typer.Argument(
            help="first: Find first free spot, nearest: Find nearest free spot to entrance"
        ),
    ] = "nearest",
):
    """
    Initialize parking lot app.

    Args:
        num_entrance_panels (int): Number of entrance panels
        num_exit_panels (int): Number of exit panels
    """

    parking_spot_counts = {
        ParkingSpotType.MOTORBIKE: 50,
        ParkingSpotType.COMPACT: 25,
        ParkingSpotType.LARGE: 15,
        ParkingSpotType.HANDICAPPED: 5,
    }

    parking_spot_rates_per_sec = {
        ParkingSpotType.MOTORBIKE: 0.0025,
        ParkingSpotType.COMPACT: 0.005,
        ParkingSpotType.LARGE: 0.01,
        ParkingSpotType.HANDICAPPED: 0.002,
    }

    vehicle_spot_type_mapping = {
        VehicleType.CAR: ParkingSpotType.COMPACT,
        VehicleType.TRUCK: ParkingSpotType.LARGE,
        VehicleType.MOTORBIKE: ParkingSpotType.MOTORBIKE,
    }

    # Create singleton instance of Parking Lot
    parking_lot = ParkingLot(
        num_entrance_panels,
        num_exit_panels,
        num_display_boards,
        parking_spot_counts,
        parking_spot_rates_per_sec,
        vehicle_spot_type_mapping,
        find_parking_spot_strategy,
    )

    # Create vehicles
    car1 = Car(vehicle_id=1)
    car2 = Car(vehicle_id=2)

    def park_one_vehicle(args):
        entrance_panel_id, vehicle = args
        vehicle_id = vehicle.vehicle_id
        vechicle_type = vehicle.vehicle_type
        logger.info(
            f" Vehicle of type: {vechicle_type} with ID: {vehicle_id} arrived at entrance panel with id: {entrance_panel_id} "
        )
        parking_lot.handle_vehicle_entrance(
            entrance_panel_id=entrance_panel_id, vehicle=vehicle
        )

    def exit_one_vehicle(args):
        exit_panel_id, vehicle = args
        vehicle_id = vehicle.vehicle_id
        vechicle_type = vehicle.vehicle_type
        logger.info(
            f" Vehicle of type: {vechicle_type} with ID: {vehicle_id} exiting at exit panel with id: {exit_panel_id} "
        )
        parking_lot.handle_vehicle_exit(exit_panel_id=exit_panel_id, vehicle=vehicle)

    with futures.ThreadPoolExecutor() as executor:
        _ = executor.map(park_one_vehicle, [(0, car1), (1, car2)])
        time.sleep(3)
        _ = executor.map(exit_one_vehicle, [(0, car1), (1, car2)])