source: src/mlx/gates.py@ 1110:67a5ba8a8664

python3
Last change on this file since 1110:67a5ba8a8664 was 1105:2d0d642d122d, checked in by István Váradi <ivaradi@…>, 14 months ago

The gate information includes if it is taxi-through (re #371)

File size: 8.1 KB
Line 
1#--------------------------------------------------------------------------------------
2
3## @package mlx.gates
4#
5# The module to handle the LHBP gate information.
6#
7
8#--------------------------------------------------------------------------------------
9
10class Gate(object):
11 """Information about a gate."""
12 def __init__(self, number, terminal, type,
13 availableFn = None, taxiThrough = False):
14 """Construct the gate with the given information.
15
16 number is the gate's number as a string (as it can contain letters).
17 terminal is the terminal the gate belongs to (not used currently).
18 type is the gate's type: G for gate, S for stand.
19 availableFn is a function that can determine if the gate is available based on
20 the statuses of other gates. Its arguments are:
21 - a collection of the gates, and
22 - a set of occupied gate numbers."""
23 self._number = number
24 self._terminal = terminal
25 self._type = type
26 self._availableFn = availableFn
27 self._taxiThrough = taxiThrough
28
29 @property
30 def number(self):
31 """Get the number of the gate."""
32 return self._number
33
34 @property
35 def taxiThrough(self):
36 """Get if the gate is a taxi through one."""
37 return self._taxiThrough
38
39 def isAvailable(self, gates, occupiedGateNumbers):
40 """Determine if this gate is available given the set of gates and
41 occupied gate numbers."""
42 if self._number in occupiedGateNumbers:
43 return False
44 return True if self._availableFn is None else \
45 self._availableFn(gates, occupiedGateNumbers)
46
47#--------------------------------------------------------------------------------------
48
49class Gates(object):
50 """A collection of gates."""
51 # Display info type: a gate (number)
52 DISPLAY_GATE=1
53
54 # Display info type: a space
55 DISPLAY_SPACE=2
56
57 # Display info type: a new column
58 DISPLAY_NEW_COLUMN=3
59
60 def __init__(self):
61 """Construct the gate collection."""
62 self._gates = []
63 self._displayInfos = []
64 self._numColumns = 1
65 self._numRows = 0
66 self._numRowsInColumn = 0
67
68 @property
69 def gates(self):
70 """Get an iterator over the gates."""
71 return iter(self._gates)
72
73 @property
74 def displayInfos(self):
75 """Get an iterator over the display info tuples.
76
77 Each tuple consists of
78 - a type (one of the DISPLAY_XXX constants), and
79 - an additional data (the gate for DISPLAY_GATE, None for others)."""
80 return iter(self._displayInfos)
81
82 @property
83 def numRows(self):
84 """Get the number of rows."""
85 return self._numRows
86
87 @property
88 def numColumns(self):
89 """Get the number of columns."""
90 return self._numColumns
91
92 def add(self, gate):
93 """Add a gate to the collection."""
94 self._gates.append(gate)
95 self._displayInfos.append((Gates.DISPLAY_GATE, gate))
96 self._addRow()
97
98 def find(self, gateNumber):
99 """Find a gate by its number."""
100 for gate in self._gates:
101 if gate.number == gateNumber:
102 return gate
103
104 def addSpace(self):
105 """Add a space between subsequent gates."""
106 self._displayInfos.append((Gates.DISPLAY_SPACE, None))
107 self._addRow()
108
109 def addNewColumn(self):
110 """Start a new column of gates."""
111 self._displayInfos.append((Gates.DISPLAY_NEW_COLUMN, None))
112 self._numRowsInColumn = 0
113 self._numColumns += 1
114
115 def _addRow(self):
116 """Add a new row."""
117 self._numRowsInColumn += 1
118 if self._numRowsInColumn > self._numRows:
119 self._numRows = self._numRowsInColumn
120
121#--------------------------------------------------------------------------------------
122
123def availableIf(occupiedGateNumbers, othersAvailable = []):
124 """Determine if a gate is available.
125
126 othersAvailable is a list of numbers of gates, that must be available so
127 that the one we are considering is available."""
128 for otherNumber in othersAvailable:
129 if otherNumber in occupiedGateNumbers:
130 return False
131 return True
132
133#--------------------------------------------------------------------------------------
134
135def getAvilableIf(othersAvailable = []):
136 """Get a function that determines if a gate is available based on the
137 statuses of other gates."""
138 return lambda gates, occupiedGateNumbers: availableIf(occupiedGateNumbers,
139 othersAvailable =
140 othersAvailable)
141
142#--------------------------------------------------------------------------------------
143
144# The gates at LHBP
145lhbpGates = Gates()
146
147lhbpGates.add(Gate("1", "1", "S"))
148lhbpGates.add(Gate("2", "1", "S"))
149lhbpGates.add(Gate("3", "1", "S"))
150lhbpGates.add(Gate("4", "1", "S"))
151lhbpGates.add(Gate("5", "1", "S"))
152lhbpGates.add(Gate("6", "1", "S"))
153lhbpGates.add(Gate("25", "1", "S"))
154lhbpGates.add(Gate("26", "1", "S"))
155lhbpGates.add(Gate("27", "1", "S"))
156lhbpGates.addSpace()
157
158lhbpGates.add(Gate("31", "2B", "G"))
159lhbpGates.add(Gate("32", "2B", "G"))
160lhbpGates.add(Gate("33", "2B", "G"))
161lhbpGates.addNewColumn()
162
163lhbpGates.add(Gate("34", "2B", "G"))
164lhbpGates.add(Gate("35", "2B", "G"))
165lhbpGates.add(Gate("36", "2B", "G"))
166lhbpGates.add(Gate("37", "2B", "G"))
167lhbpGates.add(Gate("38", "2B", "G"))
168lhbpGates.add(Gate("39", "2B", "G"))
169lhbpGates.addSpace()
170
171lhbpGates.add(Gate("42", "2A", "G"))
172lhbpGates.add(Gate("43", "2A", "G"))
173lhbpGates.add(Gate("44", "2A", "G"))
174lhbpGates.add(Gate("45", "2A", "G"))
175lhbpGates.addNewColumn()
176
177lhbpGates.add(Gate("107", "1", "S"))
178lhbpGates.add(Gate("108", "1", "S"))
179lhbpGates.add(Gate("109", "1", "S"))
180lhbpGates.add(Gate("R110", "1", "S",
181 availableFn = getAvilableIf(othersAvailable = ["R111"])))
182lhbpGates.add(Gate("R111", "1", "S",
183 availableFn = getAvilableIf(othersAvailable = ["R110", "R112"])))
184lhbpGates.add(Gate("R112", "1", "S",
185 availableFn = getAvilableIf(othersAvailable = ["R111"])))
186lhbpGates.add(Gate("R113", "1", "S",
187 availableFn = getAvilableIf(othersAvailable = ["R114"])))
188lhbpGates.add(Gate("R114", "1", "S",
189 availableFn = getAvilableIf(othersAvailable = ["R113"])))
190lhbpGates.add(Gate("R115", "1", "S"))
191lhbpGates.add(Gate("R116", "1", "S"))
192lhbpGates.add(Gate("R117", "1", "S"))
193lhbpGates.addNewColumn()
194
195lhbpGates.add(Gate("R210", "2A", "S",
196 availableFn = getAvilableIf(othersAvailable = ["R212A"]),
197 taxiThrough = True))
198lhbpGates.add(Gate("R211", "2A", "S",
199 availableFn = getAvilableIf(othersAvailable = ["R212A"]),
200 taxiThrough = True))
201lhbpGates.add(Gate("R212", "2A", "S",
202 availableFn = getAvilableIf(othersAvailable = ["R212A"]),
203 taxiThrough = True))
204lhbpGates.add(Gate("R212A", "2A", "S",
205 availableFn = getAvilableIf(othersAvailable = ["R210", "R211", "R212"]),
206 taxiThrough = True))
207lhbpGates.addSpace()
208
209lhbpGates.add(Gate("R220", "2B", "S"))
210lhbpGates.add(Gate("R221", "2B", "S"))
211lhbpGates.add(Gate("R222", "2B", "S"))
212lhbpGates.add(Gate("R223", "2B", "S"))
213lhbpGates.addSpace()
214
215lhbpGates.add(Gate("R224", "2A", "R"))
216lhbpGates.add(Gate("R225", "2A", "S"))
217lhbpGates.add(Gate("R226", "2A", "S"))
218lhbpGates.add(Gate("R227", "2A", "S"))
219lhbpGates.addNewColumn()
220
221lhbpGates.add(Gate("R270", "2A", "S"))
222lhbpGates.add(Gate("R271", "2A", "S"))
223lhbpGates.add(Gate("R272", "2A", "S"))
224lhbpGates.add(Gate("R274", "2A", "S"))
225lhbpGates.add(Gate("R275", "2A", "S"))
226lhbpGates.add(Gate("R276", "2A", "S"))
227lhbpGates.add(Gate("R277", "2A", "S"))
228lhbpGates.add(Gate("R278", "2A", "S",
229 availableFn = getAvilableIf(othersAvailable = ["R278A"]),
230 taxiThrough = True))
231lhbpGates.add(Gate("R278A", "2A", "S",
232 availableFn = getAvilableIf(othersAvailable = ["R278", "R279"]),
233 taxiThrough = True))
234lhbpGates.add(Gate("R279", "2A", "S",
235 availableFn = getAvilableIf(othersAvailable = ["R278A"]),
236 taxiThrough = True))
Note: See TracBrowser for help on using the repository browser.