Changeset 742:464227881300 for src/mlx
- Timestamp:
- 01/02/16 12:25:47 (9 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/web.py
r740 r742 2 2 import const 3 3 import util 4 import rpccommon 4 5 5 6 from common import MAVA_BASE_URL … … 257 258 #------------------------------------------------------------------------------ 258 259 259 class Plane( object):260 class Plane(rpccommon.Plane): 260 261 """Information about an airplane in the fleet.""" 261 262 def __init__(self, s): … … 265 266 The first field is the tail number, the second field is the gate 266 267 number, the third field is the plane's status as a character.""" 268 super(Plane, self).__init__() 269 267 270 try: 268 271 words = s.split(" ") … … 271 274 272 275 status = words[2] if len(words)>2 else None 273 self.status = const.PLANE_HOME if status=="H" else \ 274 const.PLANE_AWAY if status=="A" else \ 275 const.PLANE_PARKING if status=="P" else \ 276 const.PLANE_UNKNOWN 276 self._setStatus(status) 277 277 278 278 gateNumber = words[1] if len(words)>1 else "" … … 283 283 self.tailNumber = None 284 284 285 def __repr__(self): 286 """Get the representation of the plane object.""" 287 s = "<Plane: %s %s" % (self.tailNumber, 288 "home" if self.status==const.PLANE_HOME else \ 289 "away" if self.status==const.PLANE_AWAY else \ 290 "parking" if self.status==const.PLANE_PARKING \ 291 else "unknown") 292 if self.gateNumber is not None: 293 s += " (gate " + self.gateNumber + ")" 294 s += ">" 295 return s 296 297 298 #------------------------------------------------------------------------------ 299 300 class Fleet(object): 285 #------------------------------------------------------------------------------ 286 287 class Fleet(rpccommon.Fleet): 301 288 """Information about the whole fleet.""" 302 289 def __init__(self, f): 303 290 """Construct the fleet information by reading the given file object.""" 304 self._planes = {} 291 super(Fleet, self).__init__() 292 305 293 while True: 306 294 line = readline(f) … … 308 296 309 297 plane = Plane(line) 310 if plane.tailNumber is not None: 311 self._planes[plane.tailNumber] = plane 312 313 def isGateConflicting(self, plane): 314 """Check if the gate of the given plane conflicts with another plane's 315 position.""" 316 for p in self._planes.itervalues(): 317 if p.tailNumber!=plane.tailNumber and \ 318 p.status==const.PLANE_HOME and \ 319 p.gateNumber==plane.gateNumber: 320 return True 321 322 return False 323 324 def getOccupiedGateNumbers(self): 325 """Get a set containing the numbers of the gates occupied by planes.""" 326 gateNumbers = set() 327 for p in self._planes.itervalues(): 328 if p.status==const.PLANE_HOME and p.gateNumber: 329 gateNumbers.add(p.gateNumber) 330 return gateNumbers 331 332 def updatePlane(self, tailNumber, status, gateNumber = None): 333 """Update the status of the given plane.""" 334 if tailNumber in self._planes: 335 plane = self._planes[tailNumber] 336 plane.status = status 337 plane.gateNumber = gateNumber 338 339 def __iter__(self): 340 """Get an iterator over the planes.""" 341 for plane in self._planes.itervalues(): 342 yield plane 343 344 def __getitem__(self, tailNumber): 345 """Get the plane with the given tail number. 346 347 If the plane is not in the fleet, None is returned.""" 348 return self._planes[tailNumber] if tailNumber in self._planes else None 349 350 def __repr__(self): 351 """Get the representation of the fleet object.""" 352 return self._planes.__repr__() 298 self._addPlane(plane) 353 299 354 300 #------------------------------------------------------------------------------ … … 771 717 url = MAVA_BASE_URL + "/onlinegates_set.php" 772 718 773 status = "H" if self._status==const.PLANE_HOME else \ 774 "A" if self._status==const.PLANE_AWAY else \ 775 "P" if self._status==const.PLANE_PARKING else "" 719 status = Plane.status2str(self._status) 776 720 777 721 gateNumber = self._gateNumber if self._gateNumber else ""
Note:
See TracChangeset
for help on using the changeset viewer.