Skip to content

Instantly share code, notes, and snippets.

@jabley
Last active December 11, 2015 04:48
Show Gist options
  • Save jabley/4547342 to your computer and use it in GitHub Desktop.
Save jabley/4547342 to your computer and use it in GitHub Desktop.
Initial exercise at the Developing Project Guidance through Code History Mining workshop
# This was a minor addition to the provided code_event.rb class
def dir_name
File.dirname(file_name)
end
require './reader_csv.rb'
require './analytics.rb'
require 'ap'
# ap mutated_methods
# Task discover opportunities for refactoring
# Find 95th percentile of method size?
events = read_events("../data/pry/methodevents.csv")
def method_size(e)
if e.status == :deleted
0
else
e.method_length
end
end
# large_methods = method_events(events).group_by(&:method_name)
# .map {|mn, es| [mn, ((es.map { |e| method_size(e)}).reduce(&:+) / es.size.to_f) ] }
# .select { |mn, line_count| line_count > 15 }
# .sort_by(&:second)
large_methods = method_events(events).group_by(&:method_name)
.map {|mn, es| [mn, (es.map { |e| method_size(e) }).select {|s| s > 15 } ]} # remove small methods or method deletions
.select { |mn, sizes| sizes.size > 3 } # look at the number of changes
ap large_methods
require './reader_csv.rb'
require './analytics.rb'
require 'ap'
events = read_events "../data/rspec/methodevents.csv"
# ap events
end_date = ((Time.parse("2010-01-01").to_date) - 90).to_time
start_date = ((end_date.to_date) - 90).to_time
#
relevant_method_events = method_events(events).select { |e| e.date > start_date && e.date < end_date }
deleted_methods = relevant_method_events.select { |e| e.status == :deleted }.map(&:method_name)
mutated_methods = relevant_method_events.select { |e| !deleted_methods.include?(e.method_name) }
.group_by(&:method_name)
.map {|mn, es| [mn, es.size]}
.select { |mn, change_count| change_count > 2 }
.sort_by {|mn, change_count| change_count }
ap mutated_methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment