The point of the script below is to read in the 10th column which is the total number of minutes a runner took to finish the marathon and convert it into form of "hours:minutes:seconds". Is there a better way?
require 'csv'
File.open('bostonmarathon-2012-results.txt', 'w') { |f|
skip = true
CSV.foreach("bostonmarathon-2012-results.csv") do |row|
if skip
skip = false
else
total_seconds = row[10].to_f * 60
seconds = total_seconds % 60
minutes = (total_seconds / 60) % 60
hours = total_seconds / (60 * 60)
f.puts(format("%02d:%02d:%02d", hours, minutes, seconds))
end
end
}
Time starts as in total minutes in decimal format: 142.93
Example Data:
division,name,city,gender,age,official,bib,overall,state,genderdiv,net,country
4 / 26,"Soejima, Masazumi",Fukuoka City,M,41,83.45,W1,4 / 35,,4 / 26,83.45,JPN
14 / 4335,"Gebremariam, Gebregziabher",Tigray,M,27,142.93,2,14 / 21616,,14 / 12621,142.93,ETH
6 / 26,"Van Dyk, Ernst F.",Paarl,M,39,84.38,W2,6 / 35,,6 / 26,84.38,RSA
2 / 26,"Fearnley, Kurt H.",Hamilton,M,31,81.65,W3,2 / 35,,2 / 26,81.65,AUS
3 / 26,"Hokinoue, Kota",Iizuka,M,38,83.43,W4,3 / 35,,3 / 26,83.43,JPN