generated from 2KAbhishek/bare-minimum
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolf_manager.py
169 lines (146 loc) Β· 5.19 KB
/
golf_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from datetime import datetime
from course import Course
from flight import Flight
from golf_club import GolfClub
from golfing_exception import GolfingException
def submitBooking(golfClub):
print("""
Enter 3 or 4 golfers to form a flight
=====================================
""")
golfers = []
for i in range(4):
print("Enter ID for golfer {} or -1 to stop: ".format(i+1))
id = int(input())
if id == -1:
break
golfers.append(golfClub.searchGolfer(id))
flight = Flight(golfers)
print("""
List of available tee times
=========================
""")
availableTimes = golfClub.getEmptyTeeTimes()
for index, teeTime in enumerate(availableTimes):
print("{}. {}".format(index, teeTime))
print("Enter option: ")
selection = availableTimes[int(input())]
try:
for golfer in flight.getGolfersID():
if golfClub.searchMemberBooking(golfer) != None:
raise GolfingException(
"Booking has failed as one member already has another booking")
if golfClub.golfingDate.weekday() == 5 or golfClub.golfingDate.weekday() == 6:
if not flight.getWeekendEligibility():
raise GolfingException(
"Booking has failed as flight is not eligible to play on weekend")
golfClub.addBooking(selection, flight)
print("Tee time {} booked for flight with golfers {}".format(
selection, flight.getGolfersID()))
displayMenu(golfClub)
except GolfingException as e:
print(e)
print("Invalid option")
submitBooking(golfClub)
def cancelBooking(golfClub):
print("Enter member ID to cancel booking: ")
memberID = int(input())
try:
cancelTime = golfClub.searchMemberBooking(memberID)
golfClub.cancelBooking(cancelTime)
print("Tee Time {} cancelled successfully".format(cancelTime))
displayMenu(golfClub)
except GolfingException as e:
print(e)
print("Invalid member ID")
cancelBooking(golfClub)
def editBooking(golfClub):
print("Enter tee time (HH:MM) to edit booking: ")
teeTime = input()
try:
flight = golfClub.searchBooking(teeTime)
print("""
Current flight of golfers {} will be replaced by a new flight
Confirm to replace? (Y/N): """.format(flight.getGolfersID()))
selection = input()
if selection == 'y':
print("Enter 3 or 4 golfers to form a flight")
golfers = []
for i in range(4):
print("Enter ID for golfer {} or -1 to stop: ".format(i+1))
id = int(input())
if id == -1:
break
golfers.append(golfClub.searchGolfer(id))
flight = Flight(golfers)
golfClub.cancelBooking(teeTime)
golfClub.addBooking(teeTime, flight)
print("Flight with golfers {} updated successfully".format(
flight.getGolfersID()))
displayMenu(golfClub)
except GolfingException as e:
print(e)
print("Invalid tee time")
editBooking(golfClub)
def printPlaySchedule(golfClub):
print("Enter member ID to print play schedule: ")
memberID = int(input())
try:
teeTime = golfClub.searchMemberBooking(memberID)
print(golfClub.course.getPlaySchedule(teeTime))
displayMenu(golfClub)
except GolfingException as e:
print(e)
print("Invalid member ID")
printPlaySchedule(golfClub)
def overviewTeeSchedule(golfClub):
print("""
Overview of Tee Schedule
===========================
""")
print(golfClub.getBookings())
displayMenu(golfClub)
def displayMenu(golfClub):
print("""
Golf Booking for {}
======================================
1. Submit Booking
2. Cancel Booking
3. Edit Booking
4. Print Play Schedule
5. Overview of Tee Schedule
0. Exit
Enter option: """.format(golfClub.golfingDate.strftime("%d/%m/%Y %A")))
selection = int(input())
if selection == 1:
submitBooking(golfClub)
elif selection == 2:
cancelBooking(golfClub)
elif selection == 3:
editBooking(golfClub)
elif selection == 4:
printPlaySchedule(golfClub)
elif selection == 5:
overviewTeeSchedule(golfClub)
elif selection == 0:
exit()
else:
print("Invalid option")
displayMenu(golfClub)
if __name__ == "__main__":
fileName = "../data/" + input("Enter course file name: ")
course = Course(fileName)
golfingDate = datetime.strptime(
input("Enter golfing date in dd/mm/yyyy: "), "%d/%m/%Y")
golfClub = GolfClub("Fantasy Golf", course, golfingDate)
golfClub.setupGolfers("../data/Golfers.txt")
flight1 = Flight([golfClub.searchGolfer(21), golfClub.searchGolfer(
57), golfClub.searchGolfer(58), golfClub.searchGolfer(5)])
golfClub.addBooking("07:28", flight1)
flight2 = Flight([golfClub.searchGolfer(
8), golfClub.searchGolfer(18), golfClub.searchGolfer(17)])
golfClub.addBooking("07:48", flight2)
flight3 = Flight([golfClub.searchGolfer(
9), golfClub.searchGolfer(27), golfClub.searchGolfer(24)])
golfClub.addBooking("07:58", flight3)
displayMenu(golfClub)