Source Code
Source Code
import os
import time
spaces = []
avail_spaces = 0
total_spaces = 0
rows = 0
space_count = 0
border = ""
# flags
linux = 0
# vehicle class, has a type and a plate number, upon creation, stores current epoch
time for later fare calculation
class Vehicle:
self.plate = plate
self.entry_time = time.time()
def get_type(self):
return self.type
def get_type_string(self):
def get_plate(self):
return self.plate
def get_entry_time(self):
return self.entry_time
self.entry_time = new_time
def get_vehicle(self):
return self.type, self.plate, self.entry_time
class Space:
def __init__(self):
self.vehicle = None
self.occupied = False
self.vehicle = vehicle
self.occupied = True
# remove a vehicle from a space and return object for final fare calculation
def remove_vehicle(self):
v_exit = self.vehicle
self.vehicle = None
self.occupied = False
return v_exit
def vehicle_info(self):
return self.vehicle
def is_available(self):
return self.occupied
def print_row(row):
output = ""
output += "|"
if not spaces[s].is_available():
else:
output += "["
else "m"
output += "]"
output += "|"
return output
# display all spaces with availability
def display_lot():
output += border
output += border
if linux == 1:
os.system("clear")
print(output)
# display all spaces with row selection numbers for user to choose from
def display_row_selection():
output += border
output += print_row(row)
output += border
if linux == 1:
os.system("clear")
print(output)
# display a specified row with space selection numbers for user to choose from
def display_space_selection(row):
output += border
output += print_row(int(row)) + "\n"
else:
output += "\n"
output += border
if linux == 1:
os.system("clear")
print(output)
return space_count
if avail_spaces == 0:
display_lot()
time.sleep(2)
return
display_space_selection(row)
time.sleep(2)
return -1
if uniq.is_available():
if uniq.vehicle_info().get_plate() == plate:
display_lot()
time.sleep(2)
return
# add a valid vehicle to the specified space and show the time of entry
avail_spaces -= 1
display_lot()
time.localtime(new_vehicle.get_entry_time()))))
time.sleep(2)
return new_vehicle
def fare_calculation(vehicle):
# calculate the number of seconds which have passed since a vehicle was
entered into the system
# if less than one hour has passed, then a minimum fare of one hour is priced
hours = 1
else:
if vehicle.get_type() == 1:
elif vehicle.get_type() == 2:
else:
return ret
global avail_spaces
display_space_selection(row)
print("Error: No Vehicle In Space")
time.sleep(2)
return
# if the specified plate number is found within the lot, the vehicle is removed
avail_spaces += 1
display_lot()
print(fare_calculation(removed))
time.sleep(2)
display_space_selection(row)
time.sleep(2)
# collect vehicle information and display to user
else:
display_space_selection(row)
time.localtime(vehicle.get_entry_time()))) + "\n"
def command_handler(command):
if command == "P":
while True:
display_lot()
"1. Car\n"
"2. Truck\n"
"3. Motorcycle\n"
">")
break
display_lot()
">")
# while loop is in case the user selects a spot which already has a vehicle
# or if the user inputs a plate number that has already been added
ret_val = -1
while True:
display_row_selection()
">")
if row.isnumeric():
break
while True:
display_space_selection(row)
space = input("Select Space to Park In:\n"
">")
if space.isnumeric():
break
# user can specify a row and space within the lot, if a selected space is
occupied,
while True:
display_row_selection()
">")
if row.isnumeric():
break
while True:
display_space_selection(row)
space = input("Select Space of Vehicle:\n"
">")
if space.isnumeric():
break
# program will check for vehicle plate within system and remove if found,
returns error if no plate found
exit_lot(row, space)
# user can specify a row and space within the lot, if a selected space is
occupied,
while True:
display_row_selection()
">")
if row.isnumeric():
break
while True:
display_space_selection(row)
">")
if space.isnumeric():
break
view_vehicle(row, space)
display_lot()
"Cars - $3.50/hour\n"
"Trucks - $4.50/hour\n"
"Motorcycles - $2.00/hour\n"
return
display_lot()
time.sleep(1)
def read_config():
while True:
line = config.readline()
if line.find("total_spaces") != -1:
total_spaces = int(line[13:16])
avail_spaces = total_spaces
rows = int(line[5:7])
# if demo mode is enabled, populate lot with demo cars, otherwise, populate
lot based on config
if int(line[10:11]) == 1:
demo_mode()
break
else:
for i in range(total_spaces):
spaces.append(Space())
border = "|"
for j in range(4):
border += "-"
border += "---|\n"
break
config.close()
def demo_mode():
for i in range(total_spaces):
spaces.append(Space())
total_spaces = 20
avail_spaces = 20
rows = 4
border = "|"
for j in range(4):
border += "-"
border += "---|\n"
v1 = enter_vehicle(1, "aaa-bbbb", 0, 3)
v2 = enter_vehicle(3, "ccc-dddd", 1, 2)
v3 = enter_vehicle(2, "eee-ffff", 2, 0)
v4 = enter_vehicle(1, "ggg-hhhh", 3, 1)
v5 = enter_vehicle(2, "iii-jjjj", 2, 4)
v1.set_entry_time(1620561600)
v2.set_entry_time(1620570600)
v3.set_entry_time(1620577800)
v4.set_entry_time(1620576000)
v5.set_entry_time(1620586800)
def main():
read_config()
command = ""
display_lot()
print("Please Select An Option:\n"
command = input(">")
command_handler(command)
if __name__ == '__main__':
main()