Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (50 sloc) 1.53 KB
# encoding: utf-8
def accentless_name(name)
{ 'âàä' => 'a',
'êèëé' => 'e',
'î' => 'i',
'ô' => 'o',
'ûùü' => 'u',
'ç' => 'c',
}.reduce(name) do |string,map|
string.tr(map[0], map[1])
end
end
def accent_insensitive_match(name1, name2)
accentless_name(remove_middlename(name1)) == accentless_name(remove_middlename(name2))
end
def remove_middlename(name)
name = name.split(/\s+/)
return name.first if name.size == 1
name.first + " " + name.last
end
CACHE = {}
def fname(name, people)
return CACHE[name] if CACHE[name]
just_lastname = !name.include?(" ")
people.find do |r|
pname = r[0]
pname = pname.split(/\s+/).last if just_lastname
return CACHE[name] = r[0] if accent_insensitive_match(pname, name)
end
nil
end
require 'yaml'
require 'csv'
Encoding.default_internal = 'utf-8'
people = CSV.read('city_council.csv', encoding: 'utf-8', headers: true)
data = YAML.load_file('attendance.yml')
namedata = Hash.new { 0 }
presentdata = Hash.new { 0 }
data.each do |ts, attendance|
attendance[:absent].each {|name| if n = fname(name, people) then namedata[n] += 1 end }
attendance[:present].each {|name| if n = fname(name, people) then presentdata[n] += 1 end }
end
puts("% 30s % 5s % 5s % 9s" % ["NAME", "PRES", "ABS", "RECORD"])
namedata.sort_by do |x, y|
present = presentdata[x]
present / (y.to_f + present) * 100
end.reverse.each do |x, y|
present = presentdata[x]
puts("% 30s % 5d % 5d % 8.1f%%" % [x, presentdata[x], y, present / (y.to_f + present) * 100])
end