Class: Toji::Progress::Graph::Bmd

Inherits:
Object
  • Object
show all
Defined in:
lib/toji/progress/graph/bmd.rb

Instance Method Summary collapse

Constructor Details

#initializeBmd

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_dayObject



31
32
33
# File 'lib/toji/progress/graph/bmd.rb', line 31

def max_moromi_day
  @actuals.map(&:first).map(&:moromi_days).max
end

#plotObject



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_dataObject



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