Class: Ossert::Classifiers::Growing

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

Defined Under Namespace

Classes: Check, Classifier, ClassifiersInitializer

Constant Summary collapse

GRADES =
%w(
  ClassA
  ClassB
  ClassC
  ClassD
  ClassE
).freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGrowing

Returns a new instance of Growing.



28
29
30
# File 'lib/ossert/classifiers/growing.rb', line 28

def initialize
  (self.class.all ||= []) << self
end

Class Attribute Details

.allObject

Returns the value of attribute all.



17
18
19
# File 'lib/ossert/classifiers/growing.rb', line 17

def all
  @all
end

Instance Attribute Details

#agility_last_year_classifierObject (readonly)

Returns the value of attribute agility_last_year_classifier.



33
34
35
# File 'lib/ossert/classifiers/growing.rb', line 33

def agility_last_year_classifier
  @agility_last_year_classifier
end

#agility_total_classifierObject (readonly)

Returns the value of attribute agility_total_classifier.



33
34
35
# File 'lib/ossert/classifiers/growing.rb', line 33

def agility_total_classifier
  @agility_total_classifier
end

#community_last_year_classifierObject (readonly)

Returns the value of attribute community_last_year_classifier.



33
34
35
# File 'lib/ossert/classifiers/growing.rb', line 33

def community_last_year_classifier
  @community_last_year_classifier
end

#community_total_classifierObject (readonly)

Returns the value of attribute community_total_classifier.



33
34
35
# File 'lib/ossert/classifiers/growing.rb', line 33

def community_total_classifier
  @community_total_classifier
end

#train_groupObject (readonly)

Returns the value of attribute train_group.



32
33
34
# File 'lib/ossert/classifiers/growing.rb', line 32

def train_group
  @train_group
end

Class Method Details

.configObject



23
24
25
# File 'lib/ossert/classifiers/growing.rb', line 23

def config
  @config ||= Settings['classifiers']['growth']
end

.currentObject



19
20
21
# File 'lib/ossert/classifiers/growing.rb', line 19

def current
  all.last
end

Instance Method Details

#check(*args) ⇒ Object



76
77
78
# File 'lib/ossert/classifiers/growing.rb', line 76

def check(*args)
  process_using(*args.unshift(:check))
end

#classifier_to_metrics_per_grade(classifier) ⇒ Object



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

def classifier_to_metrics_per_grade(classifier)
  classifier.each_with_object({}) do |(grade, metrics), res|
    metrics.each do |metric, value|
      (res[metric] ||= {})[grade] = value
    end
  end
end

#grade(*args) ⇒ Object



72
73
74
# File 'lib/ossert/classifiers/growing.rb', line 72

def grade(*args)
  process_using(*args.unshift(:grade))
end

#process_using(action, project, last_year_offset = 1) ⇒ Object



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

def process_using(action, project, last_year_offset = 1)
  Check.send(action,
             self.class.config,
             project,
             {
               agility_total: agility_total_classifier,
               community_total: community_total_classifier,
               agility_last_year: agility_last_year_classifier,
               community_last_year: community_last_year_classifier
             },
             last_year_offset)
end

#ready?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ossert/classifiers/growing.rb', line 36

def ready?
  agility_total_classifier.keys == GRADES && community_total_classifier.keys == GRADES
end

#reference_values_per_gradeObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/ossert/classifiers/growing.rb', line 40

def reference_values_per_grade
  {
    agility_total: classifier_to_metrics_per_grade(agility_total_classifier),
    agility_quarter: classifier_to_metrics_per_grade(agility_last_year_classifier),
    agility_year: classifier_to_metrics_per_grade(agility_last_year_classifier),
    community_total: classifier_to_metrics_per_grade(community_total_classifier),
    community_quarter: classifier_to_metrics_per_grade(community_last_year_classifier),
    community_year: classifier_to_metrics_per_grade(community_last_year_classifier)
  }
end

#trainObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/ossert/classifiers/growing.rb', line 80

def train
  classifiers_initializer = ClassifiersInitializer.load_or_create
  classifiers_initializer.run
  classifiers_initializer.classifiers.each do |name, classifier|
    instance_variable_set(
      "@#{name}_classifier",
      Classifier.new(classifier, self.class.config).train
    )
  end
end