Class: Bors::Result::Statistics
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Bors::Result::Statistics
- Defined in:
- lib/bors/result/statistics.rb
Constant Summary collapse
- SPLIT_SETTINGS_LINE =
/\s=\s/
Instance Method Summary collapse
-
#initialize(data) ⇒ Statistics
constructor
A new instance of Statistics.
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(data) ⇒ Statistics
Returns a new instance of Statistics.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bors/result/statistics.rb', line 10 def initialize(data) lines = String.new found = false data.each_line do |line| if line.match('finished run') && found == false found = true next end if found == true lines += line end end lines.each_line do |line| line.match(SPLIT_SETTINGS_LINE) do |m| label, value = line.split(SPLIT_SETTINGS_LINE) self.send("#{label}=".gsub(' ', '_').downcase, value.gsub("\n", "")) end end end |
Instance Method Details
#to_h ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bors/result/statistics.rb', line 33 def to_h hash = Hash.new hash[:number_of_examples] = self.number_of_examples.to_i hash[:weighted_example_sum] = self.weighted_example_sum.to_f hash[:weighted_label_sum] = self.weighted_label_sum.to_f hash[:average_loss] = self.average_loss.to_f hash[:best_constant] = self.best_constant.to_f hash[:total_feature_number] = self.total_feature_number.to_i hash end |
#to_json ⇒ Object
44 45 46 |
# File 'lib/bors/result/statistics.rb', line 44 def to_json Oj.dump(self.to_h) end |