Module: Babygitter::FolderAnalysisMethods

Included in:
RepoAnalyzer::Branch
Defined in:
lib/babygitter/statistics/folder_analysis_methods.rb

Instance Method Summary collapse

Instance Method Details

#build_regexp(level) ⇒ Object

Build a regexp to scane the diff states and their folder string

  • build_regex(1) #=> /^.*?(?=/)/

  • build_regex(2) #=> /^.*?/.*?(?=/)/

  • build_regex(3) #=> /^.*?/.*?/.*?(?=/)/

TODO seperate this into it’s own class



98
99
100
101
102
103
104
105
106
107
# File 'lib/babygitter/statistics/folder_analysis_methods.rb', line 98

def build_regexp(level)
  regexp_string = "^.*?"
  i = 1
  while i < level
    regexp_string += "\/.*?" 
    i +=1
  end
  regexp_string += "(?=\/)"
  Regexp.new(regexp_string)
end

#create_hash_map(array) ⇒ Object

Creates a hash from an array of folder names. Also deletes or adds the “” hash key for collecting files in the top level folder



6
7
8
9
10
11
12
13
14
15
# File 'lib/babygitter/statistics/folder_analysis_methods.rb', line 6

def create_hash_map(array)
  hash = {}
  array.map {|folder| hash[folder] = 0}
  if Babygitter.use_whitelist
    hash[""] = 0 if Babygitter.marked_folders.find { |item| item =~ /^program_folder$|^program folder/i }
  else
    hash[""] = 0 unless Babygitter.marked_folders.find{ |item| item =~ /^program_folder$|^program folder/i }
  end
  hash
end

#create_stable_hash(folder_commits) ⇒ Object

Creates a stablized hash for diff state info to be plotted into.



59
60
61
62
63
# File 'lib/babygitter/statistics/folder_analysis_methods.rb', line 59

def create_stable_hash(folder_commits)
  stable_hash = {}
  folder_commits.first.each_key {|key| stable_hash[key] = [0] }
  return stable_hash
end

#find_key(folder_level, diff) ⇒ Object

Finds the key of the hash that the diff should be put into



82
83
84
85
86
87
88
89
90
91
# File 'lib/babygitter/statistics/folder_analysis_methods.rb', line 82

def find_key(folder_level, diff)
  i = folder_level
  key = nil
  while i > 0 && key == nil
    key = diff.filename.scan(build_regexp(i)).to_s if diff.filename.scan(build_regexp(i)).to_s != ""
    i -= 1
  end
  key = diff.filename.scan(/^.*?(?=\/)/).to_s unless key
  key
end

#folder_hash_for_level(folder_level) ⇒ Object

Creates the folder_array to turn into a hash for collection of data from diff stats

  • Gets the arrays of folders by levels and selects the ones applicable to that level

  • Flattens the array of arrays and intersects it or removes folders in the Babygitter.marked_folders variable

  • is then sent off to create_hash_map



38
39
40
41
42
43
44
# File 'lib/babygitter/statistics/folder_analysis_methods.rb', line 38

def folder_hash_for_level(folder_level)
  if Babygitter.use_whitelist 
    create_hash_map(@folder_array[0..(folder_level -1)].flatten & Babygitter.marked_folders)
  else
    create_hash_map(@folder_array[0..(folder_level -1)].flatten - Babygitter.marked_folders)
  end
end

#get_array_of_mapped_folder_namesObject

Recursively get the folder names inside a project Goes as many levels deep as specified



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/babygitter/statistics/folder_analysis_methods.rb', line 19

def get_array_of_mapped_folder_names
  array = []
  flattened_diffs = @mapped_diffs.flatten 
  i = 1 
  while i <= Babygitter.folder_levels.max
    folder_names = []
    for diff in flattened_diffs
     folder_names << diff.filename.scan(build_regexp(i)) 
    end
    i += 1
    array << folder_names.flatten.uniq          
  end
  array
end

#get_folder_commits_by_week_and_level(folder_level) ⇒ Object

Collects the diff states by folder Folders the diffs are mapped to depends on inputed folder_level



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/babygitter/statistics/folder_analysis_methods.rb', line 67

def get_folder_commits_by_week_and_level(folder_level)
  output = []
  diff_staff_by_week =  @mapped_diffs
    for array_of_diff_staff in diff_staff_by_week
      plot_hash =  folder_hash_for_level(folder_level).clone
      for diff in array_of_diff_staff
        key = find_key(folder_level, diff)
        plot_hash[key] = plot_hash[key] += (diff.additions - diff.deletions) unless plot_hash[key].nil?
      end
      output << plot_hash
    end
    output
end

#plot_folder_points(folder_level) ⇒ Object

Puts the data into a stablized hash to be used with gruff to plot out lines of codes commited to folder over weekly intervals



47
48
49
50
51
52
53
54
55
56
# File 'lib/babygitter/statistics/folder_analysis_methods.rb', line 47

def plot_folder_points(folder_level)
  folder_commits = get_folder_commits_by_week_and_level(folder_level)
  stable_hash = create_stable_hash(folder_commits)
  folder_commits.each do |hash|
    hash.each_key do |key|
      stable_hash[key] << (stable_hash[key].last + hash[key])
    end
  end
  return stable_hash
end