toji 2.1.1 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/example/calendar.ipynb +281 -21
  3. data/example/calendar_file.ipynb +37 -37
  4. data/example/example_core.rb +27 -53
  5. data/example/{kake_recipe.rb → kake_ingredient.rb} +0 -1
  6. data/example/{koji_recipe.rb → koji_ingredient.rb} +1 -2
  7. data/example/koji_making.ipynb +9 -9
  8. data/example/koji_making.yaml +1 -0
  9. data/example/koji_making_multi.ipynb +22 -57
  10. data/example/moromi.ipynb +17 -17
  11. data/example/moromi.rb +1 -1
  12. data/example/recipe.rb +17 -10
  13. data/example/shubo.ipynb +12 -12
  14. data/example/shubo.yaml +2 -1
  15. data/lib/toji/brew.rb +4 -2
  16. data/lib/toji/brew/base.rb +6 -26
  17. data/lib/toji/brew/builder.rb +49 -21
  18. data/lib/toji/brew/graph/bmd.rb +1 -1
  19. data/lib/toji/brew/graph/multi_progress.rb +0 -121
  20. data/lib/toji/brew/graph/progress.rb +16 -51
  21. data/lib/toji/brew/koji.rb +2 -1
  22. data/lib/toji/brew/moromi.rb +2 -1
  23. data/lib/toji/brew/shubo.rb +2 -1
  24. data/lib/toji/brew/state.rb +5 -1
  25. data/lib/toji/brew/{state_wrapper.rb → wrapped_state.rb} +6 -32
  26. data/lib/toji/calendar.rb +1 -1
  27. data/lib/toji/ingredient/kake.rb +2 -2
  28. data/lib/toji/ingredient/kake/actual.rb +6 -7
  29. data/lib/toji/ingredient/kake/base.rb +1 -1
  30. data/lib/toji/ingredient/kake/expected.rb +0 -1
  31. data/lib/toji/ingredient/koji.rb +2 -2
  32. data/lib/toji/ingredient/koji/actual.rb +8 -9
  33. data/lib/toji/ingredient/koji/base.rb +1 -1
  34. data/lib/toji/ingredient/koji/expected.rb +0 -1
  35. data/lib/toji/ingredient/rice/actual_steamable.rb +4 -4
  36. data/lib/toji/ingredient/rice/base.rb +0 -1
  37. data/lib/toji/ingredient/rice/expected_steamable.rb +1 -3
  38. data/lib/toji/ingredient/rice_rate.rb +2 -14
  39. data/lib/toji/product/event.rb +0 -10
  40. data/lib/toji/recipe.rb +5 -14
  41. data/lib/toji/recipe/step.rb +33 -33
  42. data/lib/toji/version.rb +1 -1
  43. metadata +5 -5
@@ -75,7 +75,7 @@ module Toji
75
75
  result << {x: xs, y: ys, text: text, name: "#{name}#{key}", line: {dash: @dash, shape: line_shape}, marker: {color: PLOT_COLORS[key]}}
76
76
  }
77
77
 
78
- if 0<@brew.states.length && 0<@brew.day_offset
78
+ if 0<@brew.wrapped_states.length && 0<@brew.day_offset
79
79
  result = result.map{|h|
80
80
  h[:x].unshift(0)
81
81
  h[:y].unshift(nil)
@@ -84,8 +84,8 @@ module Toji
84
84
  }
85
85
  end
86
86
 
87
- #if 0<@brew.states.length && @brew.states.last.time.strftime("%T")!="00:00:00"
88
- # t = @brew.states.last.elapsed_time_with_offset
87
+ #if 0<@brew.wrapped_states.length && @brew.wrapped_states.last.time.strftime("%T")!="00:00:00"
88
+ # t = @brew.wrapped_states.last.elapsed_time_with_offset
89
89
  # t -= (t % DAY) - DAY
90
90
  #
91
91
  # result = result.map{|h|
@@ -117,28 +117,7 @@ module Toji
117
117
  }
118
118
  end
119
119
 
120
- def state_group_by(group_by)
121
- group = {}
122
- prev = nil
123
-
124
- @brew.each {|state|
125
- val = state.send(group_by) || prev
126
- prev = val
127
-
128
- group[val] ||= []
129
- group[val] << state
130
- }
131
-
132
- group
133
- end
134
-
135
- def state_group_count(group_by)
136
- state_group_by(group_by).map{|val,states|
137
- [val, states.length]
138
- }.to_h
139
- end
140
-
141
- def table_data(keys=nil, group_by=nil, group_count=nil)
120
+ def table_data(keys=nil)
142
121
  if !keys
143
122
  keys = @brew.has_keys
144
123
  keys.delete(:elapsed_time)
@@ -151,33 +130,19 @@ module Toji
151
130
  keys &= @brew.has_keys
152
131
  end
153
132
 
154
- if group_by && group_count
155
- brew_hash = state_group_by(group_by)
156
- else
157
- group_count = state_group_count(:itself)
158
- brew_hash = state_group_by(:itself)
159
- end
160
-
161
133
  rows = []
162
- group_count.each {|group_value,num|
163
- states = brew_hash[group_value] || []
164
- num ||= states.length
165
-
166
- num.times {|i|
167
- state = states[i]
168
-
169
- rows << keys.map {|k|
170
- v = state&.send(k)
171
- if Array===v
172
- v.map(&:to_s).join(", ")
173
- elsif Float===v
174
- v.round(3)
175
- elsif v
176
- v
177
- else
178
- ""
179
- end
180
- }
134
+ @brew.each {|state|
135
+ rows << keys.map {|k|
136
+ v = state&.send(k)
137
+ if Array===v
138
+ v.map(&:to_s).join(", ")
139
+ elsif Float===v
140
+ v.round(3).to_s
141
+ elsif v
142
+ v.to_s
143
+ else
144
+ ""
145
+ end
181
146
  }
182
147
  }
183
148
 
@@ -1,6 +1,7 @@
1
1
  module Toji
2
2
  module Brew
3
- class Koji < Base
3
+ module Koji
4
+ include Base
4
5
 
5
6
  def progress(name: nil, dash: :solid, enable_annotations: true)
6
7
  Graph::Progress.new(self, name: name, dash: dash, enable_annotations: enable_annotations)
@@ -1,6 +1,7 @@
1
1
  module Toji
2
2
  module Brew
3
- class Moromi < Base
3
+ module Moromi
4
+ include Base
4
5
 
5
6
  attr_accessor :prefix_day_labels
6
7
 
@@ -1,6 +1,7 @@
1
1
  module Toji
2
2
  module Brew
3
- class Shubo < Base
3
+ module Shubo
4
+ include Base
4
5
 
5
6
  def progress(name: nil, dash: :solid, enable_annotations: true)
6
7
  Graph::Progress.new(self, name: name, dash: dash, enable_annotations: enable_annotations)
@@ -54,6 +54,10 @@ module Toji
54
54
  super(val&.to_time)
55
55
  end
56
56
 
57
+ def warmings
58
+ super || []
59
+ end
60
+
57
61
  def warmings=(val)
58
62
  super([val].flatten.compact)
59
63
  end
@@ -94,7 +98,7 @@ module Toji
94
98
  def self.create(val)
95
99
  if State===val
96
100
  val
97
- elsif StateWrapper==val
101
+ elsif WrappedState==val
98
102
  val.state
99
103
  #elsif Hash===val
100
104
  # #s = Class.new {
@@ -2,7 +2,7 @@ require 'forwardable'
2
2
 
3
3
  module Toji
4
4
  module Brew
5
- class StateWrapper
5
+ class WrappedState
6
6
  extend Forwardable
7
7
 
8
8
  attr_accessor :elapsed_time
@@ -21,8 +21,9 @@ module Toji
21
21
  def_delegators :@state, :warmings
22
22
  def_delegators :@state, :note
23
23
 
24
- def initialize(elapsed_time, state, brew)
25
- @elapsed_time = elapsed_time
24
+ def initialize(state, brew)
25
+ @elapsed_time = state.elapsed_time
26
+ @time = state.time
26
27
  @state = state
27
28
  @brew = brew
28
29
  end
@@ -69,8 +70,8 @@ module Toji
69
70
  def display_time(format="%m/%d %H:%M")
70
71
  if @time
71
72
  @time.strftime(format)
72
- elsif @brew.min_time
73
- time = @brew.min_time + @elapsed_time
73
+ elsif @brew.base_time
74
+ time = @brew.base_time + @elapsed_time
74
75
  time.strftime(format)
75
76
  else
76
77
  utc_offset = Time.at(0).utc_offset
@@ -103,33 +104,6 @@ module Toji
103
104
  target_alc - (_baume - target_nihonshudo * -0.1) * coef
104
105
  end
105
106
  end
106
-
107
- def to_h
108
- {
109
- elapsed_time: elapsed_time,
110
- time: time,
111
- mark: mark,
112
- temps: temps,
113
- preset_temp: preset_temp,
114
- room_temp: room_temp,
115
- room_psychrometry: room_psychrometry,
116
- acid: acid,
117
- amino_acid: amino_acid,
118
- alcohol: alcohol,
119
- warmings: warmings,
120
- note: note,
121
-
122
- day: day,
123
- day_label: day_label,
124
- elapsed_time_with_offset: elapsed_time_with_offset,
125
- baume: baume,
126
- nihonshudo: nihonshudo,
127
- display_baume: display_baume,
128
- display_time: display_time,
129
- moromi_day: moromi_day,
130
- bmd: bmd,
131
- }
132
- end
133
107
  end
134
108
  end
135
109
  end
@@ -10,7 +10,7 @@ module Toji
10
10
  end
11
11
 
12
12
  def <<(product)
13
- @products << product
13
+ @products += [product].flatten
14
14
  self
15
15
  end
16
16
  alias_method :add, :<<
@@ -9,8 +9,8 @@ module Toji
9
9
  Expected.new(raw, rice_rate: rice_rate)
10
10
  end
11
11
 
12
- def self.actual(raw, soaked, steaming_water, steamed, cooled)
13
- Actual.new(raw, soaked, steaming_water, steamed, cooled)
12
+ def self.actual(raw, soaked, steamed, cooled)
13
+ Actual.new(raw, soaked, steamed, cooled)
14
14
  end
15
15
  end
16
16
  end
@@ -5,17 +5,16 @@ module Toji
5
5
  include Base
6
6
  include Rice::ActualSteamable
7
7
 
8
- def initialize(raw, soaked, steaming_water, steamed, cooled)
9
- @raw = raw
10
- @soaked = soaked
11
- @steaming_water = steaming_water
12
- @steamed = steamed
13
- @cooled = cooled
8
+ def initialize(raw, soaked, steamed, cooled)
9
+ @raw = raw.to_f
10
+ @soaked = soaked.to_f
11
+ @steamed = steamed.to_f
12
+ @cooled = cooled.to_f
14
13
  end
15
14
 
16
15
  def *(other)
17
16
  if Integer===other || Float===other
18
- Actual.new(raw * other, soaked * other, steaming_water * other, steamed * other, cooled * other)
17
+ Actual.new(raw * other, soaked * other, steamed * other, cooled * other)
19
18
  else
20
19
  x, y = other.coerce(self)
21
20
  x * y
@@ -6,7 +6,7 @@ module Toji
6
6
 
7
7
  def +(other)
8
8
  if Base===other
9
- Actual.new(raw + other.raw, soaked + other.soaked, steaming_water + other.steaming_water, steamed + other.steamed, cooled + other.cooled)
9
+ Actual.new(raw + other.raw, soaked + other.soaked, steamed + other.steamed, cooled + other.cooled)
10
10
  else
11
11
  x, y = other.coerce(self)
12
12
  x + y
@@ -10,7 +10,6 @@ module Toji
10
10
 
11
11
  @rice_rate = rice_rate
12
12
  @soaked_rate = rice_rate.soaked_rate
13
- @before_steaming_rate = rice_rate.before_steaming_rate
14
13
  @steamed_rate = rice_rate.steamed_rate
15
14
  @cooled_rate = rice_rate.cooled_rate
16
15
  end
@@ -11,8 +11,8 @@ module Toji
11
11
  Expected.new(raw, rice_rate: rice_rate, koji_rate: koji_rate)
12
12
  end
13
13
 
14
- def self.actual(raw, soaked, steaming_water, steamed, cooled, tanekoji, dekoji)
15
- Actual.new(raw, soaked, steaming_water, steamed, cooled, tanekoji, dekoji)
14
+ def self.actual(raw, soaked, steamed, cooled, tanekoji, dekoji)
15
+ Actual.new(raw, soaked, steamed, cooled, tanekoji, dekoji)
16
16
  end
17
17
  end
18
18
  end
@@ -6,19 +6,18 @@ module Toji
6
6
  include Rice::ActualSteamable
7
7
  include ActualFermentable
8
8
 
9
- def initialize(raw, soaked, steaming_water, steamed, cooled, tanekoji, dekoji)
10
- @raw = raw
11
- @soaked = soaked
12
- @steaming_water = steaming_water
13
- @steamed = steamed
14
- @cooled = cooled
15
- @tanekoji = tanekoji
16
- @dekoji = dekoji
9
+ def initialize(raw, soaked, steamed, cooled, tanekoji, dekoji)
10
+ @raw = raw.to_f
11
+ @soaked = soaked.to_f
12
+ @steamed = steamed.to_f
13
+ @cooled = cooled.to_f
14
+ @tanekoji = tanekoji.to_f
15
+ @dekoji = dekoji.to_f
17
16
  end
18
17
 
19
18
  def *(other)
20
19
  if Integer===other || Float===other
21
- Actual.new(raw * other, soaked * other, steaming_water * other, steamed * other, cooled * other, tanekoji * other, dekoji * other)
20
+ Actual.new(raw * other, soaked * other, steamed * other, cooled * other, tanekoji * other, dekoji * other)
22
21
  else
23
22
  x, y = other.coerce(self)
24
23
  x * y
@@ -23,7 +23,7 @@ module Toji
23
23
 
24
24
  def +(other)
25
25
  if Base===other
26
- Actual.new(raw + other.raw, soaked + other.soaked, steaming_water + other.steaming_water, steamed + other.steamed, cooled + other.cooled, tanekoji + other.tanekoji, dekoji + other.dekoji)
26
+ Actual.new(raw + other.raw, soaked + other.soaked, steamed + other.steamed, cooled + other.cooled, tanekoji + other.tanekoji, dekoji + other.dekoji)
27
27
  else
28
28
  x, y = other.coerce(self)
29
29
  x + y
@@ -11,7 +11,6 @@ module Toji
11
11
 
12
12
  @rice_rate = rice_rate
13
13
  @soaked_rate = rice_rate.soaked_rate
14
- @before_steaming_rate = rice_rate.before_steaming_rate
15
14
  @steamed_rate = rice_rate.steamed_rate
16
15
  @cooled_rate = rice_rate.cooled_rate
17
16
 
@@ -10,14 +10,14 @@ module Toji
10
10
  soaked - raw
11
11
  end
12
12
 
13
- def before_steaming_rate
14
- # TODO
15
- end
16
-
17
13
  def steamed_rate
18
14
  (steamed - raw) / raw
19
15
  end
20
16
 
17
+ def steaming_water
18
+ steamed - raw
19
+ end
20
+
21
21
  def cooled_rate
22
22
  (cooled - raw) / raw
23
23
  end
@@ -21,7 +21,6 @@ module Toji
21
21
  # 蒸米吸水率は麹米及び酒母米で41〜43%、掛米は39〜40%で、吟醸造りの場合は数%低い
22
22
  #
23
23
  # 出典: 酒造教本 P48
24
- attr_reader :before_steaming_rate
25
24
  attr_reader :steamed_rate
26
25
  attr_reader :steaming_water
27
26
  attr_reader :steamed
@@ -11,9 +11,7 @@ module Toji
11
11
  end
12
12
 
13
13
  def steaming_water
14
- if before_steaming_rate
15
- raw * (before_steaming_rate - soaked_rate)
16
- end
14
+ raw * steamed_rate
17
15
  end
18
16
 
19
17
  def steamed
@@ -4,32 +4,20 @@ module Toji
4
4
  # 浸漬米吸水率
5
5
  attr_reader :soaked_rate
6
6
 
7
- # 蒸し前浸漬米吸水率
8
- # 炊飯の場合は水を追加
9
- # 蒸しの場合は一晩経って蒸発した分を削減
10
- attr_reader :before_steaming_rate
11
-
12
7
  # 蒸米吸水率
13
8
  attr_reader :steamed_rate
14
9
 
15
10
  # 放冷後蒸米吸水率
16
11
  attr_reader :cooled_rate
17
12
 
18
- def initialize(soaked_rate, before_steaming_rate, steamed_rate, cooled_rate)
13
+ def initialize(soaked_rate, steamed_rate, cooled_rate)
19
14
  @soaked_rate = soaked_rate
20
- @before_steaming_rate = before_steaming_rate
21
15
  @steamed_rate = steamed_rate
22
16
  @cooled_rate = cooled_rate
23
17
  end
24
18
 
25
- def before_steaming_rate
26
- @before_steaming_rate || begin
27
- @soaked_rate - 0.04
28
- end
29
- end
30
-
31
19
 
32
- DEFAULT = new(0.33, nil, 0.41, 0.33)
20
+ DEFAULT = new(0.33, 0.41, 0.33)
33
21
  end
34
22
  end
35
23
  end
@@ -39,16 +39,6 @@ module Toji
39
39
  def weight
40
40
  @product.recipe.steps[@index].send(@type)
41
41
  end
42
-
43
- def to_h
44
- {
45
- date: date,
46
- type: type,
47
- index: index,
48
- group_index: group_index,
49
- weight: weight,
50
- }
51
- end
52
42
  end
53
43
  end
54
44
  end
@@ -15,9 +15,9 @@ module Toji
15
15
  }
16
16
  end
17
17
 
18
- def round(ndigit=0, half: :up)
18
+ def round(ndigit=0, mini_ndigit=nil, half: :up)
19
19
  new_steps = steps.map {|step|
20
- step.round(ndigit, half: half)
20
+ step.round(ndigit, mini_ndigit, half: half)
21
21
  }
22
22
 
23
23
  self.class.new.tap {|o|
@@ -25,15 +25,6 @@ module Toji
25
25
  }
26
26
  end
27
27
 
28
- # 内容量の累計
29
- def cumulative_weight_totals
30
- weight_total = steps.map(&:weight_total)
31
-
32
- weight_total.map.with_index {|x,i|
33
- weight_total[0..i].inject(:+)
34
- }
35
- end
36
-
37
28
  # 総米の累計
38
29
  def cumulative_rice_totals
39
30
  rice_total = steps.map(&:rice_total)
@@ -78,15 +69,15 @@ module Toji
78
69
  end
79
70
 
80
71
  def table_data
81
- headers = [""] + @steps.map(&:name) + [:total]
72
+ headers = [""] + steps.map(&:name) + [:total]
82
73
  keys = [:rice_total, :kake, :koji, :alcohol, :water, :lactic_acid]
83
74
 
84
75
  cells = [keys]
85
- cells += @steps.map {|step|
76
+ cells += steps.map {|step|
86
77
  [step.rice_total, step.kake, step.koji, step.alcohol, step.water, step.lactic_acid]
87
78
  }
88
79
  cells << keys.map {|key|
89
- @steps.map(&key).compact.sum
80
+ steps.map(&key).compact.sum
90
81
  }
91
82
 
92
83
  cells = cells.map {|cell|