-
Notifications
You must be signed in to change notification settings - Fork 0
/
seating.py
99 lines (74 loc) · 2.67 KB
/
seating.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
class SeatingPlan:
# -1 - seat not available
# 0 - seat taken
# 1 - seat temporarily blocked
# 2 - seat available
# 0 - Accessible Seat
# 2 - Normal Seat
def __init__(self, seat_matrix):
self.seat_matrix = seat_matrix
def row_count(self):
return len(self.seat_matrix)
def full_search(self, row, col):
for r1 in self.seat_matrix:
for c1 in r1:
if c1 and c1.row == row and c1.col == col:
return (r1, c1)
return None
def get_seat_index(self, row, col):
if row < 1 or col < 1 or row > self.row_count() or col > len(self.seat_matrix[row - 1]) or self.seat_matrix[row - 1][col - 1] is None:
return self.full_search(row, col)
elif self.seat_matrix[row - 1][col - 1].row == row and self.seat_matrix[row - 1][col - 1].col == col:
return (row - 1, col - 1)
else:
return self.full_search(row, col)
def get_seat(self, row, col):
if row < 0 or col < 0 or row > self.row_count() or col > len(self.seat_matrix[row]):
return None
return self.seat_matrix[row][col]
def set_seat(self, row, col, new_seat):
row -= 1
col -=1
if row < 0 or col < 0 or row >= self.row_count() or col >= len(self.seat_matrix[row]):
return False
else:
self.seat_matrix[row][col] = new_seat
return True
class GVSeatingPlan(SeatingPlan):
GV_SEATING_PLAN_URL = "https://www.gv.com.sg/.gv-api/seatplan"
AVAILABLE_STATUSES = ['L']
TEMP_UNAVAILABLE_STATUSES = ['T']
UNAVAILABLE_STATUSES = ['B']
ACCESSIBLE_TYPE = ['W']
NORMAL_TYPE = ['N']
def __init__(self, seat_matrix):
SeatingPlan.__init__(self, seat_matrix)
def get_gv_seat_status(self, status):
if status in self.AVAILABLE_STATUSES:
return 2
elif status in self.TEMP_UNAVAILABLE_STATUSES:
return 1
elif status in self.UNAVAILABLE_STATUSES:
return 0
else:
return -1
def get_gv_seat_type(self, seat_type):
if seat_type in self.ACCESSIBLE_TYPE:
return 0
elif seat_type in self.NORMAL_TYPE:
return 1
else:
return -1
@staticmethod
def create_seat_by_id(seat_id):
row = ord(seat_id.split(":")[0]) - ord('A') + 1
col = int(seat_id.split(":")[1])
return Seat(row, col)
class Seat:
def __init__(self, row, col, status = 2, seat_type = 2):
self.row = row
self.col = col
self.status = status
self.seat_type = seat_type
def is_available(self):
return self.status == 2