class Calculator HALF_LIFE = 60.0*60*24 def initialize(time) @time = time end def go(stats) heat = {} stats.each do |commit| next if commit[:time] > @time time_delta = @time - commit[:time] unless commit[:affected_files] next end commit[:affected_files].each do |file| impact = (file[:insertions] + file[:deletions]).to_f heat[file[:file]] ||= 0 heat[file[:file]] += impact*(0.5**(time_delta/HALF_LIFE)) end end heat.sort_by {|_key, value| value}.reverse end end