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 | @staticmethod
|
---|
12 | def _formatLine(timeStr, line):
|
---|
13 | """Format the given time string and line as needed for the ACARS and
|
---|
14 | some other things."""
|
---|
15 | return "[" + timeStr + "]-[" + line + "]"
|
---|
16 |
|
---|
17 | def __init__(self, gui):
|
---|
18 | """Initialize the PIREP from the given GUI."""
|
---|
19 | self.bookedFlight = gui.bookedFlight
|
---|
20 | self.cargoWeight = gui.cargoWeight
|
---|
21 |
|
---|
22 | self.filedCruiseAltitude = gui.filedCruiseAltitude
|
---|
23 | self.cruiseAltitude = gui.cruiseAltitude
|
---|
24 | self.route = gui.route
|
---|
25 |
|
---|
26 | self.departureMETAR = gui.departureMETAR.upper()
|
---|
27 | self.arrivalMETAR = gui.arrivalMETAR.upper()
|
---|
28 |
|
---|
29 | self.departureRunway = gui.departureRunway.upper()
|
---|
30 | self.sid = gui.sid.upper()
|
---|
31 |
|
---|
32 | self.star = gui.star
|
---|
33 | self.transition = gui.transition
|
---|
34 | self.approachType = gui.approachType.upper()
|
---|
35 | self.arrivalRunway = gui.arrivalRunway.upper()
|
---|
36 |
|
---|
37 | self.flightType = gui.flightType
|
---|
38 | self.online = gui.online
|
---|
39 |
|
---|
40 | self.comments = gui.comments
|
---|
41 | self.flightDefects = gui.flightDefects
|
---|
42 |
|
---|
43 | flight = gui.flight
|
---|
44 | self.blockTimeStart = flight.blockTimeStart
|
---|
45 | self.flightTimeStart = flight.flightTimeStart
|
---|
46 | self.flightTimeEnd = flight.flightTimeEnd
|
---|
47 | self.blockTimeEnd = flight.blockTimeEnd
|
---|
48 | self.flownDistance = flight.flownDistance
|
---|
49 | self.fuelUsed = flight.endFuel - flight.startFuel
|
---|
50 |
|
---|
51 | logger = gui.logger
|
---|
52 | self.rating = logger.getRating()
|
---|
53 | self.logLines = logger.lines
|
---|
54 | self.faultLineIndexes = logger.faultLineIndexes
|
---|
55 |
|
---|
56 | def getACARSText(self):
|
---|
57 | """Get the ACARS text.
|
---|
58 |
|
---|
59 | This is a specially formatted version of the log without the faults."""
|
---|
60 | text = "[MAVA LOGGER X LOG]-[%s]" % (const.VERSION,)
|
---|
61 | for index in range(0, len(self.logLines)):
|
---|
62 | if index not in self.faultLineIndexes:
|
---|
63 | (timeStr, line) = self.logLines[index]
|
---|
64 | if timeStr is not None:
|
---|
65 | text += PIREP._formatLine(timeStr, line)
|
---|
66 | return text
|
---|
67 |
|
---|
68 | def getRatingText(self):
|
---|
69 | """Get the rating text.
|
---|
70 |
|
---|
71 | This is a specially formatted version of the lines containing the
|
---|
72 | faults."""
|
---|
73 | text = ""
|
---|
74 | for index in self.faultLineIndexes:
|
---|
75 | (timeStr, line) = self.logLines[index]
|
---|
76 | if timeStr is not None:
|
---|
77 | text += PIREP._formatLine(timeStr, line)
|
---|
78 | text += "\n"
|
---|
79 |
|
---|
80 | text += "\n[Flight Rating: %.1f]" % (max(0.0, self.rating),)
|
---|
81 |
|
---|
82 | return text
|
---|
83 |
|
---|
84 | def getTimeComment(self):
|
---|
85 | """Get the time comment.
|
---|
86 |
|
---|
87 | This is basically a collection of the delay codes, if any."""
|
---|
88 | # FIXME: implement the proper delay codes
|
---|
89 | return "UTC"
|
---|
90 |
|
---|
91 | def getSTAR(self):
|
---|
92 | """Get the STAR and/or the transition."""
|
---|
93 | star = self.star if self.star is not None else ""
|
---|
94 | if self.transition is not None:
|
---|
95 | if star: star += ", "
|
---|
96 | star += self.transition
|
---|
97 | return star.upper()
|
---|