Changeset 1171:ac0820702c0c for src
- Timestamp:
- 10/20/24 12:56:57 (5 weeks ago)
- Branch:
- python3
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/rpccommon.py
r1156 r1171 10 10 class Plane(object): 11 11 """Information about an airplane in the fleet.""" 12 _jsonAttributes = ["tailNumber", "aircraftType", 13 "dow", "dowNumCabinCrew", "maxPassengers", 14 "fuselageLength", "wingSpan"] 15 12 16 @staticmethod 13 17 def str2status(letter): … … 25 29 "P" if status==const.PLANE_PARKING else "" 26 30 31 @staticmethod 32 def fromJSON(data): 33 """Create a Plane object from the given JSON data.""" 34 plane = Plane() 35 36 for attributeName in Plane._jsonAttributes: 37 setattr(plane, attributeName, data[attributeName]) 38 plane.status = const.PLANE_AWAY 39 plane.gateNumber = "-" 40 41 return plane 42 27 43 @property 28 44 def hasStairs(self): … … 32 48 const.AIRCRAFT_F70, 33 49 const.AIRCRAFT_DH8D] 50 51 def toJSON(self): 52 """Create a JSON representation of the Plane object from the given JSON data.""" 53 data = {} 54 for attributeName in Plane._jsonAttributes: 55 data[attributeName] = getattr(self, attributeName) 56 return data 34 57 35 58 def _setStatus(self, letter): … … 53 76 class Fleet(object): 54 77 """Information about the whole fleet.""" 78 @staticmethod 79 def fromJSON(data): 80 """Load the fleet data from the given JSON file.""" 81 fleet = Fleet() 82 for planeData in data: 83 fleet._addPlane(Plane.fromJSON(planeData)) 84 return fleet 85 55 86 def __init__(self): 56 87 """Construct the fleet information by reading the given file object.""" … … 96 127 plane.gateNumber = gateNumber 97 128 129 def toJSON(self): 130 """Convert the fleet into a JSON data.""" 131 return [plane.toJSON() for plane in self._planes.values()] 132 98 133 def _addPlane(self, plane): 99 134 """Add the given plane to the fleet."""
Note:
See TracChangeset
for help on using the changeset viewer.