Skip to content

Instantly share code, notes, and snippets.

@hannahwhy
Last active December 19, 2015 12:29
Show Gist options
  • Save hannahwhy/5955346 to your computer and use it in GitHub Desktop.
Save hannahwhy/5955346 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
if ARGV.length < 2
puts "Usage: #$0 [DIRECTORY] [GOAL FILE]"
exit 1
end
values = {}
files = []
goalfile = File.expand_path(ARGV[1])
input_set = Dir["#{ARGV[0]}/*"].map { |fn| File.expand_path(fn) }
((input_set - [goalfile]).sort + [goalfile]).each do |c|
files << ((c == goalfile) ? 'Cases count' : File.basename(c))
File.read(c).split("\n").map { |l| l.split("\t") }.each do |table, cnt|
values[table] ||= []
values[table] << cnt
end
maxlen = values.values.map(&:length).max
values.each do |k, v|
if v.length != maxlen
(maxlen - v.length).times do
v << '0'
end
end
end
end
puts "Table\t" + files.join("\t") + "\tLatest (actual - expected)"
values.keys.sort.each do |k|
len = values[k].length
diff = values[k][len - 2].to_i - values[k].last.to_i
puts "#{k}\t#{values[k].join("\t")}\t#{diff}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment