Class: Ossert::Classifiers::Growing::Check::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ossert/classifiers/growing/check.rb

Direct Known Subclasses

Maintenance, Maturity, Popularity

Instance Method Summary collapse

Constructor Details

#initialize(config, project, classifiers, last_year_offset = 1) ⇒ Base

Returns a new instance of Base.



50
51
52
53
54
55
# File 'lib/ossert/classifiers/growing/check.rb', line 50

def initialize(config, project, classifiers, last_year_offset = 1)
  @config = config
  @project = project
  @classifiers = classifiers
  @last_year_offset = last_year_offset
end

Instance Method Details

#agility_last_year_dataObject



86
87
88
# File 'lib/ossert/classifiers/growing/check.rb', line 86

def agility_last_year_data
  @agility_last_year_data ||= @project.agility.quarters.last_year_as_hash(@last_year_offset)
end

#agility_total_dataObject



90
91
92
# File 'lib/ossert/classifiers/growing/check.rb', line 90

def agility_total_data
  @agility_total_data ||= @project.agility.total.metrics_to_hash
end

#checkObject



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ossert/classifiers/growing/check.rb', line 94

def check
  rates = GRADES.each_with_object({}) { |klass, res| res[klass] = 0.0.to_d }
  strategy.each do |(section_type, data_types)|
    Array(data_types).each do |data_type|
      rate(
        rates, metrics[section_type.to_s], send("#{data_type}_#{section_type}_data"),
        @classifiers.fetch("#{data_type}_#{section_type}".to_sym)
      )
    end
  end
  rates
end

#community_last_year_dataObject



78
79
80
# File 'lib/ossert/classifiers/growing/check.rb', line 78

def community_last_year_data
  @community_last_year_data ||= @project.community.quarters.last_year_as_hash(@last_year_offset)
end

#community_total_dataObject



82
83
84
# File 'lib/ossert/classifiers/growing/check.rb', line 82

def community_total_data
  @community_total_data ||= @project.community.total.metrics_to_hash
end

#gradeObject



107
108
109
110
111
112
113
114
115
# File 'lib/ossert/classifiers/growing/check.rb', line 107

def grade
  max = GRADES.count
  sum = -0.6
  check.sort.reverse.each do |(_, gain)|
    sum += gain
    sum += 0.1 if gain > trusted_probability
  end
  GRADES[(max - sum).to_i]
end

#grade_as_hashObject



117
118
119
120
121
122
123
124
125
# File 'lib/ossert/classifiers/growing/check.rb', line 117

def grade_as_hash
  max = GRADES.count
  sum = -0.6
  check.sort.reverse.each do |(_, gain)|
    sum += gain
    sum += 0.1 if gain > trusted_probability
  end
  { gain: sum, mark: GRADES[(max - sum).to_i] }
end

#max_gainObject



74
75
76
# File 'lib/ossert/classifiers/growing/check.rb', line 74

def max_gain
  @max_gain ||= (metrics['last_year'].values.sum + metrics['total'].values.sum).to_d
end

#metricsObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ossert/classifiers/growing/check.rb', line 61

def metrics
  return @metrics if defined? @metrics

  @metrics = @config['metrics'][metrics_type].map do |section, section_metrics|
    [
      section,
      section_metrics.map do |metric, weight|
        [metric, weight.to_d]
      end.to_h
    ]
  end.to_h
end

#metrics_typeObject



57
58
59
# File 'lib/ossert/classifiers/growing/check.rb', line 57

def metrics_type
  self.class.name.split('::').last.downcase
end