Skip to content

panel

Module: Entrance, Exit Panels.

DisplayBoard

Class:Display board.

Source code in parking_lot/src/panel.py
64
65
66
67
68
69
70
71
72
73
74
75
class DisplayBoard:
    """Class:Display board."""

    def __init__(self, board_id: int):
        """Initialize display board instance."""
        self._board_id = board_id

    def update_num_free_spot_counts(self, num_free_spots):
        """Update count of free spots."""
        logger.info(f"DisplayBoard{self._board_id}: ")
        for spot_type, free_spots in num_free_spots.items():
            logger.info(f"{spot_type}: {free_spots} free spots available.")

__init__(board_id)

Initialize display board instance.

Source code in parking_lot/src/panel.py
67
68
69
def __init__(self, board_id: int):
    """Initialize display board instance."""
    self._board_id = board_id

update_num_free_spot_counts(num_free_spots)

Update count of free spots.

Source code in parking_lot/src/panel.py
71
72
73
74
75
def update_num_free_spot_counts(self, num_free_spots):
    """Update count of free spots."""
    logger.info(f"DisplayBoard{self._board_id}: ")
    for spot_type, free_spots in num_free_spots.items():
        logger.info(f"{spot_type}: {free_spots} free spots available.")

EntrancePanel

Class: Entrance Panel.

Source code in parking_lot/src/panel.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class EntrancePanel:
    """Class: Entrance Panel."""

    def __init__(self, panel_id: int):
        """Initialize entrance panel instance."""
        self._panel_id = panel_id

    def issue_ticket(
        self, vehicle: Vehicle, parking_spot: ParkingSpot
    ) -> ParkingTicket:
        """Issue ticket to vehicle."""
        parking_ticket = ParkingTicket(
            ticket_id=uuid4(),
            entrance_id=self._panel_id,
            spot_id=parking_spot.spot_id,
            spot_type=parking_spot.spot_type,
            vehicle_id=vehicle.vehicle_id,
            vehicle_type=vehicle.vehicle_type,
            issued_at=datetime.now(),
            paid_at=None,
            exit_id=None,
            status=ParkingTicketStatus.UNPAID,
            paid_amount=None,
        )
        return parking_ticket

__init__(panel_id)

Initialize entrance panel instance.

Source code in parking_lot/src/panel.py
18
19
20
def __init__(self, panel_id: int):
    """Initialize entrance panel instance."""
    self._panel_id = panel_id

issue_ticket(vehicle, parking_spot)

Issue ticket to vehicle.

Source code in parking_lot/src/panel.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def issue_ticket(
    self, vehicle: Vehicle, parking_spot: ParkingSpot
) -> ParkingTicket:
    """Issue ticket to vehicle."""
    parking_ticket = ParkingTicket(
        ticket_id=uuid4(),
        entrance_id=self._panel_id,
        spot_id=parking_spot.spot_id,
        spot_type=parking_spot.spot_type,
        vehicle_id=vehicle.vehicle_id,
        vehicle_type=vehicle.vehicle_type,
        issued_at=datetime.now(),
        paid_at=None,
        exit_id=None,
        status=ParkingTicketStatus.UNPAID,
        paid_amount=None,
    )
    return parking_ticket

ExitPanel

Class: Exit Panel.

Source code in parking_lot/src/panel.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class ExitPanel:
    """Class: Exit Panel."""

    def __init__(self, panel_id: int):
        """Initialize exit panel instance."""
        self._panel_id = panel_id

    def scan_ticket(self, ticket: ParkingTicket, rates):
        """Scan ticket at exit."""
        current_timestamp = datetime.now()
        seconds_elapsed = (current_timestamp - ticket.issued_at).seconds
        total_amount = rates[ticket.spot_type] * seconds_elapsed

        # Accept payment and update ticket payment status
        ticket.paid_at = current_timestamp
        ticket.exit_id = self._panel_id
        ticket.status = ParkingTicketStatus.PAID
        ticket.paid_amount = total_amount

        return ticket

__init__(panel_id)

Initialize exit panel instance.

Source code in parking_lot/src/panel.py
45
46
47
def __init__(self, panel_id: int):
    """Initialize exit panel instance."""
    self._panel_id = panel_id

scan_ticket(ticket, rates)

Scan ticket at exit.

Source code in parking_lot/src/panel.py
49
50
51
52
53
54
55
56
57
58
59
60
61
def scan_ticket(self, ticket: ParkingTicket, rates):
    """Scan ticket at exit."""
    current_timestamp = datetime.now()
    seconds_elapsed = (current_timestamp - ticket.issued_at).seconds
    total_amount = rates[ticket.spot_type] * seconds_elapsed

    # Accept payment and update ticket payment status
    ticket.paid_at = current_timestamp
    ticket.exit_id = self._panel_id
    ticket.status = ParkingTicketStatus.PAID
    ticket.paid_amount = total_amount

    return ticket