Class: EvocCLI::Analyze

Inherits:
Thor
  • Object
show all
Defined in:
lib/evoc_cli/analyze.rb

Instance Method Summary collapse

Instance Method Details

#aggregator_rangeObject



35
36
37
38
# File 'lib/evoc_cli/analyze.rb', line 35

def aggregator_range
  a = Evoc::Analyze.new(options)
  a.aggregator_range
end

#allObject



54
55
56
# File 'lib/evoc_cli/analyze.rb', line 54

def all
  Evoc::Analyze.new(options).all
end

#avg_changes_per_fileObject



59
60
61
62
63
# File 'lib/evoc_cli/analyze.rb', line 59

def avg_changes_per_file
  a = Evoc::Analyze.new(options)
  $stdout.puts __method__
  $stdout.puts a.average_changes_per_file
end

#avg_commit_sizeObject



111
112
113
114
115
# File 'lib/evoc_cli/analyze.rb', line 111

def avg_commit_size
  a = Evoc::Analyze.new(options)
  $stdout.puts __method__
  $stdout.puts a.average_commit_size
end

#avg_time_between_commitsObject



81
82
83
84
85
86
# File 'lib/evoc_cli/analyze.rb', line 81

def avg_time_between_commits
  a = Evoc::Analyze.new(options)
  unit = 'hours'
  $stdout.puts "#{__method__}_#{unit}"
  $stdout.puts a.average_time_between_commits(unit: unit)
end

#commit_sizeObject



105
106
107
108
# File 'lib/evoc_cli/analyze.rb', line 105

def commit_size
  a = Evoc::Analyze.new(options)
  a.commit_size
end

#commitsObject



16
17
18
19
# File 'lib/evoc_cli/analyze.rb', line 16

def commits
  a = Evoc::Analyze.new(options)
  a.commits
end

#create_dictObject



118
119
120
121
# File 'lib/evoc_cli/analyze.rb', line 118

def create_dict
  a = Evoc::Analyze.new(options)
  a.create_dict
end

#evolutionObject



10
11
12
13
# File 'lib/evoc_cli/analyze.rb', line 10

def evolution
  a = Evoc::Analyze.new(options)
  a.evolution
end

#file_frequencyObject



97
98
99
100
# File 'lib/evoc_cli/analyze.rb', line 97

def file_frequency
  a = Evoc::Analyze.new(options)
  a.file_frequency
end

#measure_rangesObject



29
30
31
32
# File 'lib/evoc_cli/analyze.rb', line 29

def measure_ranges
  a = Evoc::Analyze.new(options)
  a.measure_ranges
end

#measure_valuesObject



23
24
25
26
# File 'lib/evoc_cli/analyze.rb', line 23

def measure_values
  a = Evoc::Analyze.new(options)
  a.measure_values
end

#num_commitsObject



66
67
68
69
70
# File 'lib/evoc_cli/analyze.rb', line 66

def num_commits
  a = Evoc::Analyze.new(options)
  $stdout.puts __method__
  $stdout.puts a.num_commits
end

#num_unique_filesObject



89
90
91
92
93
# File 'lib/evoc_cli/analyze.rb', line 89

def num_unique_files
  a = Evoc::Analyze.new(options)
  $stdout.puts __method__
  $stdout.puts a.num_unique_files
end

#recommendation_metaObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/evoc_cli/analyze.rb', line 124

def recommendation_meta

  int i = 1
  ARGF.each_line do |line|

    rec = JSON.parse(line)

    tx_id = rec["tx_id"]
    algorithm = rec["algorithm"]
    ap = rec["average_precision1000"]
    rank = nil
    if !ap.nil?
      if ap > 0
        rat = ap.rationalize
        # the rank is only valid if we obtained a 1 in the numerator
        if rat.numerator == 1
          rank = rat.denominator
        end
      end
    else
      $stderr.puts "AP was nil for #{tx_id}"
    end
    applicable = !rec["rules"].empty?
    positive_recommendation = !rank.nil?
    # find the confidence of the correct item
    expected_outcome = nil
    confidence_correct = nil
    rank_one = nil
    confidence_incorrect = nil
    discernibility = nil
    ordered_rec = unique_strongest_consequents(rec["rules"])
    if ordered_rec.size > 0
      if positive_recommendation
        expected_outcome = ordered_rec[rank-1][0]
        confidence_correct = ordered_rec[rank-1][1]
      else
        rank_one = ordered_rec[0][0]
        confidence_incorrect = ordered_rec[0][1]
      end
      discernibility = (ordered_rec.group_by{|(_,confidence)| confidence}.size).to_f/ordered_rec.size
    end


    # build output hash
    hash = {tx_id: tx_id,
      algorithm: algorithm,
      ap: ap,
      rank: rank,
      applicable: applicable,
      positive_recommendation: positive_recommendation,
      expected_outcome: expected_outcome,
      confidence_correct: confidence_correct,
      rank_one: rank_one,
      confidence_incorrect: confidence_incorrect,
      discernibility: discernibility}
    begin
      puts hash.to_json
    rescue JSON::GeneratorError => e
      $stderr.puts "Failed to convert hash to JSON, error was #{e}\n the hash was \n#{hash}\n\n"
      next
    end
  $stderr.print "#{i} lines processed"
  i += 1
  end
end

#time_spanObject



73
74
75
76
77
78
# File 'lib/evoc_cli/analyze.rb', line 73

def time_span
  a = Evoc::Analyze.new(options)
  unit = 'years'
  $stdout.puts "#{__method__}_#{unit}"
  $stdout.puts a.time_span(unit: unit)
end

#uniquenessObject



48
49
50
51
# File 'lib/evoc_cli/analyze.rb', line 48

def uniqueness
  a = Evoc::Analyze.new(options)
  $stdout.puts a.uniqueness
end