#!/usr/bin/env ruby require 'optparse' require 'csv' # This program may be distributed under the terms of the # Public Distribution License: http://pdl.apotheon.org def set_values( path ) CSV.readlines(path).collect do |stats| [ stats[0], [ stats[1].to_f, stats[2].to_f ] ] end end def decel_curve( statistics ) statistics.collect do |stats| [ stats[0], 10 - (stats[1][0] / stats[1][1]) ] end.sort! {|a,b| a[1] <=> b[1]}.reverse end def split_percent( statistics ) statistics.collect do |stats| name = stats[0] neg = stats[1][0] pos = stats[1][1] if neg == pos [name, 5] elsif neg > pos [name, (5 * pos / neg)] elsif neg < pos [name, (10 - 5 * neg / pos)] end end.sort! {|a,b| a[1] <=> b[1]}.reverse end help_text = { :type => "Specify the type of output you want. At this time, the only option that has been implemented is 'd', which indicates a decelerating curve function whose maximum output value is 10.00. If the '-t' option is not specified, the default of a linear function whose output value ranges between 0.00 and 10.00 is used." } if $0 == __FILE__ type = 't' opts = OptionParser.new do |opts| opts.on('--type=OUT_TYPE', '-t=OUT_TYPE', help_text[:type]) do |val| type = val end end opts.parse! path = ARGV[0] statistics = set_values(path) if type == 'd' decel_curve(statistics) else split_percent(statistics) end.each do |record| print record[0], ' : ' printf("%.2f\n", record[1]) end end