Sha256: 7f31fc6828d3a5eea600d1bdb8cc3942b344b9e5e8c06606ed4fbb848ed21967
Contents?: true
Size: 1.46 KB
Versions: 5
Compression:
Stored size: 1.46 KB
Contents
module HRMParser class TrackPoint RAD_PER_DEG = 0.017453293 # PI/180 attr_accessor :lat, :lng, :altitude, :speed, :hr, :distance, :time, :cadence, :temp, :kcal, :epoc, :respiration, :ventilation, :vo2, :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? || pointB.nil? || pointB.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 nil if pointA.nil? || pointA.lat.nil? || pointB.nil? || pointB.lat.nil? time_delta = pointB.time - pointA.time return nil if time_delta == 0 distance_delta = pointB.distance - pointA.distance return distance_delta / time_delta end end end
Version data entries
5 entries across 5 versions & 2 rubygems