Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created December 9, 2012 13:00
Show Gist options
  • Select an option

  • Save michaelfeathers/4244764 to your computer and use it in GitHub Desktop.

Select an option

Save michaelfeathers/4244764 to your computer and use it in GitHub Desktop.
# :: [[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