Sha256: df8985eb79dda76a181eb7a3e4930047aacc2fb6640a3da5534c8dce4a237b77
Contents?: true
Size: 1.31 KB
Versions: 3
Compression:
Stored size: 1.31 KB
Contents
module HRMParser class TrackPoint RAD_PER_DEG = 0.017453293 # PI/180 attr_accessor :lat, :lng, :altitude, :speed, :hr, :distance, :time, :cadence def initialize(opts = {:lat => nil, :lng => nil, :altitude => nil, :speed => nil, :hr => nil, :distance => nil, :cadence => nil, :time => Time.now}) @lat = opts[:lat] @lng = opts[:lng] @altitude = opts[:altitude] @speed = opts[:speed] @hr = opts[:hr] @distance = opts[:distance] @time = opts[:time] @cadence = opts[:cadence] end def calc_distance(pointA, pointB) return 0 if pointA.nil? || pointA.lat.nil? dlng = pointB.lng - pointA.lng dlat = pointB.lat - pointA.lat dlat_rad = dlat * RAD_PER_DEG dlng_rad = dlng * RAD_PER_DEG lat1_rad = pointA.lat * RAD_PER_DEG lng1_rad = pointA.lng * RAD_PER_DEG lat2_rad = pointB.lat * RAD_PER_DEG lng2_rad = pointB.lng * RAD_PER_DEG a = (Math.sin(dlat_rad/2))**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * (Math.sin(dlng_rad/2))**2 c = 2 * Math.atan2( Math.sqrt(a), Math.sqrt(1-a)) return 6371000 * c end def calc_speed(pointA, pointB) return 0 if pointA.nil? || pointA.lat.nil? time_delta = pointB.time - pointA.time distance_delta = pointB.distance - pointA.distance return distance_delta / time_delta end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
teich-hrmparser-0.4.1 | lib/hrmparser/trackpoint.rb |
teich-hrmparser-0.4.2 | lib/hrmparser/trackpoint.rb |
teich-hrmparser-0.4.3 | lib/hrmparser/trackpoint.rb |