1 | # The PIREP class collecting all information needed for a PIREP
|
---|
2 |
|
---|
3 | #------------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | import const
|
---|
6 |
|
---|
7 | #------------------------------------------------------------------------------
|
---|
8 |
|
---|
9 | class PIREP(object):
|
---|
10 | """A pilot's report of a flight."""
|
---|
11 | _delayCodeNames = { const.DELAYCODE_LOADING : "Loading Problems",
|
---|
12 | const.DELAYCODE_NETWORK : "Net Problems",
|
---|
13 | const.DELAYCODE_SYSTEM : "System Crash/Freezing",
|
---|
14 | const.DELAYCODE_TRAFFIC : "Traffic Problems",
|
---|
15 | const.DELAYCODE_WEATHER : "Weather Problems",
|
---|
16 | const.DELAYCODE_VATSIM : "VATSIM Problem",
|
---|
17 | const.DELAYCODE_CONTROLLER : "Controller's Fault",
|
---|
18 | const.DELAYCODE_NAVIGATION : "Navigation Problem",
|
---|
19 | const.DELAYCODE_APRON : "Apron Navigation Problems",
|
---|
20 | const.DELAYCODE_PERSONAL : "Personal Reasons" }
|
---|
21 |
|
---|
22 | @staticmethod
|
---|
23 | def _formatLine(timeStr, line):
|
---|
24 | """Format the given time string and line as needed for the ACARS and
|
---|
25 | some other things."""
|
---|
26 | return "[" + timeStr + "]-[" + line + "]"
|
---|
27 |
|
---|
28 | def __init__(self, gui):
|
---|
29 | """Initialize the PIREP from the given GUI."""
|
---|
30 | self.bookedFlight = gui.bookedFlight
|
---|
31 | self.cargoWeight = gui.cargoWeight
|
---|
32 |
|
---|
33 | self.filedCruiseAltitude = gui.filedCruiseAltitude
|
---|
34 | self.cruiseAltitude = gui.cruiseAltitude
|
---|
35 | self.route = gui.route
|
---|
36 |
|
---|
37 | self.departureMETAR = gui.departureMETAR.upper()
|
---|
38 | self.arrivalMETAR = gui.arrivalMETAR.upper()
|
---|
39 |
|
---|
40 | self.departureRunway = gui.departureRunway.upper()
|
---|
41 | self.sid = gui.sid.upper()
|
---|
42 |
|
---|
43 | self.star = gui.star
|
---|
44 | self.transition = gui.transition
|
---|
45 | self.approachType = gui.approachType.upper()
|
---|
46 | self.arrivalRunway = gui.arrivalRunway.upper()
|
---|
47 |
|
---|
48 | self.flightType = gui.flightType
|
---|
49 | self.online = gui.online
|
---|
50 |
|
---|
51 | self.comments = gui.comments
|
---|
52 | self.flightDefects = gui.flightDefects
|
---|
53 | self.delayCodes = gui.delayCodes
|
---|
54 |
|
---|
55 | flight = gui.flight
|
---|
56 | self.blockTimeStart = flight.blockTimeStart
|
---|
57 | self.flightTimeStart = flight.flightTimeStart
|
---|
58 | self.flightTimeEnd = flight.flightTimeEnd
|
---|
59 | self.blockTimeEnd = flight.blockTimeEnd
|
---|
60 | self.flownDistance = flight.flownDistance
|
---|
61 | self.fuelUsed = flight.endFuel - flight.startFuel
|
---|
62 |
|
---|
63 | logger = gui.logger
|
---|
64 | self.rating = logger.getRating()
|
---|
65 | self.logLines = logger.lines
|
---|
66 | self.faultLineIndexes = logger.faultLineIndexes
|
---|
67 |
|
---|
68 | def getACARSText(self):
|
---|
69 | """Get the ACARS text.
|
---|
70 |
|
---|
71 | This is a specially formatted version of the log without the faults."""
|
---|
72 | text = "[MAVA LOGGER X LOG]-[%s]" % (const.VERSION,)
|
---|
73 | for index in range(0, len(self.logLines)):
|
---|
74 | if index not in self.faultLineIndexes:
|
---|
75 | (timeStr, line) = self.logLines[index]
|
---|
76 | if timeStr is not None:
|
---|
77 | text += PIREP._formatLine(timeStr, line)
|
---|
78 | return text
|
---|
79 |
|
---|
80 | def getRatingText(self):
|
---|
81 | """Get the rating text.
|
---|
82 |
|
---|
83 | This is a specially formatted version of the lines containing the
|
---|
84 | faults."""
|
---|
85 | text = ""
|
---|
86 | for index in self.faultLineIndexes:
|
---|
87 | (timeStr, line) = self.logLines[index]
|
---|
88 | if timeStr is not None:
|
---|
89 | text += PIREP._formatLine(timeStr, line)
|
---|
90 | text += "\n"
|
---|
91 |
|
---|
92 | text += "\n[Flight Rating: %.1f]" % (max(0.0, self.rating),)
|
---|
93 |
|
---|
94 | return text
|
---|
95 |
|
---|
96 | def getTimeComment(self):
|
---|
97 | """Get the time comment.
|
---|
98 |
|
---|
99 | This is basically a collection of the delay codes, if any."""
|
---|
100 | if not self.delayCodes:
|
---|
101 | return "UTC"
|
---|
102 | else:
|
---|
103 | s = ""
|
---|
104 | for code in self.delayCodes:
|
---|
105 | if s: s += ", "
|
---|
106 | s += PIREP._delayCodeNames[code]
|
---|
107 | return s
|
---|
108 |
|
---|
109 | def getSTAR(self):
|
---|
110 | """Get the STAR and/or the transition."""
|
---|
111 | star = self.star if self.star is not None else ""
|
---|
112 | if self.transition is not None:
|
---|
113 | if star: star += ", "
|
---|
114 | star += self.transition
|
---|
115 | return star.upper()
|
---|