Loading...
Certainly! Here's a brief analysis of the relationships between your core objects:
import datetime
import math
from enum import Enum
class Vehicle:
def __init__(self, size):
self.size = size
class Driver:
def __init__(self, id, vehicle):
self.id = id
self.vehicle = vehicle
self.payment_due = 0
def charge(self, amount):
self.payment_due += amount
class Size(Enum):
SMALL = 1
MEDIUM = 2
LARGE = 3
class Car(Vehicle):
def __init__(self):
super().__init__(Size.SMALL)
class Limo(Vehicle):
def __init__(self):
super().__init__(Size.MEDIUM)
class SemiTruck(Vehicle):
def __init__(self):
super().__init__(Size.LARGE)
class Spot:
def __init__(self, id, size):
self.size = size
self.id = id
self.vehicle = None
def assign_vehicle(self, vehicle):
self.vehicle = vehicle
def release_vehicle(self):
vehicle = self.vehicle
self.vehicle = None
return vehicle
class Floor:
def __init__(self, small, medium, large):
self.spots = []
for i in range(small):
self.spots.append(Spot(f'Small-{i+1}', Size.SMALL))
for i in range(medium):
self.spots.append(Spot(f'Medium-{i+1}', Size.MEDIUM))
for i in range(large):
self.spots.append(Spot(f'Large-{i+1}', Size.LARGE))
self.vehicle_map = {} # vehicle: spot ID
def find_available_spot(self, vehicle):
for spot in self.spots:
if not spot.vehicle and spot.size.value >= vehicle.size.value:
return spot
return None
def assign_vehicle_to_spot(self, vehicle):
available_spot = self.find_available_spot(vehicle)
if available_spot:
available_spot.assign_vehicle(vehicle)
self.vehicle_map[vehicle] = available_spot
return True
return False
def release_spot(self, id):
for spot in self.spots:
if spot.spot_id == spot_id:
vehicle = spot.release_vehicle()
del self.vehicle_map[vehicle]
return True
return False
class Garage:
def __init__(self): # []
self.floors = []
def addFloor(self, small, medium, large):
self.floors.append(Floor(small, medium, large))
def park_vehicle(self, vehicle):
for floor in self.floors:
if floor.assign_vehicle_to_spot(vehicle):
return True
return False
def remove_vehicle(self, vehicle):
for floor in self.floors:
if vehicle in floor.vehicle_map:
floor.release_spot(self.vehicle_map[vehicle])
return True
return False
class ParkingSystem:
def __init__(self, parkingGarage, hourlyRate):
self.parkingGarage = parkingGarage
self.hourlyRate = hourlyRate
self.timeParked = {} # map driverId to time that they parked
def park_vehicle(self, driver):
isParked = self.parkingGarage.park_vehicle(driver.get_vehicle())
if isParked:
self.timeParked[driver.id] = datetime.datetime.now()
return isParked
def remove_vehicle(self, driver):
if driver.id not in self.timeParked:
return False
currentHour = datetime.datetime.now().hour
time_parked = self.timeParked[driver.id]
duration = datetime.datetime.now() - time_parked
hours_billed = math.ceil(duration.total_seconds() / 3600)
driver.charge(hours_billed * self.hourlyRate)
del self.timeParked[driver.id]
return self.parkingGarage.remove_vehicle(driver.id)
ParkingFloor class that can be instantiated multiple times within a ParkingLot, you can easily scale the number of floors. Each floor can be initialized with varying numbers and types of ParkingSpots, allowing you to adjust the capacity as needed.ParkingSpot management, adding more spots or configuring different sizes/types is straightforward. You simply update the initialization parameters to reflect the desired count and types of spots per floor.ParkingSpot objects, allowing for efficient tracking and operations such as finding available spots and updating spot states. This helps to ensure quick operations even as more spots and vehicles are added.Vehicle class or introduce new subclasses, such as Van or ElectricVehicle. This approach allows easy integration without altering the existing system structure significantly.PricingStrategy classes to introduce new pricing models (e.g., weekend rates, progressive pricing, etc.). The system can then switch between strategies without needing to modify the core logic.ParkingSpot and maintain a list of upcoming reservations. This feature would involve extending your ParkingSpot management with methods to reserve and track reservations without changing the existing core functionality.ParkingFloor class. This can be achieved by refining findAvailableSpot() methods to incorporate new rules.ParkingLotManager class could be introduced to handle collections of ParkingLot instances. This allows the system to scale to manage multiple facilities from a central framework.ParkingSpot instances. It's responsible for finding and assigning spots.Critically examine your design for any flaws or areas for future improvement...