Class: Calculator
- Inherits:
-
Object
- Object
- Calculator
- Defined in:
- lib/git_heat/calculator.rb
Constant Summary collapse
- HALF_LIFE =
60.0*60*24
Instance Method Summary collapse
- #go(stats) ⇒ Object
-
#initialize(time) ⇒ Calculator
constructor
A new instance of Calculator.
Constructor Details
#initialize(time) ⇒ Calculator
4 5 6 |
# File 'lib/git_heat/calculator.rb', line 4 def initialize(time) @time = time end |
Instance Method Details
#go(stats) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/git_heat/calculator.rb', line 8 def go(stats) heat = {} stats.each do |commit| 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 |