1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Analyze the elevations for an SABX 1.0 file.
23 """
24
25 from sabx10.oxm import mile_feet, meter_feet
26
28 """
29 Get the bounds of the elevation range for the ride.
30
31 @param ride: ride to analyze
32 @type ride: SABX 1.0 L{Ride}
33
34 @return: lowest elevation, highest elevation
35 @rtype: (C{float},C{float})
36 """
37 lowest = 100000.0
38 highest = 0.0
39 for seg in ride.segs:
40 l, h = seg.find_lowest_highest()
41 lowest = min(lowest, l)
42 highest = max(highest, h)
43 return lowest, highest
44
46 """
47 Analyze the elevations for the ride. Specifically, check the differences
48 in the elevations between the end of each segment and the start of the next
49 segment in the ride. Check this for the ele and the usgs values. When the
50 ele and usgs changes fall outside the acceptable range, graph them. The
51 acceptable range is defined as a percentage of the difference between the
52 lowest and highest elevations.
53
54 @param ride: ride to check
55 @type ride: SABX 1.0 L{Ride}
56 @param lowest: lowest elevation for the ride
57 @type lowest: C{float}
58 @param highest: highest elevation for the ride
59 @type highest: C{float}
60 """
61 diff = (highest - lowest) * 0.03
62 for seg in ride.segs:
63 print "segment %s (%s)" % (seg.id, seg.road)
64
65 if seg.waypoints[-1].ele and seg.waypoints[-2].usgs:
66 rise_ele = run_ele = grade_ele = 0.0
67 rise_ele = (seg.waypoints[-1].ele - seg.waypoints[-2].ele)
68 rise_ele *= meter_feet
69 run_ele = seg.waypoints[-1].calculate_distance(seg.waypoints[-2])
70 run_ele *= mile_feet
71 if run_ele != 0.0:
72 grade_ele = (rise_ele / run_ele) * 100.0
73
74 rise_usgs = run_usgs = grade_usgs = 0.0
75 rise_usgs = (seg.waypoints[-1].usgs - seg.waypoints[-2].usgs)
76 rise_usgs *= meter_feet
77 run_usgs = seg.waypoints[-1].calculate_distance(seg.waypoints[-2])
78 run_usgs *= mile_feet
79 if run_usgs != 0.0:
80 grade_usgs = (rise_usgs / run_usgs) * 100.0
81
82
83 if abs(rise_ele - rise_usgs) > diff:
84 print "| %s %s, %s" % ("*"*(abs(int(grade_ele))),
85 rise_ele, run_ele)
86 print "| %s %s, %s" % ("*"*(abs(int(grade_usgs))),
87 rise_usgs, run_usgs)
88 else:
89 print "NO USGS"
90
92 """
93 Analyze all the rides in the ride list.
94 """
95 for ride in rides:
96 l, h = get_ride_ele_bounds(ride)
97 print ""
98 print "======="
99 print "RIDE %s" % ride.id
100 print "======="
101 print "range: %s, %s, %s" % (l, h, h-l)
102 analyze_ride(ride, l, h)
103