Class: Ossert::Classifiers::Growing::ClassifiersInitializer
- Inherits:
-
Object
- Object
- Ossert::Classifiers::Growing::ClassifiersInitializer
- Defined in:
- lib/ossert/classifiers/growing.rb
Constant Summary collapse
- CLASSIFIERS_METRICS =
{ agility_total: ->(project) { project.agility.total.metrics_to_hash }, agility_last_year: ->(project) { project.agility.quarters.last_year_as_hash }, community_total: ->(project) { project.community.total.metrics_to_hash }, community_last_year: ->(project) { project.community.quarters.last_year_as_hash } }.freeze
Instance Attribute Summary collapse
-
#classifiers ⇒ Object
readonly
Returns the value of attribute classifiers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(grouped_projects = nil) ⇒ ClassifiersInitializer
constructor
A new instance of ClassifiersInitializer.
- #load ⇒ Object
- #merge_metrics(storage, metrics) ⇒ Object
- #new_classifiers ⇒ Object
- #run ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(grouped_projects = nil) ⇒ ClassifiersInitializer
Returns a new instance of ClassifiersInitializer.
109 110 111 112 |
# File 'lib/ossert/classifiers/growing.rb', line 109 def initialize(grouped_projects = nil) @projects = grouped_projects @classifiers = [] end |
Instance Attribute Details
#classifiers ⇒ Object (readonly)
Returns the value of attribute classifiers.
107 108 109 |
# File 'lib/ossert/classifiers/growing.rb', line 107 def classifiers @classifiers end |
Class Method Details
.load_or_create ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/ossert/classifiers/growing.rb', line 99 def self.load_or_create if ::Classifier.actual? new.load else new(Project.projects_by_reference) end end |
Instance Method Details
#load ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/ossert/classifiers/growing.rb', line 114 def load @classifiers = {} CLASSIFIERS_METRICS.keys.each do |section| @classifiers[section] = JSON.parse(::Classifier[section.to_s].reference_values) end self end |
#merge_metrics(storage, metrics) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/ossert/classifiers/growing.rb', line 122 def merge_metrics(storage, metrics) metrics.each do |metric, value| storage.store( metric.to_s, storage[metric.to_s].to_a << value.to_f ) end storage end |
#new_classifiers ⇒ Object
143 144 145 |
# File 'lib/ossert/classifiers/growing.rb', line 143 def new_classifiers CLASSIFIERS_METRICS.keys.map { |type| [type, {}] }.to_h end |
#run ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ossert/classifiers/growing.rb', line 147 def run return if @classifiers.present? @classifiers = GRADES.each_with_object(new_classifiers) do |grade, classifiers| @projects[grade].each do |project| CLASSIFIERS_METRICS.each do |type, metrics| classifiers[type][grade] = merge_metrics(classifiers[type][grade].to_h, metrics.call(project)) end end end save end |
#save ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ossert/classifiers/growing.rb', line 132 def save ::Classifier.dataset.delete @classifiers.each do |section, reference_values| ::Classifier.create( section: section.to_s, reference_values: JSON.generate(reference_values) ) end end |