toji 2.8.0 → 2.13.0

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 +54 -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 +59 -40
  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 -28
  103. data/lib/toji/product/rice_event_group.rb +0 -19
@@ -0,0 +1,43 @@
1
+ module Toji
2
+ module Utils
3
+ def self.activerecord_defined?
4
+ Object.const_defined?(:ActiveRecord) && ActiveRecord.const_defined?(:Base)
5
+ end
6
+
7
+ def self.check_dup(obj)
8
+ if activerecord_defined? && ActiveRecord::Base===obj
9
+ if !obj.class.method_defined?(:initialize_dup, false)
10
+ raise Error, "implementation required: #{obj.class}.initialize_dup"
11
+ end
12
+ else
13
+ if !obj.class.private_method_defined?(:initialize_copy, false)
14
+ raise Error, "implementation required: #{obj.class}.initialize_copy"
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.merge_ingredients(ingredients1, ingredients2)
20
+ result = {}
21
+
22
+ ingredients1&.each {|src|
23
+ dst = result[src.group_key]
24
+ if dst
25
+ dst.weight = dst.weight.to_f + src.weight.to_f
26
+ else
27
+ result[src.group_key] = src
28
+ end
29
+ }
30
+
31
+ ingredients2&.each {|src|
32
+ dst = result[src.group_key]
33
+ if dst
34
+ dst.weight = dst.weight.to_f + src.weight.to_f
35
+ else
36
+ result[src.group_key] = src.dup
37
+ end
38
+ }
39
+
40
+ result.values
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Toji
2
- VERSION = "2.8.0"
2
+ VERSION = "2.13.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toji
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshida Tetsuya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-06 00:00:00.000000000 Z
11
+ date: 2020-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -115,57 +115,76 @@ files:
115
115
  - example/example_core.rb
116
116
  - example/kake_ingredient.rb
117
117
  - example/koji_ingredient.rb
118
- - example/koji_making.ipynb
119
- - example/koji_making.rb
120
- - example/koji_making.yaml
121
- - example/koji_making_multi.ipynb
122
- - example/moromi.ipynb
123
- - example/moromi.rb
124
- - example/moromi.yaml
125
- - example/moto.rb
126
- - example/moto.yaml
118
+ - example/koji_progress.ipynb
119
+ - example/koji_progress.rb
120
+ - example/koji_progress.yaml
121
+ - example/koji_progress_multi.ipynb
122
+ - example/moromi_progress.ipynb
123
+ - example/moromi_progress.rb
124
+ - example/moromi_progress.yaml
125
+ - example/moto_progress.ipynb
126
+ - example/moto_progress.rb
127
+ - example/moto_progress.yaml
127
128
  - example/recipe.rb
128
129
  - lib/toji.rb
129
- - lib/toji/brew.rb
130
- - lib/toji/brew/base.rb
131
- - lib/toji/brew/builder.rb
132
- - lib/toji/brew/graph.rb
133
- - lib/toji/brew/graph/ab.rb
134
- - lib/toji/brew/graph/bmd.rb
135
- - lib/toji/brew/graph/multi_progress.rb
136
- - lib/toji/brew/graph/progress.rb
137
- - lib/toji/brew/koji.rb
138
- - lib/toji/brew/moromi.rb
139
- - lib/toji/brew/moto.rb
140
- - lib/toji/brew/state.rb
141
- - lib/toji/brew/wrapped_state.rb
142
130
  - lib/toji/calendar.rb
143
131
  - lib/toji/calendar/date_column.rb
144
132
  - lib/toji/calendar/date_row.rb
145
133
  - lib/toji/ingredient.rb
134
+ - lib/toji/ingredient/alcohol.rb
135
+ - lib/toji/ingredient/base.rb
146
136
  - lib/toji/ingredient/kake.rb
147
- - lib/toji/ingredient/kake/actual.rb
148
- - lib/toji/ingredient/kake/base.rb
149
- - lib/toji/ingredient/kake/expected.rb
150
137
  - lib/toji/ingredient/koji.rb
151
- - lib/toji/ingredient/koji/actual.rb
152
- - lib/toji/ingredient/koji/actual_fermentable.rb
153
- - lib/toji/ingredient/koji/base.rb
154
- - lib/toji/ingredient/koji/expected.rb
155
- - lib/toji/ingredient/koji/expected_fermentable.rb
156
- - lib/toji/ingredient/koji_rate.rb
138
+ - lib/toji/ingredient/lactic_acid.rb
157
139
  - lib/toji/ingredient/rice.rb
158
- - lib/toji/ingredient/rice/actual_steamable.rb
159
- - lib/toji/ingredient/rice/base.rb
160
- - lib/toji/ingredient/rice/expected_steamable.rb
161
- - lib/toji/ingredient/rice_rate.rb
140
+ - lib/toji/ingredient/tanekoji.rb
141
+ - lib/toji/ingredient/water.rb
142
+ - lib/toji/ingredient/yeast.rb
143
+ - lib/toji/processing.rb
144
+ - lib/toji/processing/base.rb
145
+ - lib/toji/processing/cooled_rice.rb
146
+ - lib/toji/processing/cooled_rice_element.rb
147
+ - lib/toji/processing/dekoji.rb
148
+ - lib/toji/processing/dekoji_element.rb
149
+ - lib/toji/processing/kake_processing.rb
150
+ - lib/toji/processing/koji_processing.rb
151
+ - lib/toji/processing/rice_processing.rb
152
+ - lib/toji/processing/soaked_rice.rb
153
+ - lib/toji/processing/soaked_rice_element.rb
154
+ - lib/toji/processing/steamed_rice.rb
155
+ - lib/toji/processing/steamed_rice_element.rb
162
156
  - lib/toji/product.rb
163
- - lib/toji/product/event.rb
164
- - lib/toji/product/rice_event.rb
165
- - lib/toji/product/rice_event_group.rb
157
+ - lib/toji/product/schedule_factory.rb
158
+ - lib/toji/progress.rb
159
+ - lib/toji/progress/base_progress.rb
160
+ - lib/toji/progress/base_state.rb
161
+ - lib/toji/progress/builder.rb
162
+ - lib/toji/progress/graph.rb
163
+ - lib/toji/progress/graph/ab.rb
164
+ - lib/toji/progress/graph/bmd.rb
165
+ - lib/toji/progress/graph/multi_progress_note.rb
166
+ - lib/toji/progress/graph/progress_note.rb
167
+ - lib/toji/progress/koji_progress.rb
168
+ - lib/toji/progress/koji_state.rb
169
+ - lib/toji/progress/moromi_progress.rb
170
+ - lib/toji/progress/moromi_state.rb
171
+ - lib/toji/progress/moto_progress.rb
172
+ - lib/toji/progress/moto_state.rb
173
+ - lib/toji/progress/progress.rb
174
+ - lib/toji/progress/state.rb
175
+ - lib/toji/progress/state/baume_to_nihonshudo.rb
176
+ - lib/toji/progress/state/nihonshudo_to_baume.rb
166
177
  - lib/toji/recipe.rb
167
178
  - lib/toji/recipe/ab_expect.rb
179
+ - lib/toji/recipe/action.rb
168
180
  - lib/toji/recipe/step.rb
181
+ - lib/toji/schedule.rb
182
+ - lib/toji/schedule/action_schedule.rb
183
+ - lib/toji/schedule/base.rb
184
+ - lib/toji/schedule/kake_schedule.rb
185
+ - lib/toji/schedule/koji_schedule.rb
186
+ - lib/toji/schedule/rice_schedule.rb
187
+ - lib/toji/utils.rb
169
188
  - lib/toji/version.rb
170
189
  - toji.gemspec
171
190
  homepage: https://github.com/yoshida-eth0/ruby-toji
@@ -1,18 +0,0 @@
1
- module Toji
2
- module Brew
3
- SECOND = 1
4
- MINUTE = 60 * SECOND
5
- HOUR = 60 * MINUTE
6
- DAY = 24 * HOUR
7
- end
8
- end
9
-
10
- require 'toji/brew/base'
11
- require 'toji/brew/wrapped_state'
12
- require 'toji/brew/state'
13
- require 'toji/brew/builder'
14
- require 'toji/brew/graph'
15
-
16
- require 'toji/brew/koji'
17
- require 'toji/brew/moto'
18
- require 'toji/brew/moromi'
@@ -1,55 +0,0 @@
1
- module Toji
2
- module Brew
3
- module Base
4
- REQUIRED_KEYS = [
5
- :time,
6
- :elapsed_time,
7
- :day,
8
- :day_label,
9
- :display_time,
10
- ].freeze
11
-
12
- OPTIONAL_KEYS = [
13
- :moromi_day,
14
- :mark,
15
- :temps,
16
- :preset_temp,
17
- :room_temp,
18
- :room_psychrometry,
19
- :baume,
20
- :nihonshudo,
21
- :display_baume,
22
- :acid,
23
- :amino_acid,
24
- :alcohol,
25
- :bmd,
26
- :warmings,
27
- :note,
28
- ].freeze
29
-
30
- attr_accessor :wrapped_states
31
- attr_accessor :day_offset
32
- attr_accessor :base_time
33
-
34
- def days
35
- ((wrapped_states.last.elapsed_time_with_offset.to_f + 1) / DAY).ceil
36
- end
37
-
38
- def day_labels
39
- days.times.map(&:succ).map(&:to_s)
40
- end
41
-
42
- def moromi_tome_day
43
- nil
44
- end
45
-
46
- def has_keys
47
- result = REQUIRED_KEYS.dup
48
-
49
- result += OPTIONAL_KEYS.select {|k|
50
- wrapped_states.find {|s| s.send(k).present?}
51
- }
52
- end
53
- end
54
- end
55
- end
@@ -1,98 +0,0 @@
1
- module Toji
2
- module Brew
3
- class Builder
4
-
5
- def initialize(cls)
6
- @cls = cls
7
- @states = []
8
- @date_line = 0
9
- @prefix_day_labels = nil
10
- @base_time = nil
11
- @time_interpolation = false
12
- @elapsed_time_interpolation = false
13
- end
14
-
15
- def <<(state)
16
- @states += [state].flatten.map {|state|
17
- State.create(state)
18
- }
19
- self
20
- end
21
- alias_method :add, :<<
22
-
23
- def date_line(val, unit=SECOND)
24
- @date_line = (val * unit).to_i
25
- self
26
- end
27
-
28
- def prefix_day_labels(val)
29
- @prefix_day_labels = val
30
- self
31
- end
32
-
33
- def time_interpolation(base_time)
34
- @base_time = base_time&.to_time
35
- @time_interpolation = true
36
- #@elapsed_time_interpolation = false
37
- self
38
- end
39
-
40
- def elapsed_time_interpolation
41
- #@base_time = nil
42
- #@time_interpolation = false
43
- @elapsed_time_interpolation = true
44
- self
45
- end
46
-
47
- def build
48
- brew = @cls.new
49
-
50
- wrapped_states = @states.map{|s| WrappedState.new(s, brew)}
51
-
52
- # time interpolation
53
- if @time_interpolation
54
- base_time = @base_time
55
-
56
- base_state = wrapped_states.select{|w| w.time && w.elapsed_time}.first
57
- if base_state
58
- base_time = base_state.time - base_state.elapsed_time
59
- end
60
-
61
- wrapped_states.each {|w|
62
- if w.elapsed_time
63
- w.time = base_time + w.elapsed_time
64
- end
65
- }
66
- end
67
-
68
- # elapsed_time interpolation
69
- if @elapsed_time_interpolation
70
- base_time = wrapped_states.map(&:time).sort.first
71
- wrapped_states.each {|w|
72
- if w.time
73
- w.elapsed_time = (w.time - base_time).to_i
74
- end
75
- }
76
- end
77
-
78
- wrapped_states = wrapped_states.sort_by(&:elapsed_time)
79
- base_time = wrapped_states.first&.time
80
-
81
- # day_offset
82
- day_offset = 0
83
- if base_time
84
- day_offset = base_time - Time.mktime(base_time.year, base_time.month, base_time.day)
85
- end
86
- day_offset = (DAY - @date_line + day_offset) % DAY
87
-
88
- brew.wrapped_states = wrapped_states
89
- brew.day_offset = day_offset
90
- brew.base_time = base_time
91
- if Moromi===brew
92
- brew.prefix_day_labels = @prefix_day_labels
93
- end
94
- brew
95
- end
96
- end
97
- end
98
- end
@@ -1,11 +0,0 @@
1
- require 'toji/brew/graph/progress'
2
- require 'toji/brew/graph/multi_progress'
3
- require 'toji/brew/graph/bmd'
4
- require 'toji/brew/graph/ab'
5
-
6
- module Toji
7
- module Brew
8
- module Graph
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Toji
2
- module Brew
3
- module Koji
4
- include Base
5
-
6
- def progress(name: nil, dash: :solid, enable_annotations: true)
7
- Graph::Progress.new(self, name: name, dash: dash, enable_annotations: enable_annotations)
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Toji
2
- module Brew
3
- module Moto
4
- include Base
5
-
6
- def progress(name: nil, dash: :solid, enable_annotations: true)
7
- Graph::Progress.new(self, name: name, dash: dash, enable_annotations: enable_annotations)
8
- end
9
- end
10
- end
11
- end
@@ -1,122 +0,0 @@
1
- module Toji
2
- module Brew
3
- module State
4
- KEYS = [
5
- :time,
6
- :elapsed_time,
7
- :mark,
8
- :temps,
9
- :preset_temp,
10
- :room_temp,
11
- :room_psychrometry,
12
- :baume,
13
- :nihonshudo,
14
- :acid,
15
- :amino_acid,
16
- :alcohol,
17
- :warmings,
18
- :note,
19
- ].freeze
20
-
21
- attr_accessor :time
22
- attr_accessor :elapsed_time
23
- attr_accessor :mark
24
- attr_accessor :temps
25
-
26
- attr_accessor :preset_temp
27
- attr_accessor :room_temp
28
- attr_accessor :room_psychrometry
29
-
30
- attr_accessor :baume
31
- attr_accessor :nihonshudo
32
- attr_accessor :acid
33
- attr_accessor :amino_acid
34
- attr_accessor :alcohol
35
-
36
- attr_accessor :warmings
37
- attr_accessor :note
38
-
39
-
40
- def self.included(cls)
41
- cls.prepend PrependMethods
42
- end
43
-
44
- module PrependMethods
45
- def temps
46
- (super || []).map(&:to_f)
47
- end
48
-
49
- def temps=(val)
50
- super([val].flatten.compact.map(&:to_f))
51
- end
52
-
53
- def time=(val)
54
- super(val&.to_time)
55
- end
56
-
57
- def warmings
58
- super || []
59
- end
60
-
61
- def warmings=(val)
62
- super([val].flatten.compact)
63
- end
64
- end
65
-
66
- module BaumeToNihonshudo
67
- def nihonshudo
68
- if self.baume
69
- self.baume * -10
70
- end
71
- end
72
-
73
- def nihonshudo=(val)
74
- if val
75
- self.baume = val.to_f / -10.0
76
- else
77
- self.baume = nil
78
- end
79
- end
80
- end
81
-
82
- module NihonshudoToBaume
83
- def baume
84
- if self.nihonshudo
85
- self.nihonshudo / -10.0
86
- end
87
- end
88
-
89
- def baume=(val)
90
- if val
91
- self.nihonshudo = val.to_f * -10
92
- else
93
- self.nihonshudo = nil
94
- end
95
- end
96
- end
97
-
98
- def self.create(val)
99
- if State===val
100
- val
101
- elsif WrappedState==val
102
- val.state
103
- #elsif Hash===val
104
- # #s = Class.new {
105
- # # include State
106
- # #}.new
107
- # s = Object.new.tap {|o|
108
- # o.extend State
109
- # o.extend State::PrependMethods
110
- # }
111
-
112
- # KEYS.each {|k|
113
- # s.send("#{k}=", val[k])
114
- # }
115
- # s
116
- else
117
- raise Error, "ArgumentError: cant cast to Toji::Brew::State"
118
- end
119
- end
120
- end
121
- end
122
- end