Skip to content

Commit

Permalink
Make util/update.rb more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
sbeyer committed Nov 19, 2017
1 parent a6684b7 commit d14c85a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions util/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
Reads two CSVs and use the best bounds.
The file <output-csv> will contain all files of <input-csv1>
but with updated bounds of <input-csv2>, if they exist and are better.
<input-csv2> is only expected to have "group,filename" as the first two
columns and "lower,upper" as the last two columns.
EOF
exit 1
end
Expand All @@ -20,9 +23,9 @@ def read_to_hash(filename)
header = csv.shift
hashmap = csv.map do |line|
data = line.chomp.split(/,/)
[data[0..4], data[5..7].map do |val|
[data[0..1], [data[2..-4], data[-3..-1].map do |val|
val.to_i
end]
end]]
end
[header, hashmap]
end
Expand All @@ -32,13 +35,16 @@ def read_to_hash(filename)
csv2 = csv2.to_h
File.open(outfile, 'w') do |outf|
outf.print header1
csv1.each do |instance, data|
newdata = csv2[instance]
if not newdata.nil?
csv1.each do |instance, stuff_and_data|
stuff, data = stuff_and_data
new_stuff_and_data = csv2[instance]
if not new_stuff_and_data.nil?
newdata = new_stuff_and_data[1]
data[1] = [newdata[1], data[1]].max # lower bound
data[2] = [newdata[2], data[2]].min # upper bound
data[0] = data[1] if data[1] == data[2] # optimum solution
STDERR.puts "Warning: [#{instance.join('/')}] upper bound below lower bound" if data[1] > data[2]
end
outf.puts "#{instance.join(',')},#{data.join(',')}"
outf.puts "#{instance.join(',')}#{stuff.empty? ? "" : ","}#{stuff.join(',')},#{data.join(',')}"
end
end

0 comments on commit d14c85a

Please sign in to comment.