toji 2.7.0 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 Shubo < Base
60
- include Toji::Brew::Shubo
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(reduce_key, name, description, recipe, base_date, color=nil)
253
- @reduce_key = reduce_key || SecureRandom.uuid
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
- shubo = Example::Brew::Shubo.load_yaml_file(File.dirname(__FILE__)+"/shubo.yaml")
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
- shubo.wrapped_states.each {|s|
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
@@ -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.cumulative_shubo_rates.map{|s| s * 100}.map{|v| v&.round(2)}
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)
@@ -6,6 +6,7 @@ require 'toji/ingredient'
6
6
  require 'toji/recipe'
7
7
  require 'toji/brew'
8
8
  require 'toji/calendar'
9
+ require 'toji/event'
9
10
  require 'toji/product'
10
11
 
11
12
  module Toji
@@ -14,5 +14,5 @@ require 'toji/brew/builder'
14
14
  require 'toji/brew/graph'
15
15
 
16
16
  require 'toji/brew/koji'
17
- require 'toji/brew/shubo'
17
+ require 'toji/brew/moto'
18
18
  require 'toji/brew/moromi'
@@ -1,6 +1,6 @@
1
1
  module Toji
2
2
  module Brew
3
- module Shubo
3
+ module Moto
4
4
  include Base
5
5
 
6
6
  def progress(name: nil, dash: :solid, enable_annotations: true)
@@ -28,10 +28,12 @@ module Toji
28
28
  end
29
29
 
30
30
  def table_data
31
- events = @products.map{|product| product.rice_events}.flatten
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 = events.select{|e| e.type==:koji}.map(&:group_index).max + 1
34
- kake_len = events.select{|e| e.type==:kake}.map(&:group_index).max + 1
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 << (date_row.kojis[i]&.column_events || [])
70
+ columns << date_row.kojis[i]
69
71
  }
70
72
  kake_len.times {|i|
71
- columns << (date_row.kakes[i]&.column_events || [])
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 Array===column
92
- column.map{|c|
93
- name = c[:product].name
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
- event_groups.map {|es|
23
- name = es.first.product.name
24
- weight = "%.17g" % es.map(&:weight).sum
25
- "#{name}: #{weight}"
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
@@ -12,7 +12,7 @@ module Toji
12
12
  end
13
13
 
14
14
  def <<(event)
15
- case event.type
15
+ case event.rice_type
16
16
  when :koji
17
17
  index = event.group_index
18
18
  @kojis[index] ||= DateColumn.new
@@ -0,0 +1,5 @@
1
+ require 'toji/event/base'
2
+ require 'toji/event/rice_event'
3
+ require 'toji/event/koji_event'
4
+ require 'toji/event/kake_event'
5
+ require 'toji/event/action_event'
@@ -0,0 +1,12 @@
1
+ require 'toji/event/base'
2
+
3
+ module Toji
4
+ module Event
5
+ module ActionEvent
6
+ include Event
7
+
8
+ attr_reader :index
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Toji
2
+ module Event
3
+ module Base
4
+ attr_reader :product
5
+ attr_reader :date
6
+ attr_reader :type
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'toji/event/rice_event'
2
+
3
+ module Toji
4
+ module Event
5
+ module KakeEvent
6
+ include RiceEvent
7
+
8
+ def rice_type
9
+ :kake
10
+ end
11
+ end
12
+ end
13
+ end
@@ -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
@@ -1,14 +1,15 @@
1
- require 'toji/product/event'
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 squeeze_date
27
- base_date.next_day(recipe.squeeze_interval_days)
28
- end
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
- events = []
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