def test_companyParked(self): parkingLotObj = ParkingLot(6, 30) # res1 = parkingLotObj.parkVehicle(Car(20, "Google")) # res2 = parkingLotObj.companyParked("Google") self.assertTrue(parkingLotObj.parkVehicle(Car(20, "Google"))) self.assertEqual(parkingLotObj.companyParked("Google"), [Car(20, "Google")]) #self.assertEqual(parkingLotObj.companyParked("Google"), Car(10, "Google")) print(parkingLotObj.companyParked("Google"))
def test_park(self): parkingLotObj = ParkingLot(6, 30) res2 = parkingLotObj.parkVehicle(Car(10, "Amazon")) res3 = parkingLotObj.parkVehicle(Bike(20, "Amazon")) res4 = parkingLotObj.parkVehicle(Bus(30, "Microsoft")) self.assertEqual(res2, True) self.assertEqual(res3, True) self.assertEqual(res4, True)
def __execute(self, cmd): cmd = cmd.strip() if not self.parking_lot_initialized: cmd_list = cmd.split() if cmd_list[0] == self.create_parking_lot_cmd: self.parking_lot = ParkingLot(int(cmd_list[1])) self.parking_lot_initialized = True logger.debug('Parking lot initialized with slots {}'.format( cmd_list[1])) return logger.debug( 'Command seen before initializing Parking lot: {}'.format(cmd)) else: self.parking_lot.execute(cmd)
class MainExecutor: def __init__(self): self.create_parking_lot_cmd = 'create_parking_lot' self.parking_lot_initialized = False if len(sys.argv) == 2: # Contains the file to be parsed file = sys.argv[1] logger.debug('FILE INPUT {}'.format(file)) self.__parse_file(file) else: logger.debug('STDIN INPUT') self.__get_inputs_from_stdin() def __parse_file(self, file): try: fs = open(file, 'r') except Exception as e: logger.error('Unable to open file {}'.format(file)) return lines = fs.readlines() for cmd in lines: self.__execute(cmd) logger.debug('Parsed file {}: Exiting the process'.format(file)) return def __execute(self, cmd): cmd = cmd.strip() if not self.parking_lot_initialized: cmd_list = cmd.split() if cmd_list[0] == self.create_parking_lot_cmd: self.parking_lot = ParkingLot(int(cmd_list[1])) self.parking_lot_initialized = True logger.debug('Parking lot initialized with slots {}'.format( cmd_list[1])) return logger.debug( 'Command seen before initializing Parking lot: {}'.format(cmd)) else: self.parking_lot.execute(cmd) def __get_inputs_from_stdin(self): while True: cmd = sys.stdin.readline() cmd = cmd.strip() if 'exit' == cmd.lower(): logger.debug('Obtained Exit from input: Exiting the process') return self.__execute(cmd)
def test_all(self): parkingLotObj = ParkingLot(3, 10) # Atleast 1 parking spot for car. # First park a car, it should return True. self.assertTrue(parkingLotObj.parkVehicle(Car(10, "Google"))) # Get the list of cars, it should give one car we parked. self.assertEqual(parkingLotObj.companyParked("Google"), [Car(10, "Google")]) # Remove that car successfully. self.assertTrue(parkingLotObj.leaveOperation(Car(10, "Google"))) # Now the list of cars should be empty. self.assertEqual(parkingLotObj.companyParked("Google"), [])
def test(self): levels = [Level(2, 1), Level(2, 2), Level(2, 3)] parkingLot = ParkingLot(levels) # Fill first level but one for i in range(1, 30): # 1-29 parkingLot.park(Vehicle("Bus", str(i))) self.assertEqual(30, parkingLot.park(Vehicle("Bus","30"))) self.assertEqual(None, parkingLot.park(Vehicle("Truck","31"))) self.assertEqual(5, parkingLot.exit("5")) self.assertEqual(5, parkingLot.park(Vehicle("Truck","31"))) #Fill second level and third level but 2 for i in range(101, 159): # 101-158 parkingLot.park(Vehicle("Car", str(i))) self.assertEqual(29, parkingLot.park(Vehicle("MotorCycle","159"))) self.assertEqual(None, parkingLot.park(Vehicle("Bike","159"))) self.assertEqual(None, parkingLot.park(Vehicle("Truck","1"))) self.assertEqual(30, parkingLot.park(Vehicle("Car","160"))) self.assertEqual(25, parkingLot.exit("125")) self.assertEqual(25, parkingLot.park(Vehicle("Car","161")))
def test_leave_operation(self): parkingLotObj = ParkingLot(6, 30) self.assertTrue(parkingLotObj.parkVehicle(Car(20, "Google"))) #self.assertTrue(parkingLotObj.leaveOperation(Car(10, "Google"))) self.assertTrue(parkingLotObj.leaveOperation(Car(20, "Google"))) self.assertEqual(parkingLotObj.leaveOperation(Car(20, "Google")), None)
from parkinglot import ParkingLot, Level, Vehicle levels = [Level(2, 1), Level(2, 2), Level(2, 3)] parkingLot = ParkingLot(levels) print("\n====================================") print(" Parking Lot Management System v0.0") print("====================================\n\n") while True: print("\nInput Intruction: (enter 'exit' to stop the system)") if line := input(): line = line.split() if line[0] == "exit": break if line[0] == "ENTRY" and len(line) == 3: parkingLot.park(Vehicle(line[1], line[2])) elif line[0] == "EXIT" and len(line) == 2: parkingLot.exit(line[1]) else: print("Invalid Input!")
def create_charging_stations(identitiesArray, areas, percentageOfStates, areaPerCar, charging_status=True, charging_power=3.7): """Creates and returns a list of stations This function is used to create a list of stations. The idea is every charging station is divided into several charging stations based on the percentages of areas. Each subset charging station is then considered to have a unique state. Parameters ---------- identitiesArray : list(-) A list of unique names (IDs) for each station. It is used to name the stations and their subsets. areas : list(float) A list containing the areas of each charging station. percentageOfStates : numpy.array(float) A numpy array containing the percentage of areas of each feature dedicated to each state. In other words, each charging station will be divided into several states, what is the percentage of division. areaPerCar : float A float encoding the ground area needed to fit a car in a parking lot. This area should take into account the manuevering area and landscaping area. charging_status : list(bool), optional Which stations will only be considered parking lots and no charging will be enabled in. Default True. charging_power : float, optional The charging power of the stations. Default 3.7 kW. Returns ------- list(ParkingLot) A list of parking lots representing charging stations and or parking lots without charging. """ if type(charging_status) is bool: charging_status = [ charging_status for i in range(len(identitiesArray)) ] if type(charging_power) is int or type(charging_power) is float: charging_power = [charging_power for i in range(len(identitiesArray))] if type(areaPerCar) is int or type(areaPerCar) is float: areaPerCar = [areaPerCar for i in range(len(identitiesArray))] ids = list(identitiesArray) stations = [] for st in range(percentageOfStates.shape[1]): stations_temp = [ ParkingLot( ID=str(ids[i]) + "-" + str(st), state=st, chargingPower=charging_power[i], maximumOccupancy=ceil(1.0 / areaPerCar[i] * percentageOfStates[i, st] * areas[i]), currentOccupancy=0, chargingStatus=True, currentLoad=0.0) for i in range(len(identitiesArray)) if percentageOfStates[i, st] != 0 ] stations.extend(stations_temp) return (stations)
def main(): ps = ParkingSystem() parking = ParkingLot("TCS Parking", 3) car1 = Car("Swift", "Maruti Suzuki", "MH04T1995") car2 = Car("Fabia", "Skoda", "MH44T2012") car3 = Car("SL535", "Mercedes Benz", "MP19T1221") car4 = Car("X6", "BMW", "MP22110") ps.check_availability(parking) parking.add_car(car1) parking.add_car(car2) ps.check_availability(parking) parking.remove_car(car1) parking.add_car(car3) parking.get_parking_spot_details("P2") parking.add_car(car4) ps.check_availability(parking)
12 import numpy as np 13 import time 14 import captureimage 15 from xbeecomm import XbeeComm 16 from spot import Spot 17 from parkinglot import ParkingLot 18 19 # Sets the location of the images requires for the system 20 21 LOT_EMPTY = '/home/pi/EGE409/img/real_empty.jpg' 22 LOT_SAMPLE = '/home/pi/EGE409/img/real_sample.jpg' 23 24 # Initial creation of the parking lot 25 26 captureimage.CaptureImage(LOT_EMPTY) 27 28 lot = ParkingLot(LOT_EMPTY,5) 29 30 xbcom = XbeeComm() 31 32 # Continuous loop that samples the parking lot 33 34 while True: 35 36 time.sleep(1) 37 captureimage.CaptureImage(LOT_SAMPLE) 38 lot.update_status(LOT_SAMPLE) 39 # Sends $ for clearing the LCD screen 40 xbcom.sendmsg('$Vacancies = ' + str(lot.vacancy)) 41 42
from parkinglot import ParkingLot P = ParkingLot([{'bike': 2, 'car': 3}, {'bike': 5, 'car': 8}], ['bike', 'car'])