toji 2.9.0 → 2.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/example/calendar.ipynb +42 -51
  3. data/example/calendar.yaml +6 -6
  4. data/example/calendar_file.ipynb +36 -36
  5. data/example/example_core.rb +877 -205
  6. data/example/kake_ingredient.rb +21 -15
  7. data/example/koji_ingredient.rb +31 -21
  8. data/example/{koji_making.ipynb → koji_progress.ipynb} +14 -14
  9. data/example/{koji_making.rb → koji_progress.rb} +3 -2
  10. data/example/{koji_making.yaml → koji_progress.yaml} +8 -9
  11. data/example/{koji_making_multi.ipynb → koji_progress_multi.ipynb} +21 -22
  12. data/example/{moromi.ipynb → moromi_progress.ipynb} +22 -22
  13. data/example/{moromi.rb → moromi_progress.rb} +3 -2
  14. data/example/{moromi.yaml → moromi_progress.yaml} +0 -0
  15. data/example/moto_progress.ipynb +121 -0
  16. data/example/{moto.rb → moto_progress.rb} +3 -2
  17. data/example/{moto.yaml → moto_progress.yaml} +14 -15
  18. data/example/recipe.rb +44 -32
  19. data/lib/toji.rb +4 -1
  20. data/lib/toji/calendar.rb +18 -18
  21. data/lib/toji/calendar/date_column.rb +7 -22
  22. data/lib/toji/calendar/date_row.rb +6 -6
  23. data/lib/toji/ingredient.rb +6 -2
  24. data/lib/toji/ingredient/alcohol.rb +14 -0
  25. data/lib/toji/ingredient/base.rb +11 -0
  26. data/lib/toji/ingredient/kake.rb +3 -9
  27. data/lib/toji/ingredient/koji.rb +19 -10
  28. data/lib/toji/ingredient/lactic_acid.rb +14 -0
  29. data/lib/toji/ingredient/rice.rb +50 -4
  30. data/lib/toji/ingredient/tanekoji.rb +29 -0
  31. data/lib/toji/ingredient/water.rb +18 -0
  32. data/lib/toji/ingredient/yeast.rb +20 -0
  33. data/lib/toji/processing.rb +18 -0
  34. data/lib/toji/processing/base.rb +7 -0
  35. data/lib/toji/processing/cooled_rice.rb +22 -0
  36. data/lib/toji/processing/cooled_rice_element.rb +8 -0
  37. data/lib/toji/processing/dekoji.rb +22 -0
  38. data/lib/toji/processing/dekoji_element.rb +8 -0
  39. data/lib/toji/processing/kake_processing.rb +7 -0
  40. data/lib/toji/processing/koji_processing.rb +10 -0
  41. data/lib/toji/processing/rice_processing.rb +19 -0
  42. data/lib/toji/processing/soaked_rice.rb +49 -0
  43. data/lib/toji/processing/soaked_rice_element.rb +18 -0
  44. data/lib/toji/processing/steamed_rice.rb +22 -0
  45. data/lib/toji/processing/steamed_rice_element.rb +8 -0
  46. data/lib/toji/product.rb +11 -83
  47. data/lib/toji/product/schedule_factory.rb +74 -0
  48. data/lib/toji/progress.rb +23 -0
  49. data/lib/toji/progress/base_progress.rb +37 -0
  50. data/lib/toji/progress/base_state.rb +39 -0
  51. data/lib/toji/progress/builder.rb +53 -0
  52. data/lib/toji/progress/graph.rb +11 -0
  53. data/lib/toji/{brew → progress}/graph/ab.rb +4 -4
  54. data/lib/toji/{brew → progress}/graph/bmd.rb +2 -2
  55. data/lib/toji/{brew/graph/multi_progress.rb → progress/graph/multi_progress_note.rb} +11 -11
  56. data/lib/toji/{brew/graph/progress.rb → progress/graph/progress_note.rb} +20 -18
  57. data/lib/toji/progress/koji_progress.rb +15 -0
  58. data/lib/toji/progress/koji_state.rb +23 -0
  59. data/lib/toji/{brew/moromi.rb → progress/moromi_progress.rb} +9 -5
  60. data/lib/toji/progress/moromi_state.rb +77 -0
  61. data/lib/toji/progress/moto_progress.rb +15 -0
  62. data/lib/toji/progress/moto_state.rb +31 -0
  63. data/lib/toji/progress/progress.rb +15 -0
  64. data/lib/toji/progress/state.rb +9 -0
  65. data/lib/toji/progress/state/baume_to_nihonshudo.rb +21 -0
  66. data/lib/toji/progress/state/nihonshudo_to_baume.rb +21 -0
  67. data/lib/toji/recipe.rb +52 -39
  68. data/lib/toji/recipe/ab_expect.rb +2 -2
  69. data/lib/toji/recipe/action.rb +8 -0
  70. data/lib/toji/recipe/step.rb +97 -71
  71. data/lib/toji/schedule.rb +5 -0
  72. data/lib/toji/schedule/action_schedule.rb +9 -0
  73. data/lib/toji/schedule/base.rb +9 -0
  74. data/lib/toji/schedule/kake_schedule.rb +11 -0
  75. data/lib/toji/schedule/koji_schedule.rb +11 -0
  76. data/lib/toji/schedule/rice_schedule.rb +16 -0
  77. data/lib/toji/utils.rb +43 -0
  78. data/lib/toji/version.rb +1 -1
  79. metadata +60 -41
  80. data/lib/toji/brew.rb +0 -18
  81. data/lib/toji/brew/base.rb +0 -55
  82. data/lib/toji/brew/builder.rb +0 -98
  83. data/lib/toji/brew/graph.rb +0 -11
  84. data/lib/toji/brew/koji.rb +0 -11
  85. data/lib/toji/brew/moto.rb +0 -11
  86. data/lib/toji/brew/state.rb +0 -122
  87. data/lib/toji/brew/wrapped_state.rb +0 -109
  88. data/lib/toji/ingredient/kake/actual.rb +0 -26
  89. data/lib/toji/ingredient/kake/base.rb +0 -18
  90. data/lib/toji/ingredient/kake/expected.rb +0 -40
  91. data/lib/toji/ingredient/koji/actual.rb +0 -29
  92. data/lib/toji/ingredient/koji/actual_fermentable.rb +0 -15
  93. data/lib/toji/ingredient/koji/base.rb +0 -35
  94. data/lib/toji/ingredient/koji/expected.rb +0 -45
  95. data/lib/toji/ingredient/koji/expected_fermentable.rb +0 -15
  96. data/lib/toji/ingredient/koji_rate.rb +0 -16
  97. data/lib/toji/ingredient/rice/actual_steamable.rb +0 -27
  98. data/lib/toji/ingredient/rice/base.rb +0 -40
  99. data/lib/toji/ingredient/rice/expected_steamable.rb +0 -27
  100. data/lib/toji/ingredient/rice_rate.rb +0 -23
  101. data/lib/toji/product/event.rb +0 -13
  102. data/lib/toji/product/rice_event.rb +0 -30
  103. data/lib/toji/product/rice_event_group.rb +0 -21
@@ -0,0 +1,21 @@
1
+ module Toji
2
+ module Progress
3
+ module State
4
+ module NihonshudoToBaume
5
+ def baume
6
+ if self.nihonshudo
7
+ self.nihonshudo / -10.0
8
+ end
9
+ end
10
+
11
+ def baume=(val)
12
+ if val
13
+ self.nihonshudo = val.to_f * -10
14
+ else
15
+ self.nihonshudo = nil
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,44 +1,45 @@
1
1
  require 'toji/recipe/step'
2
+ require 'toji/recipe/action'
2
3
  require 'toji/recipe/ab_expect'
3
4
 
4
5
  module Toji
5
6
  module Recipe
6
- attr_accessor :steps
7
- attr_accessor :has_moto
8
- attr_accessor :has_moromi
9
- attr_accessor :ab_coef
10
- attr_accessor :ab_expects
11
- attr_accessor :squeeze_interval_days
12
-
13
- def scale(rice_total)
14
- rate = rice_total / steps.map(&:rice_total).sum
15
- new_steps = steps.map {|step|
16
- step * rate
7
+ attr_reader :steps
8
+ attr_reader :actions
9
+ attr_reader :ab_coef
10
+ attr_reader :ab_expects
11
+
12
+ def scale_rice_total(rice_total)
13
+ ratio = rice_total / steps.map(&:rice_total).sum
14
+ scale(ratio)
15
+ end
16
+
17
+ def scale!(ratio)
18
+ steps.each {|step|
19
+ step.scale!(ratio)
17
20
  }
21
+ self
22
+ end
23
+
24
+ def scale(ratio)
25
+ Utils.check_dup(self)
26
+
27
+ dst = self.dup
28
+ dst.scale!(ratio)
29
+ end
18
30
 
19
- self.class.new.tap {|o|
20
- o.steps = new_steps
21
- o.has_moto = has_moto
22
- o.has_moromi = has_moromi
23
- o.ab_coef = ab_coef
24
- o.ab_expects = ab_expects.deep_dup
25
- o.squeeze_interval_days = squeeze_interval_days
31
+ def round!(ndigit=0, mini_ndigit=nil, half: :up)
32
+ steps.each {|step|
33
+ step.round!(ndigit, mini_ndigit, half: half)
26
34
  }
35
+ self
27
36
  end
28
37
 
29
38
  def round(ndigit=0, mini_ndigit=nil, half: :up)
30
- new_steps = steps.map {|step|
31
- step.round(ndigit, mini_ndigit, half: half)
32
- }
39
+ Utils.check_dup(self)
33
40
 
34
- self.class.new.tap {|o|
35
- o.steps = new_steps
36
- o.has_moto = has_moto
37
- o.has_moromi = has_moromi
38
- o.ab_coef = ab_coef
39
- o.ab_expects = ab_expects.deep_dup
40
- o.squeeze_interval_days = squeeze_interval_days
41
- }
41
+ dst = self.dup
42
+ dst.round!(ndigit, mini_ndigit, half: half)
42
43
  end
43
44
 
44
45
  # 総米の累計
@@ -51,7 +52,7 @@ module Toji
51
52
  end
52
53
 
53
54
  # 酒母歩合の累計
54
- def cumulative_moto_rates
55
+ def cumulative_moto_ratios
55
56
  rice_total = steps.map(&:rice_total)
56
57
  moto = rice_total.first
57
58
 
@@ -66,8 +67,8 @@ module Toji
66
67
  # 汲水歩合が大きい高温糖化酒母では6%程度である
67
68
  #
68
69
  # 出典: 酒造教本 P96
69
- def moto_rate
70
- cumulative_moto_rates.last || 0.0
70
+ def moto_ratio
71
+ cumulative_moto_ratios.last || 0.0
71
72
  end
72
73
 
73
74
  # 白米比率
@@ -78,22 +79,34 @@ module Toji
78
79
  # 湧き抑え型 1 2 4 7 長期醪、甘口、おだやかな酒質
79
80
  #
80
81
  # 出典: 酒造教本 P95
81
- def rice_rates
82
+ def rice_ratios
82
83
  steps.map {|step|
83
84
  step.rice_total / steps.first.rice_total
84
85
  }
85
86
  end
86
87
 
87
88
  def table_data
88
- headers = [""] + steps.map(&:name) + [:total]
89
- keys = [:rice_total, :kake, :koji, :alcohol, :water, :lactic_acid]
89
+ headers = [""] + steps.map.with_index{|s,i| :"Step#{i}"} + [:total]
90
+ keys = [["RiceTotal", :rice_total], ["Kake", :kakes], ["Koji", :kojis], ["Alcohol", :alcohols], ["Water", :waters], ["LacticAcid", :lactic_acids]]
90
91
 
91
- cells = [keys]
92
+ cells = [keys.map(&:first)]
92
93
  cells += steps.map {|step|
93
- [step.rice_total, step.kake, step.koji, step.alcohol, step.water, step.lactic_acid]
94
+ keys.map(&:last).map {|key|
95
+ vals = step.send(key)
96
+ if Numeric===vals
97
+ vals
98
+ else
99
+ vals.compact.map(&:weight).sum
100
+ end
101
+ }
94
102
  }
95
- cells << keys.map {|key|
96
- steps.map(&key).compact.sum
103
+ cells << keys.map(&:last).map {|key|
104
+ vals = steps.map(&key)
105
+ if Numeric===vals[0]
106
+ vals.sum
107
+ else
108
+ vals.flatten.compact.map(&:weight).sum
109
+ end
97
110
  }
98
111
 
99
112
  cells = cells.map {|cell|
@@ -1,8 +1,8 @@
1
1
  module Toji
2
2
  module Recipe
3
3
  module AbExpect
4
- attr_accessor :alcohol
5
- attr_accessor :nihonshudo
4
+ attr_reader :alcohol
5
+ attr_reader :nihonshudo
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,8 @@
1
+ module Toji
2
+ module Recipe
3
+ module Action
4
+ attr_reader :type
5
+ attr_reader :interval_days
6
+ end
7
+ end
8
+ end
@@ -1,25 +1,31 @@
1
1
  module Toji
2
2
  module Recipe
3
3
  module Step
4
- attr_accessor :koji
5
- attr_accessor :koji_soaked_rate
6
- attr_accessor :koji_steamed_rate
7
- attr_accessor :koji_dekoji_rate
8
- attr_accessor :koji_interval_days
9
-
10
- attr_accessor :kake
11
- attr_accessor :kake_soaked_rate
12
- attr_accessor :kake_steamed_rate
13
- attr_accessor :kake_interval_days
14
-
15
- attr_accessor :water
16
- attr_accessor :lactic_acid
17
- attr_accessor :alcohol
18
- attr_accessor :yeast
4
+ attr_accessor :kojis
5
+ attr_accessor :kakes
6
+ attr_accessor :waters
7
+ attr_accessor :lactic_acids
8
+ attr_accessor :alcohols
9
+ attr_accessor :yeasts
10
+
11
+ # 麹米
12
+ def koji_total
13
+ (kojis || []).map(&:weight).map(&:to_f).sum.to_f
14
+ end
15
+
16
+ # 掛米
17
+ def kake_total
18
+ (kakes || []).map(&:weight).map(&:to_f).sum.to_f
19
+ end
19
20
 
20
21
  # 総米
21
22
  def rice_total
22
- kake.to_f + koji.to_f
23
+ koji_total + kake_total
24
+ end
25
+
26
+ # 汲水
27
+ def water_total
28
+ (waters || []).map(&:weight).map(&:to_f).sum.to_f
23
29
  end
24
30
 
25
31
  # 麹歩合
@@ -27,8 +33,8 @@ module Toji
27
33
  # 留め仕込みまでの総米重量の20〜22%が標準である
28
34
  # なお、留め仕込みまでの麹歩合が20%を下回ると蒸米の溶解糖化に影響が出るので注意がいる
29
35
  # 出典: 酒造教本 P95
30
- def koji_rate
31
- val = koji.to_f / rice_total
36
+ def koji_ratio
37
+ val = koji_total / rice_total
32
38
  val.nan? ? 0.0 : val
33
39
  end
34
40
 
@@ -41,54 +47,90 @@ module Toji
41
47
  # 全体: 留までの総米に対し120〜130%、標準は125%、高級酒は130〜145%である
42
48
  #
43
49
  # 出典: 酒造教本 P96
44
- def water_rate
45
- val = water.to_f / rice_total
50
+ def water_ratio
51
+ val = water_total / rice_total
46
52
  val.nan? ? 0.0 : val
47
53
  end
48
54
 
49
- def round(ndigit=0, mini_ndigit=nil, half: :up)
55
+ def scale!(ratio)
56
+ kojis&.each {|koji|
57
+ koji.weight *= ratio
58
+ }
59
+ kakes&.each {|kake|
60
+ kake.weight *= ratio
61
+ }
62
+ waters&.each {|water|
63
+ water.weight *= ratio
64
+ }
65
+ lactic_acids&.each {|lactic_acid|
66
+ lactic_acid.weight *= ratio
67
+ }
68
+ alcohols&.each {|alcohol|
69
+ alcohol.weight *= ratio
70
+ }
71
+ yeasts&.each {|yeast|
72
+ yeast.weight *= ratio
73
+ }
74
+ self
75
+ end
76
+
77
+ def scale(ratio)
78
+ Utils.check_dup(self)
79
+
80
+ dst = self.dup
81
+ dst.scale!(ratio)
82
+ end
83
+
84
+ def round!(ndigit=0, mini_ndigit=nil, half: :up)
50
85
  if !mini_ndigit
51
86
  mini_ndigit = ndigit + 3
52
87
  end
53
88
 
54
- self.class.new.tap {|o|
55
- o.koji = koji.to_f.round(ndigit, half: half)
56
- o.koji_soaked_rate = koji_soaked_rate.to_f
57
- o.koji_steamed_rate = koji_steamed_rate.to_f
58
- o.koji_dekoji_rate = koji_dekoji_rate.to_f
59
- o.koji_interval_days = koji_interval_days.to_i
60
-
61
- o.kake = kake.to_f.round(ndigit, half: half)
62
- o.kake_soaked_rate = kake_soaked_rate.to_f
63
- o.kake_steamed_rate = kake_steamed_rate.to_f
64
- o.kake_interval_days = kake_interval_days.to_i
65
-
66
- o.water = water.to_f.round(ndigit, half: half)
67
- o.lactic_acid = lactic_acid.to_f.round(mini_ndigit, half: half)
68
- o.alcohol = alcohol.to_f.round(ndigit, half: half)
69
- o.yeast = yeast.to_f.round(mini_ndigit, half: half)
89
+ kojis&.each {|koji|
90
+ koji.weight = koji.weight.to_f.round(ndigit, half: half)
91
+ }
92
+ kakes&.each {|kake|
93
+ kake.weight = kake.weight.to_f.round(ndigit, half: half)
94
+ }
95
+ waters&.each {|water|
96
+ water.weight = water.weight.to_f.round(ndigit, half: half)
70
97
  }
98
+ lactic_acids&.each {|lactic_acid|
99
+ lactic_acid.weight = lactic_acid.weight.to_f.round(mini_ndigit, half: half)
100
+ }
101
+ alcohols&.each {|alcohol|
102
+ alcohol.weight = alcohol.weight.to_f.round(ndigit, half: half)
103
+ }
104
+ yeasts&.each {|yeast|
105
+ yeast.weight = yeast.weight.to_f.round(mini_ndigit, half: half)
106
+ }
107
+
108
+ self
109
+ end
110
+
111
+ def round(ndigit=0, mini_ndigit=nil, half: :up)
112
+ Utils.check_dup(self)
113
+
114
+ dst = self.dup
115
+ dst.round!(ndigit, mini_ndigit, half: half)
71
116
  end
72
117
 
73
118
  def +(other)
74
119
  if Step===other
75
- self.class.new.tap {|o|
76
- o.koji = koji.to_f + other.koji.to_f
77
- o.koji_soaked_rate = koji_soaked_rate.to_f
78
- o.koji_steamed_rate = koji_steamed_rate.to_f
79
- o.koji_dekoji_rate = koji_dekoji_rate.to_f
80
- o.koji_interval_days = koji_interval_days.to_i
81
-
82
- o.kake = kake.to_f + other.kake.to_f
83
- o.kake_soaked_rate = kake_soaked_rate.to_f
84
- o.kake_steamed_rate = kake_steamed_rate.to_f
85
- o.kake_interval_days = kake_interval_days.to_i
86
-
87
- o.water = water.to_f + other.water.to_f
88
- o.lactic_acid = lactic_acid.to_f + other.lactic_acid.to_f
89
- o.alcohol = alcohol.to_f + other.alcohol.to_f
90
- o.yeast = yeast.to_f + other.yeast.to_f
91
- }
120
+ Utils.check_dup(self)
121
+ Utils.check_dup(other)
122
+
123
+ dst = self.dup
124
+ other = other.dup
125
+
126
+ dst.kojis = Utils.merge_ingredients(dst.kojis, other.kojis)
127
+ dst.kakes = Utils.merge_ingredients(dst.kakes, other.kakes)
128
+ dst.waters = Utils.merge_ingredients(dst.waters, other.waters)
129
+ dst.lactic_acids = Utils.merge_ingredients(dst.lactic_acids, other.lactic_acids)
130
+ dst.alcohols = Utils.merge_ingredients(dst.alcohols, other.alcohols)
131
+ dst.yeasts = Utils.merge_ingredients(dst.yeasts, other.yeasts)
132
+
133
+ dst
92
134
  else
93
135
  x, y = other.coerce(self)
94
136
  x + y
@@ -97,23 +139,7 @@ module Toji
97
139
 
98
140
  def *(other)
99
141
  if Integer===other || Float===other
100
- self.class.new.tap {|o|
101
- o.koji = koji.to_f * other
102
- o.koji_soaked_rate = koji_soaked_rate.to_f
103
- o.koji_steamed_rate = koji_steamed_rate.to_f
104
- o.koji_dekoji_rate = koji_dekoji_rate.to_f
105
- o.koji_interval_days = koji_interval_days.to_i
106
-
107
- o.kake = kake.to_f * other
108
- o.kake_soaked_rate = kake_soaked_rate.to_f
109
- o.kake_steamed_rate = kake_steamed_rate.to_f
110
- o.kake_interval_days = kake_interval_days.to_i
111
-
112
- o.water = water.to_f * other
113
- o.lactic_acid = lactic_acid.to_f * other
114
- o.alcohol = alcohol.to_f * other
115
- o.yeast = yeast.to_f * other
116
- }
142
+ scale(other)
117
143
  else
118
144
  x, y = other.coerce(self)
119
145
  x * y
@@ -0,0 +1,5 @@
1
+ require 'toji/schedule/base'
2
+ require 'toji/schedule/rice_schedule'
3
+ require 'toji/schedule/koji_schedule'
4
+ require 'toji/schedule/kake_schedule'
5
+ require 'toji/schedule/action_schedule'
@@ -0,0 +1,9 @@
1
+ module Toji
2
+ module Schedule
3
+ module ActionSchedule
4
+ include Base
5
+
6
+ attr_reader :index
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Toji
2
+ module Schedule
3
+ module Base
4
+ attr_reader :product
5
+ attr_reader :date
6
+ attr_reader :type
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Toji
2
+ module Schedule
3
+ module KakeSchedule
4
+ include RiceSchedule
5
+
6
+ def rice_type
7
+ :kake
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Toji
2
+ module Schedule
3
+ module KojiSchedule
4
+ include RiceSchedule
5
+
6
+ def rice_type
7
+ :koji
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module Toji
2
+ module Schedule
3
+ module RiceSchedule
4
+ include Base
5
+
6
+ attr_reader :rice_type
7
+ attr_reader :step_indexes
8
+
9
+ attr_reader :expect
10
+
11
+ def type
12
+ :rice
13
+ end
14
+ end
15
+ end
16
+ end