Created
December 9, 2012 13:00
-
-
Save michaelfeathers/4244764 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # :: [[a,b]] -> (a..a) -> b -> [[a,b]]] | |
| def spread mappings, range, default_value = 0 | |
| occupied = Hash[mappings] | |
| range.map { |index| [index, occupied[index] || default_value] } | |
| end | |
| # :: String -> [event] -> [[date, Int]] | |
| def class_commit_monthly_timeline class_name, events | |
| class_month_dates = events.select {|e| e.class_name == class_name }.map(&:date).map(&:month_start) | |
| spread(class_month_dates.freq, month_range(class_month_dates.min, class_month_dates.max)) | |
| end | |
| # :: [event] -> [Int] | |
| def aggregate_class_lifetimes events | |
| lifetimes = method_events(events).group_by(&:class_name).map {|cn,es| class_commit_monthly_timeline(cn,es).map(&:second) } | |
| lifetimes.reduce {|aggregate,es| aggregate.zip(es).map { |x,y| [x || 0, y || 0] }.map {|x,y| x + y }} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment