Class: Toji::Progress::Graph::Ab
- Inherits:
-
Object
- Object
- Toji::Progress::Graph::Ab
- Defined in:
- lib/toji/progress/graph/ab.rb
Instance Method Summary collapse
- #actual(moromi, name = :actual) ⇒ Object
- #coef(coef) ⇒ Object
- #expect(alcohol, nihonshudo) ⇒ Object
- #expects(expects) ⇒ Object
-
#initialize ⇒ Ab
constructor
A new instance of Ab.
- #max_baume ⇒ Object
- #min_baume ⇒ Object
- #plot ⇒ Object
- #plot_data ⇒ Object
Constructor Details
#initialize ⇒ Ab
Returns a new instance of Ab.
5 6 7 8 9 |
# File 'lib/toji/progress/graph/ab.rb', line 5 def initialize @coef = 1.0 @actuals = [] @expects = [] end |
Instance Method Details
#actual(moromi, name = :actual) ⇒ Object
16 17 18 19 |
# File 'lib/toji/progress/graph/ab.rb', line 16 def actual(moromi, name=:actual) @actuals << [moromi, name] self end |
#coef(coef) ⇒ Object
11 12 13 14 |
# File 'lib/toji/progress/graph/ab.rb', line 11 def coef(coef) @coef = coef self end |
#expect(alcohol, nihonshudo) ⇒ Object
21 22 23 24 |
# File 'lib/toji/progress/graph/ab.rb', line 21 def expect(alcohol, nihonshudo) @expects << [alcohol.to_f, nihonshudo.to_f] self end |
#expects(expects) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/toji/progress/graph/ab.rb', line 26 def expects(expects) expects.each {|o| expect(o.alcohol, o.nihonshudo) } self end |
#max_baume ⇒ Object
64 65 66 67 68 |
# File 'lib/toji/progress/graph/ab.rb', line 64 def max_baume @actuals.map {|moromi, name| moromi.states.map(&:baume).compact.max }.compact.max || 0.0 end |
#min_baume ⇒ Object
58 59 60 61 62 |
# File 'lib/toji/progress/graph/ab.rb', line 58 def min_baume @actuals.map {|moromi, name| moromi.states.map(&:baume).compact.min }.compact.min || 0.0 end |
#plot ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/toji/progress/graph/ab.rb', line 70 def plot #_min_baume = [min_baume-1, 0].min _min_baume = 0 _max_baume = [max_baume+1, 10].max Plotly::Plot.new( data: plot_data, layout: { xaxis: { title: "Alcohol", dtick: 2, range: [0, 20], }, yaxis: { title: "Baume", dtick: 1, range: [_min_baume, _max_baume], } } ) end |
#plot_data ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/toji/progress/graph/ab.rb', line 33 def plot_data result = [] @actuals.each {|moromi, name| states = moromi.states.select{|s| s.alcohol && s.baume} xs = states.map(&:alcohol) ys = states.map(&:baume) texts = states.map{|s| "%s<br />alc=%s, be=%s" % [s.display_time, s.alcohol, s.baume]} result << {x: xs, y: ys, text: texts, name: name} } @expects.each {|alcohol, nihonshudo| ys = [0.0, 8.0] xs = ys.map{|b| alcohol - (b - nihonshudo * -0.1) * @coef} name = "%s%s %s" % [nihonshudo<0 ? "" : "+", nihonshudo, alcohol] result << {x: xs, y: ys, name: name} } result end |