Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code python car parking
#1

My program for the final assessment question.
The way I interpreted the question was to create a program which simulates
the back-end of a car-park administration system. This involves manually entering
each vehicle that parks, when it leaves, payment systems etc.. You can also
list the currently parked vehicles, dump a history list of all vehicles
that have parked here and a statistics page which dumps free spots, taken spots
and total revenue. The code isn't commented, as it is fairly basic, but I tried to keep
it nice and clean.
As a bit of review, the program would be far more functional if it used a persistent
MySQL database to store all information (and it would be easy to adapt the system).
The system also needs to implemented a background thread to keep track of the time
so that fines could be issued more efficiently than requiring a refresh on car exit.
''
from itertools import product
import sys, cmd, string, pprint, threading, time, datetime, os
class Car():
cars = []
def __init__(self, nplate, floor, coord, time, tent, fee, index):
self.nplate = nplate
self.floor = floor
self.coord = coord
self.time = time
self.tent = tent
self.fee = fee
self.index = index

class CarHistory():
def __init__(self, nplate, tentd, tleft, fee, index):
self.nplate = nplate
self.tentd = tentd
self.tleft = tleft
self.fee = fee
self.index = index

class CarPayment():
def __init__(self, nplate, type, number, expiry, csc, index):
self.nplate = nplate
self.type = type
self.number = number
self.expiry = expiry
self.csc = csc
self.index = index

class CarPark():
parked = []
historylist = []
payment = []
def __init__(self):
groundcoords = list(product(xrange(7), xrange(7))
self.ground = [["OO","R","OO","NN","OO","R","OO"],
["OO","R","OO","NN","OO","R","OO"],
["OO","R","OO","OO","OO","R","OO"],
["DL","R","R","R","R","R","DR"],
["OO","R","OO","R","OO","R","OO"],
["OO","R","OO","R","OO","R","OO"],
["OO","R","OO","Ra","OO","R","OO"]]
self.middle = [["OO","R","OO","Ra","OO","R","OO"],
["OO","R","OO","R","OO","R","OO"],
["OO","R","OO","R","OO","R","OO"],
["R","R","R","R","R","R","R"],
["OO","R","OO","R","OO","R","OO"],
["OO","R","OO","R","OO","R","OO"],
["OO","R","OO","Ra","OO","R","OO"]]
self.top = [["OO","R","OO","Ra","OO","R","OO"],
["OO","R","OO","R","OO","R","OO"],
["OO","R","OO","R","OO","R","OO"],
["R","R","R","R","R","R","R"],
["OO","R","OO","R","OO","R","OO"],
["OO","R","OO","R","OO","R","OO"],
["OO","R","OO","R","OO","R","OO"]]
self.currentindex = 0

def spotsFree(self):
i=0
for rownum, row in enumerate(self.ground):
for colnum, value in enumerate(row):
if value == "OO":
i+=1
for rownum, row in enumerate(self.middle):
for colnum, value in enumerate(row):
if value == "OO":
i+=1
for rownum, row in enumerate(self.top):
for colnum, value in enumerate(row):
if value == "OO":
i+=1
return i

def printgrid(self):
print "\n Ground Floor:\n"
for i in self.ground:
x = ' '.join(map(str, i))
print x.replace("DL", "<<").replace("DR",">>").replace("Ra", "^^").replace("R", chr(254) + chr(254))
print "\nFirst Floor:\n"
for i in self.middle:
x = ' '.join(map(str, i))
print x.replace("DL", "<<").replace("DR",">>").replace("Ra", "^^").replace("R", chr(254) + chr(254))
print "\nRoof:\n"
for i in self.top:
x = ' '.join(map(str, i))
print x.replace("DL", "<<").replace("DR",">>").replace("Ra", "^^").replace("R", chr(254) + chr(254))
print "\n"
print "KEY:"
print chr(254) + chr(254), "- Road\nOO - Empty Spot\nNumber - ID of car parked in spot\n>>/<< - Entrance/Exits\n^^ - Ramp\nNN - Invalid Slot (not accessible)\n"

def createCar(self, nplate, xtime, floor, rownum, colnum, list):
coord = (rownum, colnum)
fee = float(xtime)*0.5
self.currentindex += 1
car = Car(nplate, floor, coord, xtime*60, time.time(), fee, self.currentindex)
carh = CarHistory(nplate, time.ctime(), 0, 0, self.currentindex)
carp = CarPayment(nplate, "", "", "", "", self.currentindex)
self.payment += [carp]
self.parked += [car]
self.historylist += [carh]
if self.currentindex < 10:
list[rownum][colnum] = "0" + str(self.currentindex)
else:
list[rownum][colnum] = str(self.currentindex)
print "Vehicle ID: " + nplate + " parked successfully.\n"
return

def park(self, nplate, xtime):
for rownum, row in enumerate(self.ground):
for colnum, value in enumerate(row):
if value == "OO":
self.createCar(nplate, xtime, "Ground ", rownum, colnum, self.ground)
return
for rownum, row in enumerate(self.middle):
for colnum, value in enumerate(row):
if value == "OO":
self.createCar(nplate, xtime, "Level 1", rownum, colnum, self.middle)
return
for rownum, row in enumerate(self.top):
for colnum, value in enumerate(row):
if value == "OO":
self.createCar(nplate, xtime, "Roof ", rownum, colnum, self.top)
return
print "There are no further parking spots on this level.\n"
return


def search (self, id, list):
if len(str(id)) <= 2:
for z in [z for z,x in enumerate(list) if x.index == int(id)]:
return list[z]
else:
for z in [z for z,x in enumerate(list) if x.nplate == id]:
return list[z]


def lookup(self, id):
i = self.search(id, self.parked)
h = self.search(id, self.historylist)
print "\nResult Found:"
print "\nNumber \nPlate: Time: Floor: Coord: Fee: Car No.:\n"
t = time.time()
nowtime = i.time - (t-i.tent)
if (nowtime/60)<=0:
f = (nowtime/60)/(-10)
f = f*10+i.fee
h.fee = f
else:
f = i.fee
print str(i.nplate), str('%.2f'%(nowtime/60)), str(i.floor).title(), str(i.coord) + " $" + str('%.2f'%f) + " " + str(i.index)
print "\n"

def list(self):
print "\n"
print "Number \nPlate: Time: Floor: Coord: Fee: Car No.:\n"
for i in self.parked:
t = time.time()
nowtime = i.time - (t-i.tent)
if (nowtime/60)<=0:
f = (nowtime/60)/(-10)
f = f*10+i.fee
else:
f = i.fee
print str(i.nplate), str('%.2f'%(nowtime/60)), str(i.floor).title(), str(i.coord) + " $" + str('%.2f'%f) + " " + str(i.index)
print "\n"

def leave(self, id, type, number, expiry, csc):
if id > 0:
j = self.search(id, self.parked)
h = self.search(id, self.historylist)
p = self.search(id, self.payment)
p.type = type
p.number = number
p.expiry = expiry
p.csc = csc
try:
x,y = j.coord
except AttributeError:
print "Enter in a valid car ID/number plate!"
return
self.ground[x][y] = "OO"
h.tleft = time.ctime()
h.fee = j.fee
self.parked.remove(j)
else:
print "Invalid Number Plate/Car ID entered."

def history(self):
totalpi = 0
print "\n"
print "Number \nPlate: Time Entered: Time Left: Fee Paid: Car No.:\n"
for i in self.historylist:
p = self.search(i.index, self.payment)
if i.tleft == 0:
temp = "Car has not left yet. "
totalpi += i.fee
print str(i.nplate), str(i.tentd), str(temp) + " $" + str('%.2f'%i.fee) + " " + str(i.index)
else:
temp = i.tleft
print str(i.nplate), str(i.tentd), str(temp) + " $" + str('%.2f'%i.fee) + " " + str(i.index)
totalpi += i.fee
if p.type == "credit":
print "Payment\nType: Card Number: Expiry: CSC:"
print str(p.type).title(), str(p.number), str(p.expiry) + " " + str(p.csc) + "\n\n"
else:
print "Payment Type: " + str(p.type).title() + "\n"
print "\nTotal Revenue: $" + str('%.2f'%totalpi) + "\n"

def stats(self):
total=73
totalr = 0.0
free = self.spotsFree()
for i in self.historylist:
if i.tleft == 0:
None
else:
totalr+=i.fee
print "Statistics:\n=======================\nTotal Cars Parked: " + str(total-free) + "\nFree Spots: " + str(free) + "\nTotal Revenue: $" + str('%.2f'%totalr) + "\n"



class CLI(cmd.Cmd):
def __init__(self):
self.c = CarPark()
cmd.Cmd.__init__(self)
self.prompt = "Enter a command: "

def do_map(self, arg):
self.c.printgrid()

def help_map(self):
print "\nsyntax: map"
print "Displays a map of the complex onscreen.\n"

def do_clear(self, arg):
os.system('cls')

def help_clear(self):
print "\nsyntax: clear"
print "Clears the screen on windows.\n"

def do_quit(self, arg):
sys.exit(1)

def help_quit(self):
print "syntax: quit"
print "Quits the program"

def do_park(self, arg):
try:
l = arg.split()
self.c.park(l[0], float(l[1]))
except IndexError:
print "Invalid parking entry. Syntax is: park <number plate> <time paid>"

def help_park(self):
print "\nsyntax: park <number plate> <time in minutes>"
print "Adds a new car to the parking complex with so many minutes pre-paid.\nThe system automatically assigns the car a place and a level.\n"

def do_lookup(self, arg):
l=arg.split()
l[0] = str(l[0]).upper()
i = self.c.search(l[0], self.c.parked)
if i == None:
print "\nNo valid result found.\n"
else:
self.c.lookup(l[0])

def help_lookup(self):
print "\nsyntax: lookup <number plate/id>"
print "Searches the vehicle database to find a certain vehicle parked in the complex.\nDisplays all relevant information on discovery.\n"

def do_list(self, arg):
self.c.list()

def help_list(self):
print "\nsyntax: list"
print "Lists all vehicles currently in the car park and all relevant information.\n"

def do_leave(self, arg):
l=arg.split()
self.c.list()
type = raw_input("Payment Type: [Cash, Cheque or Credit] ")
type = type.lower()
if type == "credit":
number = raw_input("Please enter the card number: ")
expiry = raw_input("Please enter the expiry: [Format dd/mm] ")
csc = raw_input("Please enter the security code: ")
self.c.leave(l[0], type, number, expiry, csc)
else:
self.c.leave(l[0], type, "", "", "")

def help_leave(self):
print "\nsyntax: leave <number plate/id>"
print "Removes the car from the database, and collects prepaid toll + any fines."

def do_history(self, arg):
self.c.history()

def do_stats(self, arg):
self.c.stats()

print "\nWelcome to the Manly Car Park Admin Panel!!"
print "============================================"
print "\n"
cli = CLI()
#threadconfigure()
cli.cmdloop()
cli.cmdloop()
Reply

#2
code python car parking

#include <stdio.h>
#include <conio.h>

#define CAR 1
#define SCOOTER 2

/* to store vehicle number, and its
row-col position in an array */
struct vehicle
{
int num ;
int row ;
int col ;
int type ;
} ;

int parkinfo[4][10] ; /* a 2-D array to store number of vehicle parked */
int vehcount ; /* to store total count of vehicles */
int carcount ; /* stores total count of cars */
int scootercount ; /* stores total count of scooters */
void display( ) ;
void changecol ( struct vehicle * ) ;
struct vehicle * add ( int, int, int, int ) ;
void del ( struct vehicle * ) ;
void getfreerowcol ( int, int * ) ;
void getrcbyinfo ( int, int, int * ) ;
void show( ) ;

/* decrements the col. number by one
this fun. is called when the data is
shifted one place to left */
void changecol ( struct vehicle *v )
{
v -> col = v -> col - 1 ;
}

/* adds a data of vehicle */
struct vehicle * add ( int t, int num, int row, int col )
{
struct vehicle *v ;

v = ( struct vehicle * ) malloc ( sizeof ( struct vehicle ) ) ;

v -> type = t ;
v -> row = row ;
v -> col = col ;

if ( t == CAR )
carcount++ ;
else
scootercount++ ;

vehcount++ ;
parkinfo[row][col] = num ;

return v ;
}

/* deletes the data of the specified
car from the array, if found */
void del ( struct vehicle *v )
{
int c ;

for ( c = v -> col ; c < 9 ; c++ )
parkinfo[v -> row][c] = parkinfo[v -> row][c+1] ;

parkinfo[v -> row][c] = 0 ;

if ( v -> type == CAR )
carcount-- ;
else
scootercount-- ;

vehcount-- ;
}

/* get the row-col position for the vehicle to be parked */
void getfreerowcol ( int type, int *arr )
{
int r, c, fromrow = 0, torow = 2 ;

if ( type == SCOOTER )
{
fromrow += 2 ;
torow += 2 ;
}

for ( r = fromrow ; r < torow ; r++ )
{
for ( c = 0 ; c < 10 ; c++ )
{
if ( parkinfo[r][c] == 0 )
{
arr[0] = r ;
arr[1] = c ;
return ;
}
}
}

if ( r == 2 r == 4 )
{
arr[0] = -1 ;
arr[1] = -1 ;
}
}

/* get the row-col position for the vehicle with specified number */
void getrcbyinfo ( int type, int num, int *arr )
{
int r, c, fromrow = 0, torow = 2 ;

if ( type == SCOOTER )
{
fromrow += 2 ;
torow += 2 ;
}

for ( r = fromrow ; r < torow ; r++ )
{
for ( c = 0 ; c < 10 ; c++ )
{
if ( parkinfo[r][c] == num )
{
arr[0] = r ;
arr[1] = c ;
return ;
}
}
}

if ( r == 2 r == 4 )
{
arr[0] = -1 ;
arr[1] = -1 ;
}
}

/* displays list of vehicles parked */
void display( )
{
int r, c ;

printf ( "Cars ->\n" ) ;

for ( r = 0 ; r < 4 ; r++ )
{
if ( r == 2 )
printf ( "Scooters ->\n" ) ;

for ( c = 0 ; c < 10 ; c++ )
printf ( "%d\t", parkinfo[r][c] ) ;
printf ( "\n" ) ;
}
}

void main( )
{
int choice, type, number, row = 0, col = 0 ;
int i, tarr[2] ;
int finish = 1 ;
struct vehicle *v ;

/* creates a 2-D array of car and scooter class */
struct vehicle *car[2][10] ;
struct vehicle *scooter[2][10] ;

clrscr( ) ;

/* displays menu and calls corresponding functions */
while ( finish )
{
clrscr( ) ;

printf ( "\nCar Parking\n" ) ;
printf ( "1. Arrival of a vehicle\n" ) ;
printf ( "2. Total no. of vehicles parked\n" ) ;
printf ( "3. Total no. of cars parked\n" ) ;
printf ( "4. Total no. of scooters parked\n" ) ;
printf ( "5. Display order in which vehicles are parked\n" ) ;
printf ( "6. Departure of vehicle\n" ) ;
printf ( "7. Exit\n" ) ;
scanf ( "%d", &choice ) ;

switch ( choice )
{
case 1 :

clrscr( ) ;
printf ( "\nAdd: \n" ) ;

type = 0 ;

/* check for vehicle type */
while ( type != CAR && type != SCOOTER )
{
printf ( "Enter vehicle type (1 for Car / 2 for Scooter ): \n" ) ;
scanf ( "%d", &type ) ;
if ( type != CAR && type != SCOOTER )
printf ( "\nInvalid vehicle type.\n" ) ;
}

printf ( "Enter vehicle number: " ) ;
scanf ( "%d", &number ) ;

/* add cars' data */
if ( type == CAR type == SCOOTER )
{
getfreerowcol ( type, tarr ) ;

if ( tarr[0] != -1 && tarr[1] != -1 )
{
row = tarr[0] ;
col = tarr[1] ;

if ( type == CAR )
car[row][col] = add ( type, number, row, col ) ;
else
scooter[row - 2][col] = add ( type, number, row, col ) ; ;
}
else
{
if ( type == CAR )
printf ( "\nNo parking slot free to park a car\n" ) ;
else
printf ( "\nNo parking slot free to park a scooter\n" ) ;
}
}
else
{
printf ( "Invalid type\n" ) ;
break ;
}

printf ( "\nPress any key to continue.." ) ;
getch( ) ;
break ;

case 2 :

clrscr( ) ;
printf ( "Total vehicles parked: %d\n", vehcount ) ;
printf ( "\nPress any key to continue.." ) ;
getch( ) ;
break ;

case 3 :

clrscr( ) ;
printf ( "Total cars parked: %d\n", carcount ) ;

printf ( "\nPress any key to continue.." ) ;
getch( ) ;
break ;

case 4 :

clrscr( ) ;
printf ( "Total scooters parked: %d\n", scootercount ) ;
printf ( "\nPress any key to continue.." ) ;
getch( ) ;
break ;

case 5 :

clrscr( ) ;
printf ( "Display\n" ) ;
display( ) ;

printf ( "\nPress any key to continue.." ) ;
getch( ) ;
break ;

case 6 :

clrscr( ) ;
printf ( "Departure\n" ) ;

type = 0 ;

/* check for vehicle type */
while ( type != CAR && type != SCOOTER )
{
printf ( "Enter vehicle type (1 for Car / 2 for Scooter ): \n" ) ;
scanf ( "%d", &type ) ;
if ( type != CAR && type != SCOOTER )
printf ( "\nInvalid vehicle type.\n" ) ;
}
printf ( "Enter number: " ) ;
scanf ( "%d", &number ) ;

if ( type == CAR type == SCOOTER )
{
getrcbyinfo ( type, number, tarr ) ;
if ( tarr[0] != -1 && tarr[1] != -1 )
{
col = tarr [1] ;

/* if the vehicle is car */
if ( type == CAR )
{
row = tarr [0] ;
del ( car [row][col] ) ;
for ( i = col ; i < 9 ; i++ )
{
car[row][i] = car[row][i + 1] ;
changecol ( car[row][i] ) ;
}
free ( car[row][i] ) ;
car[row][i] = NULL ;
}
/* if a vehicle is scooter */
else
{
row = tarr[0] - 2 ;
if ( ! ( row < 0 ) )
{
del ( scooter[row][col] ) ;
for ( i = col ; i < 9 ; i++ )
{
scooter[row][i] = scooter[row][i + 1] ;
changecol ( scooter[row][col] ) ;
}
scooter[row][i] = NULL ;
}
}
}
else
{
if ( type == CAR )
printf ( "\nInvalid car number, or a car with such number has not been parked here.\n" ) ;
else
printf ( "\nInvalid scooter number, or a scooter with such number has not been parked here.\n" ) ;
}
}

printf ( "\nPress any key to continue.." ) ;
getch( ) ;
break ;

case 7 :

clrscr( ) ;
for ( row = 0 ; row < 2 ; row++ )
{
for ( col = 0 ; col < 10 ; col++ )
{
if ( car[row][col] -> num != 0 )
free ( car[row][col] ) ;
if ( scooter[row][col] -> num != 0 )
free ( scooter[row+2][col] ) ;
}
}
finish = 0 ;
break ;
}
}
}
Reply

#3
Learning Outcomes:
On conclusion students should be able to:
Develop a problem-based strategy for creating and applying programmed solutions
Create, edit, compile, run, debug and test programs using an appropriate development environment

STUDENTS CAR PARK REGISTRATION SYSTEM

The management of APU has completed the construction of a three story car park where students may park their cars. The car park can accommodate a total of 45 cars, where each level will have 15 parking spaces. In order to facilitate the management of the car park, and enable students to rent parking spaces, a system is needed to handle the registration of students for each available car park for each semester. A student, once registered may park his or her car at the car park for duration of 120 days. The system would be used by the parking administration office to register students who wishes to park at the car park. The users should be able to insert, update, delete, read the following information about the students, parking spaces as well as user details.

Students Description
StudentID Student s TP number
FirstName Student s first name
LastName Student s last name
Contact Number Student s mobile number
E-mail address Student s e-mail address
CarNumber Student s car number
Date Registered Date of registration for the car park
Parking Spaces Description
ParkingSpaceID The parking bay number, using the car park level and the bay number. Example, the parking bay number 10 at level 2 would be L2010.
Status Parking bay status as Available or Assigned
StudentID

Users Description
UserID User s ID Number e.g. PKO1234 (PKO = Parking Office)
Password User s password for logging into the system
User s First Name User s first name
User s Last Name User s first name

SYSTEM REQUIREMENTS

1. The system must require user to enter his or her ID and an assigned password before using the system. Upon login, the system shall display the user s actual name on the system s user interface.

2. The system must have the following functionalities:
a. New Registration where students who wish to park their car at the car park is registered by the system. Once registered, a parking bay is assigned by the system depending on the availability of parking bays. If all the parking bays are already assigned, then the system shall indicate to the user its status.

b. Cancel (Delete) a registration where a student who do not wish to park at the car park anymore. The parking bay occupied then will be released, and the student s record will be deleted from the system.

c. Update a student s information such as Car Number, Contact Number and E-mail address. Other student s information such as StudentID, FirstName and LastName should not be available for editing. To facilitate the update process, a Search for the student s information using the StudentID will be required.

d. Generate a report of all cars parked at the car park which should include the following information:
i. StudentID
ii. Car Number
ii. ParkingSpaceID
iv. Date Registered
v. Date Expired (to be calculated from the date of registration)

The applications can be developed using structure programming or object-oriented approach. Data may be stored in collections i.e. array of objects or into data files

INSTRUCTIONS

This is a group assignment. Each group should consist of 2 3 members only. Upon submission of your assignment, you would be required to present your assignment at a date and time specified by your module lecturer.

Each team member is required to contribute towards all sections of the assignment, present and explain his or her contribution of the work done. Each team member should also be able to answer questions posed with regards to the project and / or subject matter.

DELIVERABLES

You are required to submit:
a. A softcopy of the program coded in Python submitted on a CD. The program should include the following:
Basic programming concepts such as displaying and reading of inputs, displaying of outputs, declaration of variables and assignment of values, comments to explain various parts of the program, etc.
Using selection control structures and iteration structures and arrays
Object-oriented concepts such as the use of classes / objects / inheritance / constructors
Use of exception handling and packages

b. Documentation of the system, that incorporates basic documentation standards such as header and footer, page numbering and which includes
Cover page
Table of contents
Workload matrix to indicate the contribution of each individual for each required component (shown in %age form) and signed off by each team member
Design of the program using use case diagram, use case description, class diagram, IPO (input, process, output) chart, pseudocode or flowcharts which adheres to the basic requirements listed above
Test plan
Sample outputs when the program is executed with some explanation of the outputs / sections of the program
References

The documentation should be comb-bound with the CD attached.

ASSESSMENT CRITERIA


Individual Component (30%)
Program Listing (15%)
Presentation (5%)
Q & A (5%)
Contribution (5%)

Group Component (70%)
Design (20%)
Module Integration (25%)
Documentation (25%)
Reply

#4
To get full information or details of code python car parking please have a look on the pages

http://seminarsprojects.net/Thread-code-...#pid176716

if you again feel trouble on code python car parking please reply in that page and ask specific fields in code python car parking
Reply

#5

Just wanna know how to write good code from you guy
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.