Package sabx10 :: Package utils :: Module sabx_ele_analyze
[hide private]
[frames] | no frames]

Source Code for Module sabx10.utils.sabx_ele_analyze

  1  ############################################################################### 
  2  # 
  3  # sabx10 - an SABX file manipulation library 
  4  # Copyright (C) 2009, 2010 Jay Farrimond (jay@sabikerides.com) 
  5  # 
  6  # This file is part of sabx10. 
  7  # 
  8  # sabx10 is free software: you can redistribute it and/or modify it under the 
  9  # terms of the GNU General Public License as published by the Free Software 
 10  # Foundation, either version 3 of the License, or (at your option) any later 
 11  # version. 
 12  # 
 13  # sabx10 is distributed in the hope that it will be useful, but WITHOUT ANY 
 14  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
 15  # A PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU General Public License along with 
 18  # sabx10.  If not, see <http://www.gnu.org/licenses/>. 
 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   
27 -def get_ride_ele_bounds(ride):
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
45 -def analyze_ride(ride, lowest, highest):
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 #if abs(rise_ele) > diff or abs(rise_usgs) > diff: 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
91 -def analyze_all_rides(rides):
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