[619] | 1 | #--------------------------------------------------------------------------------------
|
---|
| 2 |
|
---|
| 3 | ## @package mlx.gates
|
---|
| 4 | #
|
---|
| 5 | # The module to handle the LHBP gate information.
|
---|
| 6 | #
|
---|
| 7 |
|
---|
| 8 | #--------------------------------------------------------------------------------------
|
---|
| 9 |
|
---|
| 10 | class Gate(object):
|
---|
| 11 | """Information about a gate."""
|
---|
[1172] | 12 | @staticmethod
|
---|
| 13 | def fromJSON(data):
|
---|
| 14 | """Create the gate from the given JSON data."""
|
---|
| 15 | return Gate(data["number"], data["terminal"],
|
---|
| 16 | data["type"],
|
---|
| 17 | maxSpan = data["maxSpan"],
|
---|
| 18 | maxLength = data["maxLength"])
|
---|
| 19 |
|
---|
[619] | 20 | def __init__(self, number, terminal, type,
|
---|
[1154] | 21 | availableFn = None, taxiThrough = False,
|
---|
| 22 | maxSpan = 0.0, maxLength = 0.0):
|
---|
[619] | 23 | """Construct the gate with the given information.
|
---|
| 24 |
|
---|
| 25 | number is the gate's number as a string (as it can contain letters).
|
---|
| 26 | terminal is the terminal the gate belongs to (not used currently).
|
---|
| 27 | type is the gate's type: G for gate, S for stand.
|
---|
| 28 | availableFn is a function that can determine if the gate is available based on
|
---|
| 29 | the statuses of other gates. Its arguments are:
|
---|
| 30 | - a collection of the gates, and
|
---|
| 31 | - a set of occupied gate numbers."""
|
---|
[1154] | 32 | self.number = number
|
---|
| 33 | self.terminal = terminal
|
---|
| 34 | self.type = type
|
---|
[619] | 35 | self._availableFn = availableFn
|
---|
[1154] | 36 | self.taxiThrough = taxiThrough
|
---|
| 37 | self.maxSpan = maxSpan
|
---|
| 38 | self.maxLength = maxLength
|
---|
[619] | 39 |
|
---|
[1154] | 40 | def isAvailable(self, plane, gates, occupiedGateNumbers):
|
---|
| 41 | """Determine if this gate is available for the given plane and the
|
---|
| 42 | given the set of gates and occupied gate numbers."""
|
---|
| 43 | if self.number in occupiedGateNumbers:
|
---|
[619] | 44 | return False
|
---|
[1154] | 45 | if self._availableFn is None or \
|
---|
| 46 | self._availableFn(gates, occupiedGateNumbers):
|
---|
| 47 | return plane is None or \
|
---|
[1155] | 48 | ((self.maxSpan<0.1 or plane.wingSpan <= self.maxSpan) and
|
---|
[1156] | 49 | (self.maxLength<0.1 or plane.fuselageLength <= self.maxLength) and
|
---|
| 50 | (not plane.hasStairs or self.type!="G"))
|
---|
[1154] | 51 | else:
|
---|
| 52 | return False
|
---|
[619] | 53 |
|
---|
[1172] | 54 | def toJSON(self):
|
---|
| 55 | """Create a JSON representation of the gate."""
|
---|
| 56 | data = {}
|
---|
| 57 | for attributeName in ["number", "terminal", "type",
|
---|
| 58 | "maxSpan", "maxLength"]:
|
---|
| 59 | data[attributeName] = getattr(self, attributeName)
|
---|
| 60 | return data
|
---|
| 61 |
|
---|
[619] | 62 | #--------------------------------------------------------------------------------------
|
---|
| 63 |
|
---|
| 64 | class Gates(object):
|
---|
| 65 | """A collection of gates."""
|
---|
| 66 | # Display info type: a gate (number)
|
---|
| 67 | DISPLAY_GATE=1
|
---|
| 68 |
|
---|
| 69 | # Display info type: a space
|
---|
| 70 | DISPLAY_SPACE=2
|
---|
| 71 |
|
---|
| 72 | # Display info type: a new column
|
---|
| 73 | DISPLAY_NEW_COLUMN=3
|
---|
| 74 |
|
---|
[1172] | 75 | @staticmethod
|
---|
| 76 | def fromJSON(data):
|
---|
| 77 | """Create a gates object from the given JSON data."""
|
---|
| 78 | gates = Gates()
|
---|
| 79 | for gateData in data:
|
---|
| 80 | gates.add(Gate.fromJSON(gateData))
|
---|
| 81 | return gates
|
---|
| 82 |
|
---|
[619] | 83 | def __init__(self):
|
---|
| 84 | """Construct the gate collection."""
|
---|
| 85 | self._gates = []
|
---|
| 86 | self._displayInfos = []
|
---|
| 87 | self._numColumns = 1
|
---|
| 88 | self._numRows = 0
|
---|
| 89 | self._numRowsInColumn = 0
|
---|
| 90 |
|
---|
| 91 | @property
|
---|
| 92 | def gates(self):
|
---|
| 93 | """Get an iterator over the gates."""
|
---|
| 94 | return iter(self._gates)
|
---|
| 95 |
|
---|
| 96 | @property
|
---|
| 97 | def displayInfos(self):
|
---|
| 98 | """Get an iterator over the display info tuples.
|
---|
| 99 |
|
---|
| 100 | Each tuple consists of
|
---|
| 101 | - a type (one of the DISPLAY_XXX constants), and
|
---|
| 102 | - an additional data (the gate for DISPLAY_GATE, None for others)."""
|
---|
| 103 | return iter(self._displayInfos)
|
---|
| 104 |
|
---|
| 105 | @property
|
---|
| 106 | def numRows(self):
|
---|
| 107 | """Get the number of rows."""
|
---|
| 108 | return self._numRows
|
---|
| 109 |
|
---|
| 110 | @property
|
---|
| 111 | def numColumns(self):
|
---|
| 112 | """Get the number of columns."""
|
---|
| 113 | return self._numColumns
|
---|
| 114 |
|
---|
| 115 | def add(self, gate):
|
---|
| 116 | """Add a gate to the collection."""
|
---|
| 117 | self._gates.append(gate)
|
---|
| 118 | self._displayInfos.append((Gates.DISPLAY_GATE, gate))
|
---|
| 119 | self._addRow()
|
---|
| 120 |
|
---|
[1105] | 121 | def find(self, gateNumber):
|
---|
| 122 | """Find a gate by its number."""
|
---|
| 123 | for gate in self._gates:
|
---|
| 124 | if gate.number == gateNumber:
|
---|
| 125 | return gate
|
---|
| 126 |
|
---|
[619] | 127 | def addSpace(self):
|
---|
| 128 | """Add a space between subsequent gates."""
|
---|
| 129 | self._displayInfos.append((Gates.DISPLAY_SPACE, None))
|
---|
| 130 | self._addRow()
|
---|
| 131 |
|
---|
| 132 | def addNewColumn(self):
|
---|
| 133 | """Start a new column of gates."""
|
---|
| 134 | self._displayInfos.append((Gates.DISPLAY_NEW_COLUMN, None))
|
---|
| 135 | self._numRowsInColumn = 0
|
---|
| 136 | self._numColumns += 1
|
---|
| 137 |
|
---|
[1154] | 138 | def merge(self, otherGates):
|
---|
| 139 | """Merge the information from the given gate list (retrieved from the
|
---|
| 140 | MAVA server) into this gate list."""
|
---|
| 141 | for otherGate in otherGates.gates:
|
---|
| 142 | gate = self.find(otherGate.number)
|
---|
| 143 | if gate is None:
|
---|
| 144 | print("Received data for gate %s, but it does not exist locally!" %
|
---|
| 145 | (otherGate.number,))
|
---|
| 146 | else:
|
---|
| 147 | if gate.terminal != otherGate.terminal:
|
---|
| 148 | print("The terminal for gate %s is received as: %s" %
|
---|
| 149 | (gate.number, otherGate.terminal))
|
---|
| 150 | gate.terminal = otherGate.terminal
|
---|
| 151 | if gate.type != otherGate.type:
|
---|
| 152 | print("The type for gate %s is received as: %s" %
|
---|
| 153 | (gate.number, otherGate.type))
|
---|
| 154 | gate.type = otherGate.type
|
---|
| 155 |
|
---|
| 156 | gate.maxSpan = otherGate.maxSpan
|
---|
| 157 | gate.maxLength = otherGate.maxLength
|
---|
| 158 |
|
---|
| 159 | for gate in self.gates:
|
---|
| 160 | if gate.maxSpan==0.0 or gate.maxLength==0.0:
|
---|
| 161 | print("Gate %s has no maximal dimensions from the database" %
|
---|
| 162 | (gate.number,))
|
---|
| 163 |
|
---|
[1172] | 164 | def toJSON(self):
|
---|
| 165 | """Convert the list of gates into a JSON data."""
|
---|
| 166 | return [gate.toJSON() for gate in self._gates]
|
---|
| 167 |
|
---|
[619] | 168 | def _addRow(self):
|
---|
| 169 | """Add a new row."""
|
---|
| 170 | self._numRowsInColumn += 1
|
---|
| 171 | if self._numRowsInColumn > self._numRows:
|
---|
| 172 | self._numRows = self._numRowsInColumn
|
---|
| 173 |
|
---|
| 174 | #--------------------------------------------------------------------------------------
|
---|
| 175 |
|
---|
| 176 | def availableIf(occupiedGateNumbers, othersAvailable = []):
|
---|
| 177 | """Determine if a gate is available.
|
---|
| 178 |
|
---|
| 179 | othersAvailable is a list of numbers of gates, that must be available so
|
---|
| 180 | that the one we are considering is available."""
|
---|
| 181 | for otherNumber in othersAvailable:
|
---|
| 182 | if otherNumber in occupiedGateNumbers:
|
---|
| 183 | return False
|
---|
| 184 | return True
|
---|
| 185 |
|
---|
| 186 | #--------------------------------------------------------------------------------------
|
---|
| 187 |
|
---|
[1151] | 188 | def getAvailableIf(othersAvailable = []):
|
---|
[619] | 189 | """Get a function that determines if a gate is available based on the
|
---|
| 190 | statuses of other gates."""
|
---|
| 191 | return lambda gates, occupiedGateNumbers: availableIf(occupiedGateNumbers,
|
---|
| 192 | othersAvailable =
|
---|
| 193 | othersAvailable)
|
---|
| 194 |
|
---|
| 195 | #--------------------------------------------------------------------------------------
|
---|
| 196 |
|
---|
| 197 | # The gates at LHBP
|
---|
| 198 | lhbpGates = Gates()
|
---|
| 199 |
|
---|
[1158] | 200 | lhbpGates.add(Gate("R101", "1", "S", taxiThrough = True))
|
---|
[1151] | 201 | lhbpGates.add(Gate("R102", "1", "S"))
|
---|
| 202 | lhbpGates.add(Gate("R103", "1", "S"))
|
---|
| 203 | lhbpGates.add(Gate("R104", "1", "S",
|
---|
| 204 | availableFn = getAvailableIf(othersAvailable = ["R105"])))
|
---|
| 205 | lhbpGates.add(Gate("R105", "1", "S",
|
---|
| 206 | availableFn = getAvailableIf(othersAvailable = ["R104", "R106"])))
|
---|
| 207 | lhbpGates.add(Gate("R106", "1", "S",
|
---|
| 208 | availableFn = getAvailableIf(othersAvailable = ["R105", "R108"])))
|
---|
| 209 | lhbpGates.add(Gate("R107", "1", "S",
|
---|
| 210 | availableFn = getAvailableIf(othersAvailable = ["R108"])))
|
---|
| 211 | lhbpGates.add(Gate("R108", "1", "S",
|
---|
| 212 | availableFn = getAvailableIf(othersAvailable = ["R106", "R107"])))
|
---|
| 213 |
|
---|
[619] | 214 | lhbpGates.addSpace()
|
---|
[1151] | 215 | lhbpGates.add(Gate("R110", "1", "S",
|
---|
| 216 | availableFn = getAvailableIf(othersAvailable = ["R111"])))
|
---|
| 217 | lhbpGates.add(Gate("R111", "1", "S",
|
---|
| 218 | availableFn = getAvailableIf(othersAvailable = ["R110", "R112"])))
|
---|
| 219 | lhbpGates.add(Gate("R112", "1", "S",
|
---|
| 220 | availableFn = getAvailableIf(othersAvailable = ["R111"])))
|
---|
| 221 | lhbpGates.add(Gate("R113", "1", "S",
|
---|
| 222 | availableFn = getAvailableIf(othersAvailable = ["R112", "R114"])))
|
---|
| 223 | lhbpGates.add(Gate("R114", "1", "S",
|
---|
| 224 | availableFn = getAvailableIf(othersAvailable = ["R113"])))
|
---|
| 225 | lhbpGates.add(Gate("R115", "1", "S"))
|
---|
| 226 | lhbpGates.add(Gate("R116", "1", "S",
|
---|
[1158] | 227 | availableFn = getAvailableIf(othersAvailable = ["R117"]),
|
---|
| 228 | taxiThrough = True))
|
---|
[1151] | 229 | lhbpGates.add(Gate("R117", "1", "S",
|
---|
| 230 | availableFn = getAvailableIf(othersAvailable = ["R116", "R117A"])))
|
---|
| 231 | lhbpGates.add(Gate("R117A", "1", "S",
|
---|
| 232 | availableFn = getAvailableIf(othersAvailable = ["R116", "R117"])))
|
---|
| 233 | lhbpGates.addNewColumn()
|
---|
| 234 |
|
---|
| 235 | lhbpGates.add(Gate("G150", "1", "S"))
|
---|
| 236 | lhbpGates.add(Gate("G151", "1", "S"))
|
---|
| 237 | lhbpGates.add(Gate("G152", "1", "S"))
|
---|
| 238 | lhbpGates.add(Gate("G153", "1", "S"))
|
---|
| 239 | lhbpGates.add(Gate("G154", "1", "S"))
|
---|
| 240 | lhbpGates.add(Gate("G155", "1", "S"))
|
---|
| 241 |
|
---|
| 242 | lhbpGates.addSpace()
|
---|
[1158] | 243 | lhbpGates.add(Gate("G170", "1", "S", taxiThrough = True))
|
---|
| 244 | lhbpGates.add(Gate("G171", "1", "S", taxiThrough = True))
|
---|
| 245 | lhbpGates.add(Gate("G172", "1", "S", taxiThrough = True))
|
---|
[1151] | 246 | lhbpGates.addNewColumn()
|
---|
[619] | 247 |
|
---|
| 248 | lhbpGates.add(Gate("31", "2B", "G"))
|
---|
| 249 | lhbpGates.add(Gate("32", "2B", "G"))
|
---|
| 250 | lhbpGates.add(Gate("33", "2B", "G"))
|
---|
[1151] | 251 | lhbpGates.add(Gate("34", "2B", "G",
|
---|
| 252 | availableFn = getAvailableIf(othersAvailable = ["34L", "34R"])))
|
---|
| 253 | lhbpGates.add(Gate("34L", "2B", "G",
|
---|
| 254 | availableFn = getAvailableIf(othersAvailable = ["34", "34R"])))
|
---|
| 255 | lhbpGates.add(Gate("34R", "2B", "G",
|
---|
| 256 | availableFn = getAvailableIf(othersAvailable = ["34L", "34"])))
|
---|
| 257 | lhbpGates.add(Gate("35", "2B", "G",
|
---|
| 258 | availableFn = getAvailableIf(othersAvailable = ["35L", "35R"])))
|
---|
| 259 | lhbpGates.add(Gate("35L", "2B", "G",
|
---|
| 260 | availableFn = getAvailableIf(othersAvailable = ["35", "35R"])))
|
---|
| 261 | lhbpGates.add(Gate("35R", "2B", "G",
|
---|
| 262 | availableFn = getAvailableIf(othersAvailable = ["35L", "35"])))
|
---|
| 263 | lhbpGates.add(Gate("36", "2B", "G",
|
---|
| 264 | availableFn = getAvailableIf(othersAvailable = ["36L", "36R"])))
|
---|
| 265 | lhbpGates.add(Gate("36L", "2B", "G",
|
---|
| 266 | availableFn = getAvailableIf(othersAvailable = ["36", "36R"])))
|
---|
| 267 | lhbpGates.add(Gate("36R", "2B", "G",
|
---|
| 268 | availableFn = getAvailableIf(othersAvailable = ["36L", "36"])))
|
---|
| 269 | lhbpGates.addSpace()
|
---|
[619] | 270 |
|
---|
| 271 | lhbpGates.add(Gate("37", "2B", "G"))
|
---|
| 272 | lhbpGates.add(Gate("38", "2B", "G"))
|
---|
[1151] | 273 | lhbpGates.add(Gate("39", "2B", "G",
|
---|
| 274 | availableFn = getAvailableIf(othersAvailable = ["37L", "37R"])))
|
---|
| 275 | lhbpGates.add(Gate("39L", "2B", "G",
|
---|
| 276 | availableFn = getAvailableIf(othersAvailable = ["37", "37R"])))
|
---|
| 277 | lhbpGates.add(Gate("39R", "2B", "G",
|
---|
| 278 | availableFn = getAvailableIf(othersAvailable = ["37L", "37"])))
|
---|
| 279 | lhbpGates.addNewColumn()
|
---|
[619] | 280 |
|
---|
| 281 | lhbpGates.add(Gate("42", "2A", "G"))
|
---|
| 282 | lhbpGates.add(Gate("43", "2A", "G"))
|
---|
| 283 | lhbpGates.add(Gate("44", "2A", "G"))
|
---|
| 284 | lhbpGates.add(Gate("45", "2A", "G"))
|
---|
[1151] | 285 | lhbpGates.addSpace()
|
---|
[619] | 286 |
|
---|
| 287 | lhbpGates.add(Gate("R210", "2A", "S",
|
---|
[1151] | 288 | availableFn = getAvailableIf(othersAvailable = ["R212A"]),
|
---|
[1105] | 289 | taxiThrough = True))
|
---|
[619] | 290 | lhbpGates.add(Gate("R211", "2A", "S",
|
---|
[1151] | 291 | availableFn = getAvailableIf(othersAvailable = ["R212A"]),
|
---|
[1105] | 292 | taxiThrough = True))
|
---|
[619] | 293 | lhbpGates.add(Gate("R212", "2A", "S",
|
---|
[1151] | 294 | availableFn = getAvailableIf(othersAvailable = ["R212A"]),
|
---|
[1105] | 295 | taxiThrough = True))
|
---|
[619] | 296 | lhbpGates.add(Gate("R212A", "2A", "S",
|
---|
[1151] | 297 | availableFn = getAvailableIf(othersAvailable = ["R210", "R211", "R212"]),
|
---|
[1105] | 298 | taxiThrough = True))
|
---|
[619] | 299 | lhbpGates.addSpace()
|
---|
| 300 |
|
---|
| 301 | lhbpGates.add(Gate("R220", "2B", "S"))
|
---|
| 302 | lhbpGates.add(Gate("R221", "2B", "S"))
|
---|
| 303 | lhbpGates.add(Gate("R222", "2B", "S"))
|
---|
| 304 | lhbpGates.add(Gate("R223", "2B", "S"))
|
---|
| 305 | lhbpGates.addSpace()
|
---|
| 306 |
|
---|
[1151] | 307 | lhbpGates.add(Gate("R224", "2A", "S"))
|
---|
[619] | 308 | lhbpGates.add(Gate("R225", "2A", "S"))
|
---|
| 309 | lhbpGates.add(Gate("R226", "2A", "S"))
|
---|
| 310 | lhbpGates.add(Gate("R227", "2A", "S"))
|
---|
| 311 | lhbpGates.addNewColumn()
|
---|
| 312 |
|
---|
| 313 | lhbpGates.add(Gate("R270", "2A", "S"))
|
---|
| 314 | lhbpGates.add(Gate("R271", "2A", "S"))
|
---|
| 315 | lhbpGates.add(Gate("R272", "2A", "S"))
|
---|
[1151] | 316 | lhbpGates.add(Gate("R273", "2A", "S"))
|
---|
[619] | 317 | lhbpGates.add(Gate("R274", "2A", "S"))
|
---|
| 318 | lhbpGates.add(Gate("R275", "2A", "S"))
|
---|
| 319 | lhbpGates.add(Gate("R276", "2A", "S"))
|
---|
| 320 | lhbpGates.add(Gate("R277", "2A", "S"))
|
---|
| 321 | lhbpGates.add(Gate("R278", "2A", "S",
|
---|
[1151] | 322 | availableFn = getAvailableIf(othersAvailable = ["R278A"]),
|
---|
[1105] | 323 | taxiThrough = True))
|
---|
[619] | 324 | lhbpGates.add(Gate("R278A", "2A", "S",
|
---|
[1158] | 325 | availableFn = getAvailableIf(othersAvailable = ["R278", "R279"])))
|
---|
[619] | 326 | lhbpGates.add(Gate("R279", "2A", "S",
|
---|
[1151] | 327 | availableFn = getAvailableIf(othersAvailable = ["R278A"]),
|
---|
[1105] | 328 | taxiThrough = True))
|
---|