Created
October 13, 2020 10:27
-
-
Save neilmiddleton/0603cb03554b3e1e1815a1e3d80a90ed to your computer and use it in GitHub Desktop.
iRacing results to drivers CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
require 'chronic_duration' | |
teams = [] | |
results = CSV.read('./eventresult.csv', | |
encoding: 'windows-1251:utf-8', | |
headers: true) | |
team = {} | |
results.each do |row| | |
if row["Cust ID"] == row["Team ID"] | |
teams << team unless team == {} | |
team = {} | |
team[:name] = row["Name"] | |
team[:pro] = row["Car #"].to_i < 100 || (row["Car #"].to_i > 199 && row["Car #"].to_i < 300) | |
team[:number] = row["Car #"].to_i | |
team[:avg_lap] = ChronicDuration.parse row["Average Lap Time"] | |
team[:fast_lap] = ChronicDuration.parse row["Fastest Lap Time"] | |
team[:inc] = row["Inc"].to_i | |
team[:drivers] = [] | |
else | |
driver = {} | |
driver[:name] = row["Name"] | |
driver[:avg_lap] = ChronicDuration.parse row["Average Lap Time"] | |
driver[:fast_lap] = ChronicDuration.parse row["Fastest Lap Time"] | |
driver[:inc] = row["Inc"].to_i | |
driver[:laps] = row["Laps Comp"].to_i | |
team[:drivers] << driver | |
end | |
end | |
teams.each do |team| | |
team[:drivers].each do |driver| | |
puts "#{team[:name]},#{team[:number]},#{team[:pro]},#{driver[:name]},#{driver[:avg_lap]},#{driver[:fast_lap]},#{driver[:laps]},#{driver[:inc]}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment