toji 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +39 -0
  7. data/Rakefile +10 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/example/koji_recipe.rb +34 -0
  11. data/example/make_koji.rb +18 -0
  12. data/example/rice_recipe.rb +28 -0
  13. data/example/three_step_mashing_recipe.rb +65 -0
  14. data/lib/toji.rb +12 -0
  15. data/lib/toji/graph.rb +6 -0
  16. data/lib/toji/graph/ab.rb +75 -0
  17. data/lib/toji/ingredient.rb +8 -0
  18. data/lib/toji/ingredient/koji.rb +19 -0
  19. data/lib/toji/ingredient/koji/actual.rb +21 -0
  20. data/lib/toji/ingredient/koji/actual_fermentable.rb +15 -0
  21. data/lib/toji/ingredient/koji/base.rb +26 -0
  22. data/lib/toji/ingredient/koji/expected.rb +51 -0
  23. data/lib/toji/ingredient/koji/expected_fermentable.rb +15 -0
  24. data/lib/toji/ingredient/rice.rb +19 -0
  25. data/lib/toji/ingredient/rice/actual.rb +18 -0
  26. data/lib/toji/ingredient/rice/actual_steamable.rb +27 -0
  27. data/lib/toji/ingredient/rice/base.rb +40 -0
  28. data/lib/toji/ingredient/rice/expected.rb +46 -0
  29. data/lib/toji/ingredient/rice/expected_steamable.rb +29 -0
  30. data/lib/toji/ingredient/yeast.rb +9 -0
  31. data/lib/toji/ingredient/yeast/base.rb +21 -0
  32. data/lib/toji/ingredient/yeast/red_star.rb +30 -0
  33. data/lib/toji/progress.rb +11 -0
  34. data/lib/toji/progress/job.rb +165 -0
  35. data/lib/toji/progress/job_accessor.rb +13 -0
  36. data/lib/toji/progress/jobs.rb +142 -0
  37. data/lib/toji/progress/make_koji.rb +100 -0
  38. data/lib/toji/progress/moromi.rb +276 -0
  39. data/lib/toji/progress/shubo.rb +158 -0
  40. data/lib/toji/recipe.rb +9 -0
  41. data/lib/toji/recipe/koji_rate.rb +16 -0
  42. data/lib/toji/recipe/rice_rate.rb +10 -0
  43. data/lib/toji/recipe/rice_rate/base.rb +21 -0
  44. data/lib/toji/recipe/rice_rate/cooked.rb +61 -0
  45. data/lib/toji/recipe/rice_rate/steamed.rb +42 -0
  46. data/lib/toji/recipe/step.rb +65 -0
  47. data/lib/toji/recipe/three_step_mashing.rb +87 -0
  48. data/lib/toji/version.rb +3 -0
  49. data/toji.gemspec +36 -0
  50. metadata +178 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0fd2eacf273ed8b0126f4d78775c0b0f3d152b54cdba00cf15abe221b71baeb8
4
+ data.tar.gz: 5ad7bca85b2b46dd33ec59a5b0069612dd3cdf325fdd6404db2d9dab594f4edf
5
+ SHA512:
6
+ metadata.gz: 46c4cc2b892fc477dc7b63d01fbd75f2b5cc934d749e97b9b858820410a958d0545cf024008ad4649aa7270a0e8c2f067b667a92f2d5c3befe3643ea9da70985
7
+ data.tar.gz: 572a7438670c646a0dc93bb056a3d55e19bd7bfad5004922544cd87d8c78f8d59d2c36c5de479afe00ea9e250a8f80266d6258f7f44a8216b8c1ebfaecdcecac
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.7.0
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in toji.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 yoshida
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Toji
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/toji`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'toji'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install toji
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/toji.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "toji"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ require 'toji'
2
+ require 'terminal-table'
3
+
4
+ koji = Toji::Ingredient::Koji.expected(100, rice_rate: Toji::Recipe::RiceRate::Steamed::DEFAULT, koji_rate: Toji::Recipe::KojiRate::DEFAULT)
5
+
6
+ table = Terminal::Table.new do |t|
7
+ t << ["", "分量", "白米を基準とした歩合"]
8
+ t << :separator
9
+ t << ["麹", koji.dekoji, 1.0 + koji.dekoji_rate]
10
+ t << [" 蒸米", koji.steamed, 1.0 + koji.steamed_rate]
11
+ t << [" 白米", koji.raw, 1.0]
12
+ t << [" 汲水", koji.soaking_water, koji.soaked_rate]
13
+ t << [" 種麹", koji.tanekoji, koji.tanekoji_rate]
14
+ end
15
+ puts table
16
+ puts
17
+
18
+ table = Terminal::Table.new do |t|
19
+ t << ["工程", "原料", "分量"]
20
+ t << :separator
21
+ t << ["洗米・浸漬", "白米", koji.raw]
22
+ t << ["", "吸水増加量", koji.soaking_water]
23
+ t << :separator
24
+ t << ["水切り", "浸漬米", koji.soaked]
25
+ t << ["", "蒸発・炊飯前の汲水", koji.steaming_water]
26
+ t << :separator
27
+ t << ["蒸し", "蒸米", koji.steamed]
28
+ t << :separator
29
+ t << ["放冷・引込み", "蒸米", koji.cooled]
30
+ t << ["", "種麹", koji.tanekoji]
31
+ t << :separator
32
+ t << ["製麹", "麹", koji.dekoji]
33
+ end
34
+ puts table
@@ -0,0 +1,18 @@
1
+ require 'toji'
2
+ require 'terminal-table'
3
+
4
+ make_koji = Toji::Progress::MakeKoji.template
5
+
6
+ table = Terminal::Table.new do |t|
7
+ t << ["作業", "品温(度)", "操作室温", "乾湿差(度)", "経過時間"]
8
+ t << :separator
9
+ make_koji.jobs.each {|j|
10
+ if j.before_temp && j.after_temp
11
+ temp = "%s / %s" % [j.before_temp, j.after_temp]
12
+ else
13
+ temp = j.before_temp || j.after_temp
14
+ end
15
+ t << [j.id, temp, j.room_temp, j.room_psychrometry, j.elapsed_time]
16
+ }
17
+ end
18
+ puts table
@@ -0,0 +1,28 @@
1
+ require 'toji'
2
+ require 'terminal-table'
3
+
4
+ #rice = Toji::Ingredient::Rice.expected(100, rice_rate: Toji::Recipe::RiceRate::Steamed::DEFAULT)
5
+ rice = Toji::Ingredient::Rice.expected(100, rice_rate: Toji::Recipe::RiceRate::Cooked::DEFAULT)
6
+
7
+ table = Terminal::Table.new do |t|
8
+ t << ["", "分量", "白米を基準とした歩合"]
9
+ t << :separator
10
+ t << ["蒸米", rice.steamed, 1.0 + rice.steamed_rate]
11
+ t << [" 白米", rice.raw, 1.0]
12
+ t << [" 汲水", rice.soaking_water, rice.soaked_rate]
13
+ end
14
+ puts table
15
+ puts
16
+
17
+ table = Terminal::Table.new do |t|
18
+ t << ["工程", "原料", "分量"]
19
+ t << :separator
20
+ t << ["洗米・浸漬", "白米", rice.raw]
21
+ t << ["", "吸水増加量", rice.soaking_water]
22
+ t << :separator
23
+ t << ["水切り", "浸漬米", rice.soaked]
24
+ t << ["", "蒸発・炊飯前の汲水", rice.steaming_water]
25
+ t << :separator
26
+ t << ["蒸し", "蒸米", rice.steamed]
27
+ end
28
+ puts table
@@ -0,0 +1,65 @@
1
+ require 'toji'
2
+ require 'terminal-table'
3
+
4
+ recipe = Toji::Recipe::ThreeStepMashing.new(Toji::Ingredient::Yeast::RedStar, 2000)
5
+
6
+ table = Terminal::Table.new do |t|
7
+ t << [""] + recipe.class::STEP_NAMES
8
+ t << :separator
9
+ t << ["[原料]"]
10
+ t << ["酵母(g)", recipe.yeast.yeast]
11
+ t << ["酵母吸水", recipe.yeast.water]
12
+ t << ["乳酸(ml)"]
13
+ t << ["掛米(g)"] + recipe.steps.map(&:rice).map(&:raw)
14
+ t << ["麹米(g)"] + recipe.steps.map(&:koji).map(&:raw)
15
+ t << ["汲水(ml)"] + recipe.steps.map(&:water)
16
+ t << :separator
17
+ t << ["[合計]"]
18
+ t << ["総米(g)"] + recipe.steps.map(&:rice_total)
19
+ t << ["麹歩合(%)"] + recipe.steps.map{|s| s.koji_rate * 100}
20
+ t << ["汲水歩合(%)"] + recipe.steps.map{|s| s.water_rate * 100}
21
+ t << :separator
22
+ t << ["[累計]"]
23
+ t << ["総米(g)"] + recipe.cumulative_rice_totals
24
+ t << ["白米比率"] + recipe.rice_rates
25
+ t << ["酒母歩合(%)"] + recipe.cumulative_shubo_rates.map{|s| s * 100}
26
+ t << ["タンク内容量(ml)"] + recipe.cumulative_weight_totals
27
+ end
28
+ puts table
29
+ puts
30
+
31
+
32
+ puts "掛米"
33
+ table = Terminal::Table.new do |t|
34
+ t << ["工程", "原料"] + recipe.class::STEP_NAMES
35
+ t << :separator
36
+ t << ["洗米・浸漬", "白米(g)"] + recipe.steps.map(&:rice).map(&:raw)
37
+ t << ["", "吸水増加量(ml)"] + recipe.steps.map(&:rice).map(&:soaking_water)
38
+ t << :separator
39
+ t << ["水切り", "浸漬米(g)"] + recipe.steps.map(&:rice).map(&:soaked)
40
+ t << ["", "汲水(ml)"] + recipe.steps.map(&:rice).map(&:steaming_water)
41
+ t << :separator
42
+ t << ["蒸し", "蒸米(g)"] + recipe.steps.map(&:rice).map(&:steamed)
43
+ end
44
+ puts table
45
+ puts
46
+
47
+ puts "麹"
48
+ table = Terminal::Table.new do |t|
49
+ t << ["工程", "原料"] + recipe.class::STEP_NAMES
50
+ t << :separator
51
+ t << ["洗米・浸漬", "白米(g)"] + recipe.steps.map(&:koji).map(&:raw)
52
+ t << ["", "吸水増加量(ml)"] + recipe.steps.map(&:koji).map(&:soaking_water)
53
+ t << :separator
54
+ t << ["水切り", "浸漬米(g)"] + recipe.steps.map(&:koji).map(&:soaked)
55
+ t << ["", "汲水(ml)"] + recipe.steps.map(&:koji).map(&:steaming_water)
56
+ t << :separator
57
+ t << ["蒸し", "蒸米(g)"] + recipe.steps.map(&:koji).map(&:steamed)
58
+ t << :separator
59
+ t << ["放冷・引込み", "蒸米(g)"] + recipe.steps.map(&:koji).map(&:cooled)
60
+ t << ["", "種麹(g)"] + recipe.steps.map(&:koji).map(&:tanekoji)
61
+ t << :separator
62
+ t << ["製麹", "麹(g)"] + recipe.steps.map(&:koji).map(&:dekoji)
63
+ end
64
+ puts table
65
+ puts
data/lib/toji.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "toji/version"
2
+ require 'active_support/all'
3
+
4
+ require 'toji/ingredient'
5
+ require 'toji/recipe'
6
+ require 'toji/progress'
7
+ require 'toji/graph'
8
+
9
+ module Toji
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+ end
data/lib/toji/graph.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'toji/graph/ab'
2
+
3
+ module Toji
4
+ module Graph
5
+ end
6
+ end
@@ -0,0 +1,75 @@
1
+ module Toji
2
+ module Graph
3
+ class Ab
4
+ attr_reader :coef
5
+
6
+ def initialize(coef=1.5)
7
+ @coef = coef
8
+ @actuals = []
9
+ @expects = []
10
+ end
11
+
12
+ def actual(jobs, name=:actual)
13
+ data = jobs.map{|j| [j.time || j.elapsed_time + jobs.day_offset, j.alcohol, j.baume]}.select{|a| a[1] && a[2]}
14
+ xs = data.map{|a| a[1]}
15
+ ys = data.map{|a| a[2]}
16
+ texts = data.map{|a| "%s<br />alc=%s, be=%s" % a}
17
+ @actuals << {x: xs, y: ys, text: texts, name: name}
18
+
19
+ self
20
+ end
21
+
22
+ def expect(alcohol, nihonshudo)
23
+ @expects << [alcohol.to_f, nihonshudo.to_f]
24
+
25
+ self
26
+ end
27
+
28
+ def data
29
+ result = []
30
+
31
+ @actuals.each {|a|
32
+ result << a
33
+ }
34
+
35
+ @expects.each {|alcohol, nihonshudo|
36
+ ys = [0.0, 8.0]
37
+ xs = ys.map{|b| alcohol - (b - nihonshudo * -0.1) * @coef}
38
+
39
+ name = "%s%s %s" % [nihonshudo<0 ? "" : "+", nihonshudo, alcohol]
40
+
41
+ result << {x: xs, y: ys, name: name}
42
+ }
43
+
44
+ result
45
+ end
46
+
47
+ def plot
48
+ d = data
49
+
50
+ #min_baume = d.map{|h| h[:y].min}.min || 0
51
+ #min_baume = [min_baume-1, 0].min
52
+ min_baume = 0
53
+
54
+ max_baume = d.map{|h| h[:y].max}.max || 0
55
+ max_baume = [max_baume+1, 10].max
56
+
57
+ Plotly::Plot.new(
58
+ data: d,
59
+ layout: {
60
+ xaxis: {
61
+ title: "Alcohol",
62
+ dtick: 2,
63
+ range: [0, 20],
64
+ },
65
+ yaxis: {
66
+ title: "Baume",
67
+ dtick: 1,
68
+ range: [min_baume, max_baume],
69
+ }
70
+ }
71
+ )
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,8 @@
1
+ require 'toji/ingredient/rice'
2
+ require 'toji/ingredient/koji'
3
+ require 'toji/ingredient/yeast'
4
+
5
+ module Toji
6
+ module Ingredient
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ require 'toji/ingredient/koji/base'
2
+ require 'toji/ingredient/koji/expected_fermentable'
3
+ require 'toji/ingredient/koji/expected'
4
+ require 'toji/ingredient/koji/actual_fermentable'
5
+ require 'toji/ingredient/koji/actual'
6
+
7
+ module Toji
8
+ module Ingredient
9
+ module Koji
10
+ def self.expected(raw, rice_rate: Recipe::RiceRate::Cooked::DEFAULT, koji_rate: Recipe::KojiRate::DEFAULT)
11
+ Expected.new(raw, rice_rate: rice_rate, koji_rate: koji_rate)
12
+ end
13
+
14
+ def self.actual(raw, soaked, steaming_water, steamed, cooled, tanekoji, dekoji)
15
+ Actual.new(raw, soaked, steaming_water, steamed, cooled, tanekoji, dekoji)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Toji
2
+ module Ingredient
3
+ module Koji
4
+ class Actual
5
+ include Base
6
+ include Rice::ActualSteamable
7
+ include ActualFermentable
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
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Toji
2
+ module Ingredient
3
+ module Koji
4
+ module ActualFermentable
5
+ def tanekoji_rate
6
+ tanekoji / raw
7
+ end
8
+
9
+ def dekoji_rate
10
+ (dekoji - raw) / raw
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end