Skip to content

Instantly share code, notes, and snippets.

@tejom
Created September 5, 2016 07:51
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 tejom/918069907289b40b591f1e046552bf7a to your computer and use it in GitHub Desktop.
Save tejom/918069907289b40b591f1e046552bf7a to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'csv'
FILE_NAME = "./res3.csv"
AUD_RATE = 0.759
POUND_RATE = 1.3
CAD_RATE = 0.77
KR_RATE = 0.116852
numbers = []
def clean_num(n)
n.gsub!(/[$,]/,"")
n.gsub!(/year|yr/i,"")
if n =~ /aud/i
n.gsub!(/aud/i,"")
amount = n.match /\d+[.]?\d/
n.gsub!(amount[0], (amount[0].to_i * AUD_RATE).to_s)
end
if n =~ /kr/i
n.gsub!(/kr/i,"")
amount = n.match /\d+[.]?\d/
n.gsub!(amount[0], (amount[0].to_i * KR_RATE).to_s)
end
if n =~ /GBP/i || n =~ /£/
n.gsub!("£","")
amount = n.match /\d+[.]?\d/
n.gsub!(amount[0], (amount[0].to_i * POUND_RATE).to_s)
end
if n =~ /cad/i
n.gsub!(/cad/i,"")
amount = n.match /\d+[.]?\d/
n.gsub!(amount[0], (amount[0].to_i * CAD_RATE).to_s)
end
if n =~ /(hour)|(hr)/
n = n[/^\S+\b/].to_i * 40 *52
return n # this is an int
else
n = n[/^\S+\b/]
end
if n =~ /k/i
with_k = n.gsub(/k/i,"").to_i
if with_k < 10000
return with_k * 1000 #this is an int
end
return with_k #most likely the k wasnt important
end
return n.to_i
end
total = 0
count =0
total_exp =0
count_exp =0
CSV.foreach(FILE_NAME) do |row|
if (row[2] != "Salary" && !row[2].nil?)
num =clean_num row[2]
if num > 10000 #ignore errors, to small
total += num
row_exp = row[5]
exp= !row_exp.nil? ? row_exp[/^\d+/].to_i : -1
total_exp += exp if exp >=1
count_exp += 1 if exp >=1
numbers << {:sal => num , :location => row[4], :exp => exp, :title => row[1]}
count += 1
end
end
end
sort_info = numbers.sort_by { |h| h[:sal] }
puts sort_info
exp_array = []
(0..50).to_a.each { |n| exp_array[n] = {:exp => n, :count =>0,:total =>0, :avg =>0, :per =>0}}
numbers.each { |r|
if r[:exp] > -1
t = exp_array[r[:exp]]
t[:count] +=1
t[:total] += r[:sal]
t[:avg] = t[:total]/t[:count]
t[:per] = (t[:count].to_f/count.to_f * 100).round 2
exp_array[r[:exp]] = t
end
}
puts "Counted: #{count}"
puts "Average: #{total/count}"
puts "Experiece Counted: #{count_exp}"
puts "Experience Average: #{total_exp/count_exp}"
puts exp_array
puts exp_array.sort_by {|r| r[:per]}
puts exp_array.sort_by {|r| r[:avg]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment