# Expects "_results" folders containing .results files generated by experiment.rb
# Note: don't run with untrusted .results files!

SINGLE_PARAM_EXPERIMENTS = [
        "kernel_num",
        "buffer_num",
        "capture_num",
        "dimensions",
        "loopnests",
        "type",
        "mix",
]

require "./ruby_array_ext.rb"

SINGLE_PARAM_EXPERIMENTS.each do |exp_name|
        results = {}
        row_names = []
        col_ids = []
        Dir["*_results"].each do |dir|
                if dir =~ /(.*)_results/
                        platform_name = $1
                        row_names << platform_name
                        res = eval(File.read("#{dir}/#{exp_name}.results"))
                        results[platform_name] = res
                        res.each do |id, vals|
                                col_ids << id unless col_ids.include? id
                        end
                end
        end
        File.open("#{exp_name}.csv", "w+") do |csv_file|
                #p row_names
                #p col_ids

                csv_file.puts "; #{col_ids.join("; ")}"

                row_names.sort.each do |platform|
                        csv_file.print "#{platform}; "
                        res_string = col_ids.map do |c|
                                begin
                                        results[platform][c].median
                                rescue => exception
                                        -1
                                end
                        end.join("; ")
                        csv_file.puts res_string
                end
        end
end
