Class: Toji::Progress::Graph::Bmd
- Inherits:
-
Object
- Object
- Toji::Progress::Graph::Bmd
- Defined in:
- lib/toji/progress/graph/bmd.rb
Instance Method Summary collapse
- #actual(moromi, name = :actual) ⇒ Object
-
#initialize ⇒ Bmd
constructor
A new instance of Bmd.
- #max_moromi_day ⇒ Object
- #plot ⇒ Object
- #plot_data ⇒ Object
Constructor Details
#initialize ⇒ Bmd
Returns a new instance of Bmd.
6 7 8 |
# File 'lib/toji/progress/graph/bmd.rb', line 6 def initialize @actuals = [] end |
Instance Method Details
#actual(moromi, name = :actual) ⇒ Object
10 11 12 13 |
# File 'lib/toji/progress/graph/bmd.rb', line 10 def actual(moromi, name=:actual) @actuals << [moromi, name] self end |
#max_moromi_day ⇒ Object
31 32 33 |
# File 'lib/toji/progress/graph/bmd.rb', line 31 def max_moromi_day @actuals.map(&:first).map(&:moromi_days).max end |
#plot ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/toji/progress/graph/bmd.rb', line 35 def plot _max_moromi_day = [max_moromi_day, 14].max Plotly::Plot.new( data: plot_data, layout: { xaxis: { title: "Moromi day", dtick: DAY, range: [1, _max_moromi_day].map{|d| d*DAY}, tickvals: _max_moromi_day.times.map{|d| d*DAY}, ticktext: _max_moromi_day.times.map(&:succ) }, yaxis: { title: "BMD", } } ) end |
#plot_data ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/toji/progress/graph/bmd.rb', line 15 def plot_data result = [] @actuals.each {|moromi, name| states = moromi.states.select{|s| s.moromi_day && s.bmd} xs = states.map(&:moromi_day).map{|d| d*DAY} ys = states.map(&:bmd) texts = states.map{|s| "%s<br />moromi day=%d, be=%s, bmd=%s" % [s.display_time, s.moromi_day, s.baume, s.bmd]} result << {x: xs, y: ys, text: texts, name: name} } result end |