1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Create the table data and orchestrate turning it into PDF files.
23 """
24 from sabx10.oxm import process_rides, parse_top_level, Turn, Stop, Poi
25
26 from instruction_pdf import InstructionPdfGenerator
27
29 """
30 Format a turn as a table item.
31
32 Landmark is either "Parking" or "T - #", with # being the turn index.
33
34 Distance is how far into the ride the turn occurs.
35
36 Description is the turn cue.
37
38 Length is the length of the segment turning on to, saying how long you stay
39 on the road you're turning on to.
40
41 @param turn: L{Turn} to process
42 @type turn: L{Turn} object
43 @param segs: segment list, to get Length from
44 @type segs: C{list} of L{Segment}
45
46 @return: tuple of (landmark, distance, description, length)
47 @rtype: (C{string},C{string},C{string},C{string})
48 """
49 if turn.index == 0:
50 landmark = "Parking"
51 else:
52 landmark = "T - %s" % turn.index
53 distance = "%.2f" % turn.distance
54 description = " ".join(turn.cue.split())
55 length = "%.2f" % segs[turn.index].length
56
57 return (landmark, distance, description, length)
58
60 """
61 Format a stop as a table item.
62
63 Landmark is "S - #", with # being the stop index.
64
65 Distance is how far into the ride the stop occurs.
66
67 Description is the stop description.
68
69 Length is filled with the stop type.
70
71 @param stop: L{Stop} to process
72 @type stop: L{Stop} object
73
74 @return: tuple of (landmark, distance, description, length)
75 @rtype: (C{string},C{string},C{string},C{string})
76 """
77 landmark = "S - %s" % stop.index
78 if stop.off_route >= 0.1:
79 distance = "%.1f + %.1f" % (stop.distance, stop.off_route)
80 else:
81 distance = "%.1f" % stop.distance
82 if stop.off_route >= 0.1:
83 description = "%s (%.1f miles off route)" % (stop.description,
84 stop.off_route)
85 description = " ".join(description.split())
86 else:
87 description = " ".join(stop.description.split())
88 length = stop.type
89
90 return (landmark, distance, description, length)
91
93 """
94 Format a poi as a table item.
95
96 Landmark is "P - #", with # being the poi index.
97
98 Distance is how far into the ride the poi occurs.
99
100 Description is the poi description.
101
102 Length is filled with the string "POI".
103
104 @param poi: L{Poi} to process
105 @type poi: L{Poi} object
106
107 @return: tuple of (landmark, distance, description, length)
108 @rtype: (C{string},C{string},C{string},C{string})
109 """
110 landmark = "P - %s" % poi.index
111 if poi.off_route >= 0.1:
112 distance = "%.1f + %.1f" % (poi.distance, poi.off_route)
113 else:
114 distance = "%.1f" % poi.distance
115 if poi.off_route >= 0.1:
116 description = "%s (%.1f miles off route)" % (poi.description,
117 poi.off_route)
118 description = " ".join(description.split())
119 else:
120 description = " ".join(poi.description.split())
121 length = "POI"
122
123 return (landmark, distance, description, length)
124
126 """
127 Create a list of data lines to generate the PDF table from. The list is
128 filled with the turns, stops, and pois for the given ride.
129
130 @param ride: L{Ride} to process
131 @type ride: L{Ride} object
132
133 @return: C{list} of (landmark, distance, description, length)
134 @rtype: C{list} of (C{string},C{string},C{string},C{string})
135 """
136 processed = []
137 for item in ride.combined:
138 if isinstance(item, Turn):
139 processed.append(_convert_turn(item, ride.segs))
140 elif isinstance(item, Stop):
141 processed.append(_convert_stop(item))
142 elif isinstance(item, Poi):
143 processed.append(_convert_poi(item))
144
145 processed.append( (
146 "Finish",
147 "%.2f" % ride.distance,
148 "Arrive at finish!",
149 "Finish"
150 ))
151
152 return processed
153
171