toji 2.7.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/calendar.ipynb +36 -36
- data/example/calendar_file.ipynb +36 -36
- data/example/example_core.rb +57 -4
- data/example/{shubo.rb → moto.rb} +2 -2
- data/example/{shubo.yaml → moto.yaml} +0 -0
- data/example/recipe.rb +1 -1
- data/lib/toji.rb +1 -0
- data/lib/toji/brew.rb +1 -1
- data/lib/toji/brew/{shubo.rb → moto.rb} +1 -1
- data/lib/toji/calendar.rb +12 -12
- data/lib/toji/calendar/date_column.rb +4 -19
- data/lib/toji/calendar/date_row.rb +1 -1
- data/lib/toji/event.rb +5 -0
- data/lib/toji/event/action_event.rb +12 -0
- data/lib/toji/event/base.rb +9 -0
- data/lib/toji/event/kake_event.rb +13 -0
- data/lib/toji/event/koji_event.rb +19 -0
- data/lib/toji/event/rice_event.rb +34 -0
- data/lib/toji/product.rb +10 -65
- data/lib/toji/product/event_factory.rb +70 -0
- data/lib/toji/recipe.rb +16 -9
- data/lib/toji/recipe/action.rb +8 -0
- data/lib/toji/version.rb +1 -1
- metadata +14 -10
- data/example/shubo.ipynb +0 -121
- data/lib/toji/product/event.rb +0 -13
- data/lib/toji/product/rice_event.rb +0 -28
- data/lib/toji/product/rice_event_group.rb +0 -19
data/example/example_core.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'toji'
|
1
2
|
require 'securerandom'
|
2
3
|
|
3
4
|
module Example
|
@@ -56,8 +57,8 @@ module Example
|
|
56
57
|
include Toji::Brew::Koji
|
57
58
|
end
|
58
59
|
|
59
|
-
class
|
60
|
-
include Toji::Brew::
|
60
|
+
class Moto < Base
|
61
|
+
include Toji::Brew::Moto
|
61
62
|
end
|
62
63
|
|
63
64
|
class Moromi < Base
|
@@ -68,6 +69,7 @@ module Example
|
|
68
69
|
|
69
70
|
class Step
|
70
71
|
include Toji::Recipe::Step
|
72
|
+
attr_accessor :name
|
71
73
|
|
72
74
|
def self.create(name:, kake: 0, koji: 0, water: 0, lactic_acid: 0, alcohol: 0, yeast: 0, koji_interval_days: 0, kake_interval_days: 0)
|
73
75
|
new.tap {|o|
|
@@ -243,14 +245,53 @@ module Example
|
|
243
245
|
end
|
244
246
|
|
245
247
|
|
248
|
+
class KojiEvent
|
249
|
+
include Toji::Event::KojiEvent
|
250
|
+
|
251
|
+
def initialize(product:, date:, group_index:, indexes:, raw:)
|
252
|
+
@product = product
|
253
|
+
@date = date
|
254
|
+
@group_index = group_index
|
255
|
+
@indexes = indexes
|
256
|
+
@raw = raw
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
class KakeEvent
|
262
|
+
include Toji::Event::KakeEvent
|
263
|
+
|
264
|
+
def initialize(product:, date:, group_index:, indexes:, raw:)
|
265
|
+
@product = product
|
266
|
+
@date = date
|
267
|
+
@group_index = group_index
|
268
|
+
@indexes = indexes
|
269
|
+
@raw = raw
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
class ActionEvent
|
275
|
+
include Toji::Event::ActionEvent
|
276
|
+
|
277
|
+
def initialize(product:, date:, type:, index:)
|
278
|
+
@product = product
|
279
|
+
@date = date
|
280
|
+
@type = type
|
281
|
+
@index = index
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
|
246
286
|
class Product
|
247
287
|
include Toji::Product
|
288
|
+
include Toji::Product::EventFactory
|
248
289
|
|
249
290
|
attr_accessor :description
|
250
291
|
attr_accessor :color
|
251
292
|
|
252
|
-
def initialize(
|
253
|
-
@
|
293
|
+
def initialize(id, name, description, recipe, base_date, color=nil)
|
294
|
+
@id = id
|
254
295
|
@name = name
|
255
296
|
@description = description
|
256
297
|
@recipe = recipe
|
@@ -258,6 +299,18 @@ module Example
|
|
258
299
|
@color = color
|
259
300
|
end
|
260
301
|
|
302
|
+
def create_koji_event(date:, group_index:, indexes:, raw:)
|
303
|
+
KojiEvent.new(product: self, date: date, group_index: group_index, indexes: indexes, raw: raw)
|
304
|
+
end
|
305
|
+
|
306
|
+
def create_kake_event(date:, group_index:, indexes:, raw:)
|
307
|
+
KakeEvent.new(product: self, date: date, group_index: group_index, indexes: indexes, raw: raw)
|
308
|
+
end
|
309
|
+
|
310
|
+
def create_action_event(date:, type:, index:)
|
311
|
+
ActionEvent.new(product: self, date: date, type: type, index: index)
|
312
|
+
end
|
313
|
+
|
261
314
|
def self.create(args)
|
262
315
|
if self===args
|
263
316
|
args
|
@@ -2,12 +2,12 @@ require 'toji'
|
|
2
2
|
require_relative 'example_core'
|
3
3
|
require 'terminal-table'
|
4
4
|
|
5
|
-
|
5
|
+
moto = Example::Brew::Moto.load_yaml_file(File.dirname(__FILE__)+"/moto.yaml")
|
6
6
|
|
7
7
|
table = Terminal::Table.new do |t|
|
8
8
|
t << ["作業", "日数", "品温(度)", "ボーメ", "酸度", "経過時間", "日時"]
|
9
9
|
t << :separator
|
10
|
-
|
10
|
+
moto.wrapped_states.each {|s|
|
11
11
|
temp = s.temps.map(&:to_s).join(" / ")
|
12
12
|
t << [s.mark, s.day_label, temp, s.baume, s.acid, s.elapsed_time, s.display_time]
|
13
13
|
}
|
File without changes
|
data/example/recipe.rb
CHANGED
@@ -24,7 +24,7 @@ table = Terminal::Table.new do |t|
|
|
24
24
|
t << ["[累計]"]
|
25
25
|
t << ["総米(g)"] + recipe.cumulative_rice_totals
|
26
26
|
t << ["白米比率"] + recipe.rice_rates.map{|v| v&.round(2)}
|
27
|
-
t << ["酒母歩合(%)"] + recipe.
|
27
|
+
t << ["酒母歩合(%)"] + recipe.cumulative_moto_rates.map{|s| s * 100}.map{|v| v&.round(2)}
|
28
28
|
t << ["タンク内容量(ml)"] + recipe.steps.map {|s|
|
29
29
|
kake = Toji::Ingredient::Kake::Expected.create(s.kake)
|
30
30
|
koji = Toji::Ingredient::Koji::Expected.create(s.koji)
|
data/lib/toji.rb
CHANGED
data/lib/toji/brew.rb
CHANGED
data/lib/toji/calendar.rb
CHANGED
@@ -28,10 +28,12 @@ module Toji
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def table_data
|
31
|
-
|
31
|
+
koji_events = @products.map{|product| product.koji_events}.flatten
|
32
|
+
kake_events = @products.map{|product| product.kake_events}.flatten
|
33
|
+
events = koji_events + kake_events
|
32
34
|
|
33
|
-
koji_len =
|
34
|
-
kake_len =
|
35
|
+
koji_len = koji_events.map(&:group_index).max + 1
|
36
|
+
kake_len = kake_events.map(&:group_index).max + 1
|
35
37
|
min_date = events.map(&:date).min
|
36
38
|
max_date = events.map(&:date).max
|
37
39
|
|
@@ -65,10 +67,10 @@ module Toji
|
|
65
67
|
date_row = _date_rows[date]
|
66
68
|
if date_row
|
67
69
|
koji_len.times {|i|
|
68
|
-
columns <<
|
70
|
+
columns << date_row.kojis[i]
|
69
71
|
}
|
70
72
|
kake_len.times {|i|
|
71
|
-
columns <<
|
73
|
+
columns << date_row.kakes[i]
|
72
74
|
}
|
73
75
|
else
|
74
76
|
(koji_len + kake_len).times {
|
@@ -88,14 +90,12 @@ module Toji
|
|
88
90
|
data = table_data
|
89
91
|
data[:rows] = data[:rows].map {|row|
|
90
92
|
row.map {|column|
|
91
|
-
if
|
92
|
-
column.
|
93
|
-
|
94
|
-
weight = "%.17g" % c[:weight]
|
95
|
-
"#{name}: #{weight}"
|
96
|
-
}.join("<br>")
|
97
|
-
else
|
93
|
+
if DateColumn===column
|
94
|
+
column.text
|
95
|
+
elsif column
|
98
96
|
column
|
97
|
+
else
|
98
|
+
""
|
99
99
|
end
|
100
100
|
}
|
101
101
|
}
|
@@ -12,28 +12,13 @@ module Toji
|
|
12
12
|
end
|
13
13
|
alias_method :add, :<<
|
14
14
|
|
15
|
-
def event_groups
|
16
|
-
@rice_events.group_by {|e|
|
17
|
-
e.group_key
|
18
|
-
}.values
|
19
|
-
end
|
20
|
-
|
21
15
|
def text
|
22
|
-
|
23
|
-
name =
|
24
|
-
|
25
|
-
"#{name}: #{
|
16
|
+
@rice_events.map {|ev|
|
17
|
+
name = ev.product.name
|
18
|
+
raw = "%.17g" % ev.raw
|
19
|
+
"#{name}: #{raw}"
|
26
20
|
}.join("<br>")
|
27
21
|
end
|
28
|
-
|
29
|
-
def column_events
|
30
|
-
event_groups.map {|es|
|
31
|
-
{
|
32
|
-
product: es.first.product,
|
33
|
-
weight: es.map(&:weight).sum,
|
34
|
-
}
|
35
|
-
}
|
36
|
-
end
|
37
22
|
end
|
38
23
|
end
|
39
24
|
end
|
data/lib/toji/event.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'toji/event/rice_event'
|
2
|
+
|
3
|
+
module Toji
|
4
|
+
module Event
|
5
|
+
module KojiEvent
|
6
|
+
include RiceEvent
|
7
|
+
|
8
|
+
attr_reader :dekoji
|
9
|
+
|
10
|
+
def rice_type
|
11
|
+
:koji
|
12
|
+
end
|
13
|
+
|
14
|
+
def dekoji_rate
|
15
|
+
(dekoji.to_f - raw.to_f) / raw.to_f
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'toji/event/base'
|
2
|
+
|
3
|
+
module Toji
|
4
|
+
module Event
|
5
|
+
module RiceEvent
|
6
|
+
include Base
|
7
|
+
|
8
|
+
attr_reader :rice_type
|
9
|
+
attr_reader :group_index
|
10
|
+
attr_reader :indexes
|
11
|
+
|
12
|
+
attr_reader :raw
|
13
|
+
attr_reader :soaked
|
14
|
+
attr_reader :steamed
|
15
|
+
attr_reader :cooled
|
16
|
+
|
17
|
+
def type
|
18
|
+
:rice
|
19
|
+
end
|
20
|
+
|
21
|
+
def soaked_rate
|
22
|
+
(soaked.to_f - raw.to_f) / raw.to_f
|
23
|
+
end
|
24
|
+
|
25
|
+
def steamed_rate
|
26
|
+
(steamed.to_f - raw.to_f) / raw.to_f
|
27
|
+
end
|
28
|
+
|
29
|
+
def cooled_rate
|
30
|
+
(cooled.to_f - raw.to_f) / raw.to_f
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/toji/product.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
require 'toji/product/
|
2
|
-
require 'toji/product/rice_event'
|
3
|
-
require 'toji/product/rice_event_group'
|
1
|
+
require 'toji/product/event_factory'
|
4
2
|
|
5
3
|
module Toji
|
6
4
|
module Product
|
7
|
-
attr_reader :reduce_key
|
8
5
|
attr_accessor :name
|
9
6
|
attr_accessor :recipe
|
10
7
|
attr_accessor :base_date
|
11
8
|
|
9
|
+
attr_accessor :koji_events
|
10
|
+
attr_accessor :kake_events
|
11
|
+
attr_accessor :action_events
|
12
|
+
|
12
13
|
def koji_dates
|
13
14
|
date = base_date
|
14
15
|
recipe.steps.map {|step|
|
@@ -23,33 +24,10 @@ module Toji
|
|
23
24
|
}
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
base_date
|
28
|
-
|
29
|
-
|
30
|
-
def koji_events
|
31
|
-
koji_dates.map.with_index {|date,i|
|
32
|
-
RiceEvent.new(
|
33
|
-
product: self,
|
34
|
-
type: :koji,
|
35
|
-
index: i,
|
36
|
-
group_index: koji_dates.find_index(date),
|
37
|
-
date: date,
|
38
|
-
weight: recipe.steps[i].koji,
|
39
|
-
)
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
def kake_events
|
44
|
-
kake_dates.map.with_index {|date,i|
|
45
|
-
RiceEvent.new(
|
46
|
-
product: self,
|
47
|
-
type: :kake,
|
48
|
-
index: i,
|
49
|
-
group_index: kake_dates.find_index(date),
|
50
|
-
date: date,
|
51
|
-
weight: recipe.steps[i].kake,
|
52
|
-
)
|
27
|
+
def action_dates
|
28
|
+
date = base_date
|
29
|
+
recipe.actions.map {|action|
|
30
|
+
date = date.next_day(action.interval_days)
|
53
31
|
}
|
54
32
|
end
|
55
33
|
|
@@ -57,41 +35,8 @@ module Toji
|
|
57
35
|
koji_events + kake_events
|
58
36
|
end
|
59
37
|
|
60
|
-
def koji_event_groups
|
61
|
-
koji_events.group_by{|event|
|
62
|
-
event.group_key
|
63
|
-
}.map {|group_key,events|
|
64
|
-
events.select{|event| 0<event.weight}
|
65
|
-
}.select {|events|
|
66
|
-
0<events.length
|
67
|
-
}.map {|events|
|
68
|
-
RiceEventGroup.new(events)
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
def kake_event_groups
|
73
|
-
kake_events.group_by{|event|
|
74
|
-
event.group_key
|
75
|
-
}.map {|group_key,events|
|
76
|
-
events.select{|event| 0<event.weight}
|
77
|
-
}.select {|events|
|
78
|
-
0<events.length
|
79
|
-
}.map {|events|
|
80
|
-
RiceEventGroup.new(events)
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def rice_event_groups
|
85
|
-
koji_event_groups + kake_event_groups
|
86
|
-
end
|
87
|
-
|
88
38
|
def events
|
89
|
-
|
90
|
-
|
91
|
-
events += rice_event_groups
|
92
|
-
events << Event.new(squeeze_date, :squeeze)
|
93
|
-
|
94
|
-
events
|
39
|
+
rice_events + action_events
|
95
40
|
end
|
96
41
|
end
|
97
42
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Toji
|
2
|
+
module Product
|
3
|
+
module EventFactory
|
4
|
+
|
5
|
+
def create_koji_event(date:, group_index:, indexes:, raw:)
|
6
|
+
raise Error, "implement required: create_koji_event"
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_kake_event(date:, group_index:, indexes:, raw:)
|
10
|
+
raise Error, "implement required: create_kake_event"
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_action_event(date:, type:, index:)
|
14
|
+
raise Error, "implement required: create_action_event"
|
15
|
+
end
|
16
|
+
|
17
|
+
def koji_events
|
18
|
+
koji_dates.map.with_index {|date,i|
|
19
|
+
{
|
20
|
+
index: i,
|
21
|
+
date: date,
|
22
|
+
weight: recipe.steps[i].koji,
|
23
|
+
}
|
24
|
+
}.select {|event|
|
25
|
+
0<event[:weight]
|
26
|
+
}.group_by{|event|
|
27
|
+
event[:date]
|
28
|
+
}.map {|date,events|
|
29
|
+
create_koji_event(
|
30
|
+
date: date,
|
31
|
+
group_index: koji_dates.find_index(date),
|
32
|
+
indexes: events.map{|ev| ev[:index]},
|
33
|
+
raw: events.map{|ev| ev[:weight]}.sum,
|
34
|
+
)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def kake_events
|
39
|
+
kake_dates.map.with_index {|date,i|
|
40
|
+
{
|
41
|
+
index: i,
|
42
|
+
date: date,
|
43
|
+
weight: recipe.steps[i].kake,
|
44
|
+
}
|
45
|
+
}.select {|event|
|
46
|
+
0<event[:weight]
|
47
|
+
}.group_by{|event|
|
48
|
+
event[:date]
|
49
|
+
}.map {|date,events|
|
50
|
+
create_kake_event(
|
51
|
+
date: date,
|
52
|
+
group_index: kake_dates.find_index(date),
|
53
|
+
indexes: events.map{|ev| ev[:index]},
|
54
|
+
raw: events.map{|ev| ev[:weight]}.sum,
|
55
|
+
)
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def action_events
|
60
|
+
action_dates.map.with_index {|date,i|
|
61
|
+
create_action_event(
|
62
|
+
date: date,
|
63
|
+
type: recipe.actions[i].type,
|
64
|
+
index: i,
|
65
|
+
)
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|