Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parse typing practice stats
open ARGV.first do |file|
avg = lambda do |data, slot|
data.inject(0.0) do |sum, datum|
sum + datum.send(:[], slot).to_i
end / data.size
end
data = file.read.split(/\n\n## /).map do |round|
round.gsub!(/.*\n\n/, "")
round.split(/\n/).map do |row|
value = row.split(": ").last
if value.include?(":")
minutes, seconds = value.split(":").map(&:to_i)
value = minutes * 60 + seconds
end
value
end
end
puts "Rounds: #{ data.size }"
puts "WPM: #{ avg[data, 0] }"
puts "Time: #{ avg[data, 1] } seconds"
puts "Correct: #{ avg[data, 2] }"
puts "Incorrect: #{ avg[data, 3] }"
puts "Accuracy: #{ avg[data, 2] / (avg[data, 2] + avg[data, 3]) }"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment