...
 
Commits (2)
......@@ -2,7 +2,7 @@ require "csv"
require "./cycling/**"
module Cycling
VERSION = "0.3.3"
VERSION = "0.3.4"
# Initializing
Cycling::Options
......@@ -32,12 +32,12 @@ module Cycling
puts "Fields are optional, just press ENTER to skip"
print "Enter Date (YYYYMMDD):"
d1 = read_line
print "Enter Distance (Miles or Kilometers):"
print "Enter Distance (Kilometers):"
d2 = read_line
print "Enter Time (Enter as Seconds):"
d3 = read_line
# d4 will be set below in the conversions
print "Enter Max Speed (MPH or KPH):"
print "Enter Max Speed (KPH):"
d5 = read_line
print "Enter Average Heart Rate:"
d6 = read_line
......@@ -45,6 +45,7 @@ module Cycling
d7 = read_line
print "Enter Comments:"
d8 = read_line
# Convert to nil to save on data size
d1 = d1.empty? ? nil : d1.chomp.to_i
d2 = d2.empty? ? nil : d2.chomp.to_f32
......@@ -57,16 +58,12 @@ module Cycling
# Create new row of test data
def self.build_file(d1, d2, d3, d4, d5, d6, d7, d8)
# Prompt user for info
# Build CSV Row
result = CSV.build do |csv|
csv.row d1, d2, d3, d4, d5, d6, d7, d8
end
# Write data to file
File.write(ENV["file"], result, mode: "a")
# Some Text to know it all worked.
puts "Success: Data written to #{ENV["file"]}."
end
......
......@@ -16,7 +16,7 @@ class Cycling::AAT
a = Math.sin(dlat_rad/2)**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(dlon_rad/2)**2
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
rm * c # Delta in meters
rm * c # Return distance in meters
end
def self.import(file_name)
......@@ -38,18 +38,18 @@ class Cycling::AAT
dist_arr = Array(Float64|Int64).new
(0..(aat_arr.size-1)).each do |m|
# (m = 5) ? exit : nil
if m != 5
if m != aat_arr.size-1
dist_arr << Cycling::AAT.distance([aat_arr[m][0].to_f64, aat_arr[m][1].to_f64],[aat_arr[m+1][0].to_f64, aat_arr[m+1][1].to_f64])
else
end
end
fin_date = aat_arr[0][-1].to_s.gsub(/T.*/im,"").gsub('-',"")
fin_dist = (dist_arr.sum*1000).to_i
fin_dist = dist_arr.sum.to_i
# TODO: Calculate avg speed
# puts (aat_arr[0][-1].to_s.gsub(/.*T/im,"").gsub(".000Z","").to_i)
# ( aat_arr[-1][-1].to_s.gsub(/T.*/im,"").gsub('-',""))
ENV["file"] ||= "./data.csv"
File.exists?(ENV["file"]) ? true : Cycling.create_file
Cycling.build_file(fin_date, fin_dist, nil, nil, nil, nil, nil, nil)
......