Skip to content

Instantly share code, notes, and snippets.

@neilmiddleton
Created October 13, 2020 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilmiddleton/0603cb03554b3e1e1815a1e3d80a90ed to your computer and use it in GitHub Desktop.
Save neilmiddleton/0603cb03554b3e1e1815a1e3d80a90ed to your computer and use it in GitHub Desktop.
iRacing results to drivers CSV
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