sauna_planner 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 38744e7bf556c2a02a6715dd077ac49d52e50732dc689aaeb2091e6e945284b3
4
+ data.tar.gz: cb8ad39966c4177d20d7ce64e7a59393e0f55e788017c6215fc86b4d54d9f5cc
5
+ SHA512:
6
+ metadata.gz: 88493044e349950c54e26a33fe29325107a14ffa0fe2941b3aff985801907f8d5bc03fad8f53e4635ab63427edb4d40c062f4ea564cd269bb4179fd1950bb46d
7
+ data.tar.gz: 864456c7447503b6fef899ac0f8847e5e43873bde8c50c222e01c2e4ba45d121b606b961aa26757109e8d7390ae2fdd2463da498dbe4414e97709441148d44b6
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (2026-12-01)
4
+
5
+ - First release: `SaunaPlanner::Heater.calc` (port of `heater.js` from the DIVELUX Sauna Heater Size Calculator),
6
+ `SaunaPlanner::Planner.plan`, `ladder`, `convert_temp` (port of `sauna-planner-core` 1.0.0), and the
7
+ `sauna-planner` command.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DIVELUX Inc.
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # sauna_planner
2
+
3
+ How big a heater does a sauna room need, and how should a session be laid out? This gem answers both in plain Ruby:
4
+
5
+ - **Heater size.** From the room's inside size, the glass and stone that have no insulation behind them, and whether the walls are bare log, it gives a power range in kW for an electric heater, or the room volume to shop by for a wood-burning stove.
6
+ - **Session plan.** From the kind of sauna, the thermometer reading, your experience and the time you have, it lays out rounds, breaks, a final cool-down, a bench and how much water to plan for.
7
+
8
+ It is a Ruby port of the free sauna heater calculator and session planner made by DIVELUX, a small family brand in Irvine, California that makes handmade wool sauna hats. The browser versions of both tools are on [diveluxsaunahat.com](https://diveluxsaunahat.com/pages/sauna-tools). Same constants, same rounding, same messages: the test suite checks the Ruby answers against the JavaScript originals byte for byte.
9
+
10
+ No dependencies. Ruby 2.7 or newer.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ gem install sauna_planner
16
+ ```
17
+
18
+ ## Command line
19
+
20
+ ```sh
21
+ sauna-planner size 6 5 7 --glass 12
22
+ ```
23
+
24
+ ```
25
+ Room 6 ft x 5 ft x 7 ft, electric heater
26
+
27
+ Electric heater: 5.1 to 7.3 kW
28
+
29
+ Room volume 210 cu ft (6.0 m³)
30
+ Glass and stone 12 sq ft, counts as 47 cu ft more
31
+ Log walls no multiplier
32
+ Calculated volume 257 cu ft (7.3 m³)
33
+ ...
34
+ ```
35
+
36
+ More examples:
37
+
38
+ ```sh
39
+ # meters, bare log walls, machine-readable output
40
+ sauna-planner size 2.5 2 2.1 --unit m --log --json
41
+
42
+ # wood-burning stove: volume, not kW
43
+ sauna-planner size 7 6 7 --glass 14 --stone 20 --wood
44
+
45
+ # a session plan: Finnish sauna with löyly, 80 °C, regular bather, 90 minutes
46
+ sauna-planner plan --type loyly --temp 80 --unit c --level regular --time 90
47
+ ```
48
+
49
+ `sauna-planner --help` lists every option. Out-of-range or impossible room sizes are refused with a message and exit code 1; unknown options exit with 2.
50
+
51
+ ## Library
52
+
53
+ ```ruby
54
+ require "sauna_planner"
55
+
56
+ r = SaunaPlanner::Heater.calc(length: 2.5, width: 2, height: 2, glass: 1.6) # meters and m²
57
+ r[:calcVolumeM3] # => 11.9
58
+ r[:kw] # => {:low=>8.4, :high=>11.9}
59
+ r[:byRule] # => {:harvia=>11.9, :huum=>11.6, :huumNA=>12.4}
60
+
61
+ SaunaPlanner::Heater.calc(length: 2, width: 9, height: 2)
62
+ # => {:ok=>false, :errors=>{:width=>"Check the width: this tool covers rooms from 3 ft to 19 ft 8 in (0.9 to 6 m) a side."}}
63
+
64
+ # feet and square feet
65
+ ft = SaunaPlanner::Heater
66
+ ft.calc(length: ft.ft_in_to_m(6), width: ft.ft_in_to_m(5), height: ft.ft_in_to_m(7), glass: ft.sqft_to_m2(12))
67
+
68
+ p = SaunaPlanner::Planner.plan(type: "dry", level: "new", unit: "f", temp: 175, total: 60)
69
+ p[:rounds] # => 2
70
+ p[:roundMin] # => 8
71
+ p[:segments].first # => {:kind=>"heat", :index=>1, :min=>8, :start=>0, :label=>"Round 1"}
72
+ p[:water] # => {:before=>1, :between=>1, :after=>2, :glasses=>4, :oz=>32, :ml=>960, :liters=>1.0}
73
+
74
+ SaunaPlanner::Planner.ladder(type: "loyly", unit: "c", temp: 80) # temperature by bench height (illustration)
75
+ SaunaPlanner.to_json(p) # the same JSON the JavaScript planner returns
76
+ ```
77
+
78
+ Inputs accept symbol or string keys, and numbers as Integer, Float or text (`"2,5"` works). Result hashes use the same keys as the JavaScript tools, so `SaunaPlanner.to_json` gives exactly their JSON.
79
+
80
+ Plan options: `type` is `dry`, `loyly`, `banya`, `steam` or `infrared` (default `dry`); `level` is `new`, `regular` or `seasoned` (default `new`, the most cautious); `unit` is `f` or `c`; `temp` is clamped to the usual range for the type; `total` is the minutes available, 15 to 180 (default 60).
81
+
82
+ ## Where the numbers come from
83
+
84
+ Heater sizing uses the heater makers' own published guidance. Nothing is measured or invented here.
85
+
86
+ 1. **1 kW per cubic meter.** Harvia and HUUM both size an electric heater at an average of 1 kW for each m³ of calculated room volume. This is the top of the range.
87
+ 2. **Cold surfaces add volume.** Each m² of glass, stone, tile or brick without insulation behind it counts as 1.2 m³ of extra room (Harvia). HUUM uses 1 m³ per m², and a North American HUUM sheet uses 4.92 cu ft per sq ft (1.5 m³ per m²). The result uses Harvia's 1.2; `byRule` shows all three.
88
+ 3. **Log walls: volume x 1.5** (Harvia). HUUM counts log walls by area instead, so no HUUM figure is guessed for a log room.
89
+ 4. **The low end: 1 kW per 50 cu ft.** Harvia's own worked example sizes a room of about 8.5 m³ at a minimum of 6 kW, the same ratio as the 1 kW per 50 cu ft shortcut North American retailers quote.
90
+ 5. **Wood stoves** are sold by the room volume they suit, so for `heater: "wood"` you get the calculated volume to compare with the stove's rated range.
91
+
92
+ A calculator cannot see your room. Confirm the size with the heater manufacturer, and have a licensed electrician check the circuit before you buy.
93
+
94
+ The session plan follows conservative, commonly repeated sauna conventions: shorter rounds when the room is hotter or steamier, breaks at least as long as the round (10 to 20 minutes), two to three rounds for most people, and one glass of water before, one in each break and two to four after. These are planning numbers for healthy adults, not medical advice. Step out whenever you feel dizzy, sick or faint.
95
+
96
+ ## Tested against the originals
97
+
98
+ `rake test` (or `ruby -Ilib -Itest -e 'Dir["test/test_*.rb"].each { |f| require_relative f }'`) runs:
99
+
100
+ - the makers' worked examples (Harvia's 10 m³ room with a glass door, Harvia's wood-stove example, HUUM's glass-wall example, Harvia's 8.5 m³ room at 6 kW, a 6 x 5 x 7 ft room at 210 cu ft and 4.2 kW);
101
+ - 69,696 rooms from the web calculator's test grid plus refused input, compared as JSON, byte for byte, with the original `heater.js`;
102
+ - all 42,534 inputs of the planner's test grid plus defaults and clamping, byte for byte against the original `plan()` from `sauna-planner-core` 1.0.0, and every heat ladder and unit conversion;
103
+ - 1,422 command lines against `sauna-heater-calc`, the WebAssembly build of the same tools.
104
+
105
+ The reference answers in `test/fixtures` are written by `node test/reference/make_fixtures.js` from byte-for-byte copies of the JavaScript originals kept in `test/reference`.
106
+
107
+ ## How it was made
108
+
109
+ The port, the tests and this README were written with Claude, an AI assistant by Anthropic, working for DIVELUX. The sizing rules and planning conventions come from the original DIVELUX tools and the manufacturers' published guidance cited above; the test suite checks that the port gives the same numbers as the originals.
110
+
111
+ ## License
112
+
113
+ MIT, © 2026 DIVELUX Inc.
data/exe/sauna-planner ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "sauna_planner/cli"
5
+
6
+ exit SaunaPlanner::CLI.start(ARGV)
@@ -0,0 +1,329 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../sauna_planner"
4
+
5
+ module SaunaPlanner
6
+ # Command line: `sauna-planner size ...` and `sauna-planner plan ...`.
7
+ # Same options and the same text as sauna-heater-calc, the WebAssembly build
8
+ # of these tools on wasmer.io.
9
+ class CLI
10
+ PROG = "sauna-planner"
11
+ VALUE_KEYS = %w[unit length width height glass stone type temp level time heater].freeze
12
+ FLAG_KEYS = %w[log wood json help version metric].freeze
13
+
14
+ def self.start(argv = ARGV, out: $stdout, err: $stderr)
15
+ new(out, err).run(argv)
16
+ end
17
+
18
+ def initialize(out, err)
19
+ @out = out
20
+ @err = err
21
+ end
22
+
23
+ def run(argv)
24
+ a = parse(argv)
25
+ return usage_error("#{a[:bad]} Run with --help.") if a[:bad]
26
+ return say(VERSION) if a[:flags].include?("version")
27
+ return say(help) if a[:flags].include?("help") || a[:command] == "help"
28
+ return plan_command(a) if a[:command] == "plan"
29
+ if a[:command] == "size" || !a[:positional].empty? || !a[:keys].empty? || (a[:flags] & %w[log wood]).any?
30
+ return size_command(a)
31
+ end
32
+
33
+ say(help)
34
+ end
35
+
36
+ private
37
+
38
+ def say(text)
39
+ @out.puts(text)
40
+ 0
41
+ end
42
+
43
+ def usage_error(text)
44
+ @err.puts(text)
45
+ 2
46
+ end
47
+
48
+ # ---------- numbers ----------
49
+
50
+ # Like toLocaleString('en-US') with a fixed number of decimals; loose drops trailing zeros.
51
+ def fmt(n, digits, loose = false)
52
+ p = 10**digits
53
+ scaled = JS.round(n.abs * p).to_i
54
+ whole = scaled / p
55
+ frac = digits.positive? ? (scaled % p).to_s.rjust(digits, "0") : ""
56
+ frac = frac.sub(/0+\z/, "") if loose
57
+ w = whole.to_s.reverse.scan(/\d{1,3}/).join(",").reverse
58
+ (n.negative? && scaled != 0 ? "-" : "") + w + (frac.empty? ? "" : ".#{frac}")
59
+ end
60
+
61
+ # Strict decimal: "2.5", "2,5", ".5", "+3". Anything else is NaN.
62
+ def parse_num(s)
63
+ t = s.strip.sub(",", ".")
64
+ return Float::NAN if t.empty?
65
+ return Float::NAN unless t.match?(/\A[+-]?[0-9.]*\z/) && t.match?(/[0-9]/) && t.count(".") <= 1
66
+
67
+ JS.parse_float(t)
68
+ end
69
+
70
+ # ---------- arguments ----------
71
+
72
+ def parse(argv)
73
+ a = { command: "", positional: [], keys: [], values: [], flags: [], bad: nil }
74
+ i = 0
75
+ while i < argv.length
76
+ s = argv[i].to_s
77
+ i += 1
78
+ s = "--help" if s == "-h"
79
+ s = "--version" if %w[-v -V].include?(s)
80
+ if s.start_with?("--")
81
+ key = s[2..]
82
+ value = nil
83
+ if (eq = key.index("="))
84
+ value = key[(eq + 1)..]
85
+ key = key[0, eq]
86
+ end
87
+ if FLAG_KEYS.include?(key)
88
+ a[:flags] << key
89
+ next
90
+ end
91
+ unless VALUE_KEYS.include?(key)
92
+ a[:bad] = "Unknown option --#{key}."
93
+ return a
94
+ end
95
+ if value.nil?
96
+ if i >= argv.length
97
+ a[:bad] = "Option --#{key} needs a value."
98
+ return a
99
+ end
100
+ value = argv[i].to_s
101
+ i += 1
102
+ end
103
+ a[:keys] << key
104
+ a[:values] << value
105
+ elsif a[:command] == "" && a[:positional].empty? && %w[size plan help].include?(s)
106
+ a[:command] = s
107
+ else
108
+ a[:positional] << s
109
+ end
110
+ end
111
+ a
112
+ end
113
+
114
+ def get(a, key)
115
+ idx = a[:keys].rindex(key)
116
+ idx && a[:values][idx]
117
+ end
118
+
119
+ # ---------- size ----------
120
+
121
+ def size_command(a)
122
+ unit = a[:flags].include?("metric") ? "m" : "ft"
123
+ if (u = get(a, "unit"))
124
+ case u.downcase
125
+ when "m", "meters", "metric" then unit = "m"
126
+ when "ft", "feet", "imperial" then unit = "ft"
127
+ else return usage_error("--unit is ft or m.")
128
+ end
129
+ end
130
+ ft = unit == "ft"
131
+ if a[:positional].length > 3
132
+ return usage_error("Give the room as LENGTH WIDTH HEIGHT. Run with --help for examples.")
133
+ end
134
+
135
+ pick = ->(pos, key) { get(a, key) || a[:positional][pos] }
136
+ ls = pick.call(0, "length")
137
+ ws = pick.call(1, "width")
138
+ hs = pick.call(2, "height")
139
+ to_len = lambda do |s|
140
+ next Float::NAN if s.nil?
141
+
142
+ v = parse_num(s)
143
+ ft ? v * Heater::M_PER_FT : v
144
+ end
145
+ to_area = lambda do |s|
146
+ next 0.0 if s.nil? || s.strip.empty?
147
+
148
+ v = parse_num(s)
149
+ ft ? v / Heater::SQFT_PER_M2 : v
150
+ end
151
+ heater = get(a, "heater")
152
+ wood = a[:flags].include?("wood") || (!heater.nil? && heater.downcase == "wood")
153
+ r = Heater.calc(length: to_len.call(ls), width: to_len.call(ws), height: to_len.call(hs),
154
+ glass: to_area.call(get(a, "glass")), masonry: to_area.call(get(a, "stone")),
155
+ log: a[:flags].include?("log"), heater: wood ? "wood" : "electric")
156
+ if a[:flags].include?("json")
157
+ @out.puts(JS.json(r))
158
+ return r[:ok] ? 0 : 1
159
+ end
160
+ unless r[:ok]
161
+ r[:errors].each do |field, message|
162
+ opt = { masonry: "--stone", glass: "--glass" }[field] || "--#{field}"
163
+ @err.puts("#{opt}: #{message}")
164
+ end
165
+ if ls.nil? || ws.nil? || hs.nil?
166
+ @err.puts("Example: #{PROG} size 6 5 7 --glass 12 (feet; add --unit m for meters)")
167
+ end
168
+ return 1
169
+ end
170
+ say(heater_text(r, ft))
171
+ end
172
+
173
+ def both(m3, cuft, ft)
174
+ ft ? "#{fmt(cuft, 0)} cu ft (#{fmt(m3, 1)} m³)" : "#{fmt(m3, 1)} m³ (#{fmt(cuft, 0)} cu ft)"
175
+ end
176
+
177
+ def heater_text(r, ft)
178
+ inp = r[:input]
179
+ has_kw = !r[:kw].nil?
180
+ has_huum = !inp[:log]
181
+ side = ->(m) { ft ? "#{fmt(m / 0.3048, 2, true)} ft" : "#{fmt(m, 2, true)} m" }
182
+ l = []
183
+ l << "Room #{side[inp[:length]]} x #{side[inp[:width]]} x #{side[inp[:height]]}" \
184
+ "#{inp[:log] ? ', log walls' : ''}#{inp[:heater] == 'wood' ? ', wood-burning stove' : ', electric heater'}"
185
+ l << ""
186
+ if has_kw
187
+ l << " Electric heater: #{fmt(r[:kw][:low], 1)} to #{fmt(r[:kw][:high], 1)} kW"
188
+ else
189
+ l << " Wood-burning stove: one rated for #{ft ? "#{fmt(r[:calcVolumeCuFt], 0)} cu ft" : "#{fmt(r[:calcVolumeM3], 1)} m³"}"
190
+ end
191
+ l << ""
192
+ l << " Room volume #{both(r[:volumeM3], r[:volumeCuFt], ft)}"
193
+ surface = ft ? "#{fmt(r[:surfaceSqFt], 1, true)} sq ft" : "#{fmt(r[:surfaceM2], 2, true)} m²"
194
+ extra = ft ? "#{fmt(r[:extraCuFt], 0)} cu ft" : "#{fmt(r[:extraM3], 1)} m³"
195
+ l << " Glass and stone #{surface}#{r[:surfaceM2].positive? ? ", counts as #{extra} more" : ', nothing to add'}"
196
+ l << " Log walls #{inp[:log] ? 'x 1.5, room volume multiplied' : 'no multiplier'}"
197
+ l << " Calculated volume #{both(r[:calcVolumeM3], r[:calcVolumeCuFt], ft)}"
198
+ l << ""
199
+ if has_kw
200
+ l << " #{fmt(r[:kw][:high], 1)} kW is the average rule: 1 kW per m³ of calculated volume (Harvia, HUUM)."
201
+ l << " #{fmt(r[:kw][:low], 1)} kW is the low end: 1 kW per 50 cu ft, where Harvia's own worked example lands."
202
+ l << " Pick a model whose rated room range has your calculated volume near the middle."
203
+ else
204
+ l << " Wood stoves are sold by the room volume they suit, not by kilowatts."
205
+ l << " Look for one whose rated range includes #{both(r[:calcVolumeM3], r[:calcVolumeCuFt], ft)}, ideally near the middle."
206
+ end
207
+ l << ""
208
+ l << " The same room under each maker's rule for cold surfaces:"
209
+ per = lambda do |k|
210
+ ft ? "#{fmt(k * Heater::CUFT_PER_M3 / Heater::SQFT_PER_M2, 2)} cu ft per sq ft" : "#{fmt(k, 1)} m³ per m²"
211
+ end
212
+ vol = lambda do |key|
213
+ m3 = r[:byRule][key]
214
+ cuft = r[:byRuleCuFt][key]
215
+ (ft ? "#{fmt(cuft, 0)} cu ft" : "#{fmt(m3, 1)} m³") + (has_kw ? ", #{fmt(m3, 1)} kW at 1 kW per m³" : "")
216
+ end
217
+ s = Heater::SURFACE_M3_PER_M2
218
+ l << " Harvia (#{per[s[:harvia]]}#{inp[:log] ? ', log walls x 1.5' : ''}): #{vol[:harvia]}"
219
+ l << " HUUM (#{per[s[:huum]]}): #{has_huum ? vol[:huum] : 'ask the maker'}"
220
+ l << " HUUM, North American sheet (#{per[s[:huumNA]]}): #{has_huum ? vol[:huumNA] : 'ask the maker'}"
221
+ r[:notes].each_with_index do |n, i|
222
+ l << "" if i.zero?
223
+ l << " Note: #{n}"
224
+ end
225
+ l << ""
226
+ l << " A calculator cannot see your room. Confirm the size with the heater manufacturer"
227
+ l << " and have a licensed electrician check the circuit."
228
+ l.join("\n")
229
+ end
230
+
231
+ # ---------- plan ----------
232
+
233
+ def plan_command(a)
234
+ inp = {}
235
+ if (t = get(a, "type"))
236
+ return usage_error("--type is one of: dry, loyly, banya, steam, infrared.") unless Planner::TYPES.key?(t.downcase)
237
+
238
+ inp[:type] = t.downcase
239
+ elsif a[:positional].any? && Planner::TYPES.key?(a[:positional][0].downcase)
240
+ inp[:type] = a[:positional][0].downcase
241
+ end
242
+ if (lv = get(a, "level"))
243
+ return usage_error("--level is one of: new, regular, seasoned.") unless Planner::LEVELS.key?(lv.downcase)
244
+
245
+ inp[:level] = lv.downcase
246
+ end
247
+ if (u = get(a, "unit"))
248
+ return usage_error("--unit is f or c for a plan.") unless %w[f c].include?(u.downcase)
249
+
250
+ inp[:unit] = u.downcase
251
+ end
252
+ if (tp = get(a, "temp"))
253
+ inp[:temp] = parse_num(tp)
254
+ return usage_error("--temp is a number.") if inp[:temp].nan?
255
+ end
256
+ if (tm = get(a, "time"))
257
+ inp[:total] = parse_num(tm)
258
+ return usage_error("--time is minutes, a number.") if inp[:total].nan?
259
+ end
260
+ p = Planner.plan(inp)
261
+ return say(JS.json(p)) if a[:flags].include?("json")
262
+
263
+ say(plan_text(p))
264
+ end
265
+
266
+ def plan_text(p)
267
+ o = p[:input]
268
+ level = { "new" => "new to sauna", "regular" => "regular" }.fetch(o[:level], "seasoned")
269
+ l = []
270
+ l << "#{Planner::TYPES[o[:type]][:label]}, #{o[:temp]}#{o[:unit] == 'c' ? ' °C' : ' °F'}, #{level}, #{o[:total]} minutes available"
271
+ l << ""
272
+ l << " #{p[:rounds]}#{p[:rounds] == 1 ? ' round' : ' rounds'} of #{p[:roundMin]} min" \
273
+ "#{p[:rounds] > 1 ? ", #{p[:restMin]} min break between rounds" : ''}, #{p[:coolMin]} min final cool-down"
274
+ l << ""
275
+ p[:segments].each do |s|
276
+ l << " #{"#{s[:start]}-#{s[:start] + s[:min]} min".ljust(14)}#{s[:label]}#{s[:kind] == 'heat' ? ' (in the heat)' : ''}"
277
+ end
278
+ l << ""
279
+ l << " Uses #{p[:usedMin]} of #{o[:total]} minutes#{p[:spareMin].positive? ? ", #{p[:spareMin]} to spare" : ''}."
280
+ l << " Bench: #{p[:bench] == 'either' ? 'lower or upper, as it feels' : p[:bench]}." if p[:bench]
281
+ w = p[:water]
282
+ l << " Water: #{w[:glasses]} glasses of 8 fl oz (#{w[:ml]} ml): #{w[:before]} before, " \
283
+ "#{w[:between].positive? ? "#{w[:between]} in the breaks, " : ''}#{w[:after]} after."
284
+ p[:notes].each { |n| l << " Note: #{n}" }
285
+ l << ""
286
+ l << " Planning numbers from common sauna conventions for healthy adults, not medical advice."
287
+ l << " Step out whenever you feel dizzy, sick or faint."
288
+ l.join("\n")
289
+ end
290
+
291
+ # ---------- help ----------
292
+
293
+ def help
294
+ <<~HELP.chomp
295
+ #{PROG} #{VERSION}: sauna heater size by room volume, and a simple session plan.
296
+
297
+ USAGE
298
+ #{PROG} size LENGTH WIDTH HEIGHT [--glass AREA] [--stone AREA] [--log] [--wood] [--unit ft|m] [--json]
299
+ #{PROG} plan [--type TYPE] [--temp N] [--unit f|c] [--level LEVEL] [--time MINUTES] [--json]
300
+
301
+ SIZE
302
+ Inside length, width and ceiling height of the hot room. Feet by default (6.5 = 6 ft 6 in),
303
+ or meters with --unit m. Also accepted as --length, --width, --height.
304
+ --glass area of glass with no insulation behind it (sq ft, or m² with --unit m)
305
+ --stone area of uninsulated stone, tile or brick
306
+ --log bare log walls (room volume x 1.5)
307
+ --wood wood-burning stove: prints the room volume to shop by instead of kW
308
+ Rules: 1 kW per m³ of calculated volume (Harvia, HUUM) down to 1 kW per 50 cu ft;
309
+ each m² of glass or stone adds 1.2 m³ (Harvia). HUUM's figures are shown next to it.
310
+
311
+ PLAN
312
+ --type #{Planner::TYPES.keys.join(', ')} (default dry)
313
+ --temp thermometer reading; clamped to the usual range for the type
314
+ --unit f or c (default f)
315
+ --level new, regular or seasoned (default new, the most cautious)
316
+ --time minutes available, door to door, 15 to 180 (default 60)
317
+
318
+ EXAMPLES
319
+ #{PROG} size 6 5 7 --glass 12
320
+ #{PROG} size 2.5 2 2.1 --unit m --log --json
321
+ #{PROG} plan --type loyly --temp 80 --unit c --level regular --time 90
322
+
323
+ Confirm heater size with the manufacturer and a licensed electrician.
324
+ Session plans are planning numbers, not medical advice.
325
+ Same rules as the free DIVELUX sauna tools: https://diveluxsaunahat.com/pages/sauna-tools
326
+ HELP
327
+ end
328
+ end
329
+ end
@@ -0,0 +1,186 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SaunaPlanner
4
+ # Sauna heater size from room volume: a Ruby port of heater.js, the sizing
5
+ # logic of the free DIVELUX Sauna Heater Size Calculator
6
+ # (https://diveluxsaunahat.com/pages/sauna-tools). Same constants, same rules,
7
+ # same rounding, same messages.
8
+ #
9
+ # Where the numbers come from (every figure is a heater maker's own published
10
+ # sizing guidance; nothing here is measured or invented):
11
+ #
12
+ # 1. Power per volume: an average of 1 kW of heater power for each cubic
13
+ # meter of sauna volume (Harvia; HUUM says the same).
14
+ # 2. Uninsulated surfaces: each m² of stone, glass or similar surface counts
15
+ # like 1.2 m³ of extra room volume (Harvia). HUUM uses 1 m³ per m²; a
16
+ # North American HUUM sheet uses 4.92 cu ft per sq ft (1.5 m³ per m²).
17
+ # The result uses Harvia's 1.2 and shows the other two next to it.
18
+ # 3. Log walls: multiply the room volume by 1.5 (Harvia).
19
+ # 4. Low end of the power range: Harvia's worked example sizes a room of about
20
+ # 8.5 m³ at a minimum of 6 kW, the same ratio as the retail shortcut of
21
+ # 1 kW per 50 cu ft. So low = calculated volume / 1.416, high = volume x 1.
22
+ # 5. Wood-burning stoves are sold by the room volume they suit, so for a wood
23
+ # stove only the calculated volume is returned.
24
+ #
25
+ # A calculator cannot see your room. Always confirm the size with the heater
26
+ # manufacturer and have a licensed electrician check the circuit.
27
+ module Heater
28
+ M_PER_FT = 0.3048
29
+ CUFT_PER_M3 = 35.3147
30
+ SQFT_PER_M2 = 10.7639
31
+
32
+ KW_PER_M3 = 1 # Harvia, HUUM: 1 m³ = 1 kW
33
+ CUFT_PER_KW_LOOSE = 50 # retail shortcut; equals Harvia's 8.5 m³ -> min 6 kW example
34
+ LOG_FACTOR = 1.5 # Harvia: log walls, multiply the volume by 1.5
35
+ SURFACE_M3_PER_M2 = { harvia: 1.2, huum: 1.0, huumNA: 1.5 }.freeze
36
+
37
+ # Accepted input, in meters. Outside this the tool asks you to check the number.
38
+ LIMITS = {
39
+ side: { min: 0.9, max: 6 }, # length and width: 3 ft to about 19 ft 8 in
40
+ height: { min: 1.7, max: 3 }, # 5 ft 7 in to 9 ft 10 in
41
+ area: { min: 0, max: 40 } # m² of glass or masonry
42
+ }.freeze
43
+ DEFAULTS = {
44
+ unit: "ft", length: 1.8288, width: 1.524, height: 2.1336, # 6 ft x 5 ft x 7 ft
45
+ glass: 1.1148, # 12 sq ft: a 2 ft x 6 ft glass door
46
+ masonry: 0, log: false, heater: "electric"
47
+ }.freeze
48
+
49
+ module_function
50
+
51
+ # A number from a Float, Integer or text ("2.5", "2,5"); NaN when there is none.
52
+ def num(v)
53
+ n = v.is_a?(Numeric) ? v.to_f : JS.parse_float(v.nil? ? "" : v.to_s.sub(",", "."))
54
+ n.finite? ? n : Float::NAN
55
+ end
56
+
57
+ # Rounded like the JavaScript original: Math.round(v * 10^digits) / 10^digits.
58
+ def round(v, digits = 0)
59
+ p = 10.0**digits
60
+ JS.round(v * p) / p
61
+ end
62
+
63
+ def ft_in_to_m(ft, inches = 0)
64
+ f = num(ft)
65
+ i = num(inches)
66
+ (f.nan? || f.zero? ? 0 : f) * M_PER_FT + (i.nan? || i.zero? ? 0 : i) * M_PER_FT / 12
67
+ end
68
+
69
+ def m_to_ft_in(m)
70
+ total = JS.round(m / M_PER_FT * 12).to_i # whole inches
71
+ { ft: total / 12, in: total % 12 }
72
+ end
73
+
74
+ def sqft_to_m2(a)
75
+ num(a) / SQFT_PER_M2
76
+ end
77
+
78
+ def m2_to_sqft(a)
79
+ a * SQFT_PER_M2
80
+ end
81
+
82
+ def m3_to_cuft(v)
83
+ v * CUFT_PER_M3
84
+ end
85
+
86
+ # input, all lengths in meters and areas in m² (symbol or string keys):
87
+ # { length:, width:, height:, glass:, masonry:, log: true/false, heater: "electric" | "wood" }
88
+ # Returns { ok: false, errors: { field => message } } or the full result,
89
+ # with the same keys as the JavaScript original.
90
+ def calc(input = nil)
91
+ input ||= {}
92
+ get = ->(k) { input.key?(k) ? input[k] : input[k.to_s] }
93
+ errors = {}
94
+ l = num(get[:length])
95
+ w = num(get[:width])
96
+ h = num(get[:height])
97
+ g = get[:glass]
98
+ glass = g.nil? || g == "" ? 0.0 : num(g)
99
+ m = get[:masonry]
100
+ masonry = m.nil? || m == "" ? 0.0 : num(m)
101
+ log = ![nil, false, 0, "", 0.0].include?(get[:log]) && !(get[:log].is_a?(Float) && get[:log].nan?)
102
+ heater = get[:heater].to_s == "wood" ? "wood" : "electric"
103
+
104
+ side = lambda do |v, key, label|
105
+ if v.nan?
106
+ errors[key] = "Enter the #{label}."
107
+ elsif v < LIMITS[:side][:min] - 1e-9 || v > LIMITS[:side][:max] + 1e-9
108
+ errors[key] = "Check the #{label}: this tool covers rooms from 3 ft to 19 ft 8 in (0.9 to 6 m) a side."
109
+ end
110
+ end
111
+ side.call(l, :length, "length")
112
+ side.call(w, :width, "width")
113
+ if h.nan?
114
+ errors[:height] = "Enter the height."
115
+ elsif h < LIMITS[:height][:min] - 1e-9 || h > LIMITS[:height][:max] + 1e-9
116
+ errors[:height] = "Check the height: this tool covers ceilings from 5 ft 7 in to 9 ft 10 in (1.7 to 3 m)."
117
+ end
118
+ errors[:glass] = "Check the glass area." if glass.nan? || glass.negative? || glass > LIMITS[:area][:max]
119
+ errors[:masonry] = "Check the stone, tile or brick area." if masonry.nan? || masonry.negative? || masonry > LIMITS[:area][:max]
120
+
121
+ if errors.empty?
122
+ # All six faces of the room: nothing can be more uninsulated than that.
123
+ faces = 2 * (l * w + l * h + w * h)
124
+ if glass + masonry > faces + 1e-9
125
+ errors[:glass] = "Glass plus stone is more than the whole surface of this room. Check the areas."
126
+ end
127
+ end
128
+ return { ok: false, errors: errors } unless errors.empty?
129
+
130
+ volume = l * w * h
131
+ surface = glass + masonry
132
+ base = volume * (log ? LOG_FACTOR : 1)
133
+ calc_volume = base + surface * SURFACE_M3_PER_M2[:harvia]
134
+
135
+ # HUUM counts log walls as uninsulated surface by area, not with a factor,
136
+ # so no HUUM figure is guessed for a log room.
137
+ by_rule = {
138
+ harvia: calc_volume,
139
+ huum: log ? nil : volume + surface * SURFACE_M3_PER_M2[:huum],
140
+ huumNA: log ? nil : volume + surface * SURFACE_M3_PER_M2[:huumNA]
141
+ }
142
+
143
+ kw_high = calc_volume * KW_PER_M3
144
+ kw_low = m3_to_cuft(calc_volume) / CUFT_PER_KW_LOOSE
145
+
146
+ notes = []
147
+ if surface.positive? && surface * SURFACE_M3_PER_M2[:harvia] / calc_volume >= 0.3
148
+ share = JS.round(surface * SURFACE_M3_PER_M2[:harvia] / calc_volume * 100)
149
+ notes << "Glass and stone make up #{JS.num_str(share)}% of the calculated volume. " \
150
+ "With this much uninsulated surface, ask the manufacturer before you buy."
151
+ end
152
+ notes << "Bare log walls soak up heat, so the room volume is multiplied by 1.5 (Harvia)." if log
153
+ if h > 2.3 + 1e-9
154
+ notes << "A tall ceiling adds air to heat. Every extra foot of height adds " \
155
+ "#{JS.num_str(round(m3_to_cuft(l * w * M_PER_FT), 0))} cu ft to this room."
156
+ end
157
+
158
+ {
159
+ ok: true,
160
+ input: { length: l, width: w, height: h, glass: glass, masonry: masonry, log: log, heater: heater },
161
+ volumeM3: round(volume, 2),
162
+ volumeCuFt: round(m3_to_cuft(volume), 0).to_i,
163
+ surfaceM2: round(surface, 2),
164
+ surfaceSqFt: round(m2_to_sqft(surface), 1),
165
+ logFactor: log ? LOG_FACTOR : 1,
166
+ extraM3: round(surface * SURFACE_M3_PER_M2[:harvia], 1),
167
+ extraCuFt: round(m3_to_cuft(surface * SURFACE_M3_PER_M2[:harvia]), 0).to_i,
168
+ calcVolumeM3: round(calc_volume, 1),
169
+ calcVolumeCuFt: round(m3_to_cuft(calc_volume), 0).to_i,
170
+ byRule: {
171
+ harvia: round(by_rule[:harvia], 1),
172
+ huum: by_rule[:huum] && round(by_rule[:huum], 1),
173
+ huumNA: by_rule[:huumNA] && round(by_rule[:huumNA], 1)
174
+ },
175
+ byRuleCuFt: {
176
+ harvia: round(m3_to_cuft(by_rule[:harvia]), 0).to_i,
177
+ huum: by_rule[:huum] && round(m3_to_cuft(by_rule[:huum]), 0).to_i,
178
+ huumNA: by_rule[:huumNA] && round(m3_to_cuft(by_rule[:huumNA]), 0).to_i
179
+ },
180
+ # Power is only meaningful for electric heaters; wood stoves are chosen by volume.
181
+ kw: heater == "electric" ? { low: round(kw_low, 1), high: round(kw_high, 1) } : nil,
182
+ notes: notes
183
+ }
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module SaunaPlanner
6
+ # The few JavaScript number rules the original tools depend on, so the Ruby
7
+ # port gives the same answers digit for digit.
8
+ module JS
9
+ module_function
10
+
11
+ # Math.round: nearest integer, halves go up (towards +Infinity). Returns a Float.
12
+ def round(v)
13
+ return v unless v.finite?
14
+
15
+ r = v.floor.to_f
16
+ v - r >= 0.5 ? r + 1 : r
17
+ end
18
+
19
+ # parseFloat(String(v)): the longest leading decimal number, NaN if there is none.
20
+ PARSE_FLOAT = /\A[+-]?(?:Infinity|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/.freeze
21
+ def parse_float(v)
22
+ return v.to_f if v.is_a?(Numeric) && !v.is_a?(Complex)
23
+
24
+ m = PARSE_FLOAT.match(v.to_s.lstrip)
25
+ return Float::NAN unless m
26
+
27
+ s = m[0]
28
+ return (s.start_with?("-") ? -Float::INFINITY : Float::INFINITY) if s.end_with?("Infinity")
29
+
30
+ s.to_f
31
+ end
32
+
33
+ # Number#toString / JSON.stringify of a double.
34
+ def num_str(f)
35
+ return f.to_s if f.is_a?(Integer)
36
+ return "null" unless f.finite?
37
+ return "0" if f.zero?
38
+ return f.to_i.to_s if f == f.truncate && f.abs < 1e21
39
+
40
+ m = /\A(\d+)(?:\.(\d+))?(?:e([+-]?\d+))?\z/.match(f.abs.to_s)
41
+ int = m[1]
42
+ all = int + (m[2] || "")
43
+ lead = all[/\A0*/].length
44
+ digits = all[lead..].sub(/0+\z/, "")
45
+ n = (m[3] || "0").to_i + int.length - lead
46
+ k = digits.length
47
+ s =
48
+ if k <= n && n <= 21 then digits + ("0" * (n - k))
49
+ elsif n.positive? && n <= 21 then "#{digits[0, n]}.#{digits[n..]}"
50
+ elsif n > -6 && n <= 0 then "0.#{'0' * -n}#{digits}"
51
+ else
52
+ e = n - 1
53
+ (k == 1 ? digits : "#{digits[0]}.#{digits[1..]}") + "e#{e.negative? ? '-' : '+'}#{e.abs}"
54
+ end
55
+ f.negative? ? "-#{s}" : s
56
+ end
57
+
58
+ # JSON.stringify for the plain hashes, arrays, strings and numbers these tools return.
59
+ def json(o)
60
+ case o
61
+ when Hash then "{#{o.map { |k, v| "#{JSON.generate(k.to_s)}:#{json(v)}" }.join(',')}}"
62
+ when Array then "[#{o.map { |v| json(v) }.join(',')}]"
63
+ when Numeric then num_str(o)
64
+ when nil then "null"
65
+ when true then "true"
66
+ when false then "false"
67
+ else JSON.generate(o.to_s)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,278 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SaunaPlanner
4
+ # Sauna session plan: a Ruby port of plan() from sauna-planner-core 1.0.0, the
5
+ # planning logic of the free DIVELUX Sauna Session Planner. Same rules, same
6
+ # numbers, same notes.
7
+ #
8
+ # These are conservative, commonly repeated sauna conventions, not research
9
+ # findings and not medical advice:
10
+ #
11
+ # 1. Time per round. A single stay in a hot sauna is usually kept to no more
12
+ # than 15-20 minutes; beginners start at 5-10. So: new 5-10, regular 8-15,
13
+ # seasoned up to 20, never more than 20 in a hot room.
14
+ # 2. Hotter room, shorter round: x1.15 at the low end of the normal range for
15
+ # that kind of sauna, x0.75 at the high end.
16
+ # 3. Löyly, banya steam and steam rooms feel hotter than dry air at the same
17
+ # reading, so their bands sit a little lower than the dry Finnish band.
18
+ # 4. Infrared cabins run much cooler, so sessions are longer and usually a
19
+ # single stay; capped at 35 minutes.
20
+ # 5. Breaks: as long as the round, never under 10 minutes, capped at 20. The
21
+ # session always ends with a cool-down.
22
+ # 6. Rounds: new at most 2, regular 3, seasoned 4.
23
+ # 7. Water: one glass (8 fl oz / ~240 ml) before, one in each break, and two
24
+ # to four afterwards depending on total time in the heat.
25
+ # 8. Heat ladder: a straight-line temperature gradient from floor to ceiling,
26
+ # anchored at the thermometer. An illustration, not a measurement.
27
+ module Planner
28
+ GLASS_OZ = 8
29
+ GLASS_ML = 240
30
+ MIN_TOTAL = 15
31
+ MAX_TOTAL = 180
32
+ COOL_DOWN = 10 # final cool-down, minutes
33
+ COOL_DOWN_MIN = 5 # shortest final cool-down when time is tight
34
+ REST_MIN = 10
35
+ REST_MAX = 20
36
+
37
+ TYPES = {
38
+ "dry" => {
39
+ label: "Finnish, dry",
40
+ hint: "Hot, dry air. Little or no water on the stones.",
41
+ c: { min: 60, max: 100, def: 80 },
42
+ f: { min: 140, max: 210, def: 175 },
43
+ rounds: { "new" => [5, 8, 10], "regular" => [8, 12, 15], "seasoned" => [10, 16, 20] },
44
+ maxRounds: { "new" => 2, "regular" => 3, "seasoned" => 4 },
45
+ gradient: 14,
46
+ benches: true
47
+ },
48
+ "loyly" => {
49
+ label: "Finnish, with löyly",
50
+ hint: "Water on the stones. Each ladle makes the same air feel hotter.",
51
+ c: { min: 65, max: 100, def: 80 },
52
+ f: { min: 150, max: 210, def: 180 },
53
+ rounds: { "new" => [5, 7, 10], "regular" => [8, 11, 15], "seasoned" => [10, 14, 18] },
54
+ maxRounds: { "new" => 2, "regular" => 3, "seasoned" => 4 },
55
+ gradient: 12,
56
+ benches: true
57
+ },
58
+ "banya" => {
59
+ label: "Russian banya",
60
+ hint: "Lower temperature, heavy steam. Feels hotter than the reading.",
61
+ c: { min: 55, max: 90, def: 70 },
62
+ f: { min: 130, max: 195, def: 160 },
63
+ rounds: { "new" => [5, 6, 8], "regular" => [6, 10, 12], "seasoned" => [8, 12, 15] },
64
+ maxRounds: { "new" => 2, "regular" => 3, "seasoned" => 4 },
65
+ gradient: 10,
66
+ benches: true
67
+ },
68
+ "steam" => {
69
+ label: "Steam room / hammam",
70
+ hint: "Warm, fully saturated air. Sweat cannot evaporate, so go easy.",
71
+ c: { min: 38, max: 50, def: 43 },
72
+ f: { min: 100, max: 120, def: 110 },
73
+ rounds: { "new" => [5, 8, 10], "regular" => [8, 12, 15], "seasoned" => [10, 15, 20] },
74
+ maxRounds: { "new" => 2, "regular" => 3, "seasoned" => 3 },
75
+ gradient: 5,
76
+ benches: true
77
+ },
78
+ "infrared" => {
79
+ label: "Infrared",
80
+ hint: "Panels warm you directly. Cooler air, longer single stay.",
81
+ c: { min: 40, max: 65, def: 55 },
82
+ f: { min: 105, max: 150, def: 130 },
83
+ rounds: { "new" => [10, 15, 20], "regular" => [15, 25, 30], "seasoned" => [20, 30, 35] },
84
+ maxRounds: { "new" => 1, "regular" => 1, "seasoned" => 2 },
85
+ gradient: 3,
86
+ benches: false
87
+ }
88
+ }.freeze
89
+
90
+ LEVELS = {
91
+ "new" => { label: "New", hint: "First sessions, or back after a long break" },
92
+ "regular" => { label: "Regular", hint: "A few times a month" },
93
+ "seasoned" => { label: "Seasoned", hint: "Weekly or more, for years" }
94
+ }.freeze
95
+
96
+ # Heights for the heat ladder (meters). Thermometer assumed at head height
97
+ # on the upper bench, which is where most are mounted.
98
+ LADDER_LEVELS = [
99
+ { key: "ceiling", label: "Ceiling", m: 2.1 },
100
+ { key: "upper", label: "Head, upper bench", m: 1.7, thermometer: true },
101
+ { key: "lower", label: "Head, lower bench", m: 1.25 },
102
+ { key: "feet", label: "Feet on the lower bench", m: 0.45 },
103
+ { key: "floor", label: "Floor", m: 0 }
104
+ ].freeze
105
+ THERMOMETER_M = 1.7
106
+ ROOM_C = 22 # the ladder never drops below ordinary room temperature
107
+
108
+ module_function
109
+
110
+ def c2f(c)
111
+ c.to_f * 9 / 5 + 32
112
+ end
113
+
114
+ def f2c(f)
115
+ (f.to_f - 32) * 5 / 9
116
+ end
117
+
118
+ def clamp(v, lo, hi)
119
+ [hi, [lo, v].max].min
120
+ end
121
+
122
+ def num(v, fallback)
123
+ n = JS.parse_float(v)
124
+ n.finite? ? n : fallback
125
+ end
126
+
127
+ # Turn any input into a complete, valid set of options.
128
+ def normalize(input = nil)
129
+ input ||= {}
130
+ get = ->(k) { input.key?(k) ? input[k] : input[k.to_s] }
131
+ t = get[:type]
132
+ type = (t.is_a?(String) || t.is_a?(Symbol)) && TYPES.key?(t.to_s) ? t.to_s : "dry"
133
+ lv = get[:level]
134
+ level = (lv.is_a?(String) || lv.is_a?(Symbol)) && LEVELS.key?(lv.to_s) ? lv.to_s : "new"
135
+ u = get[:unit]
136
+ u = "f" if [nil, false, 0, ""].include?(u) || (u.is_a?(Float) && u.nan?)
137
+ unit = u.to_s.downcase == "c" ? "c" : "f"
138
+ range = TYPES[type][unit.to_sym]
139
+ temp = JS.round(clamp(num(get[:temp], range[:def]), range[:min], range[:max]).to_f).to_i
140
+ total = JS.round(clamp(num(get[:total], 60), MIN_TOTAL, MAX_TOTAL).to_f).to_i
141
+ { type: type, level: level, unit: unit, temp: temp, total: total }
142
+ end
143
+
144
+ # 0 at the cool end of the normal range for this sauna type, 1 at the hot end.
145
+ def heat_position(o)
146
+ t = TYPES[o[:type]]
147
+ c = o[:unit] == "c" ? o[:temp].to_f : f2c(o[:temp])
148
+ clamp((c - t[:c][:min]) / (t[:c][:max] - t[:c][:min]), 0, 1)
149
+ end
150
+
151
+ def round_minutes(o)
152
+ band = TYPES[o[:type]][:rounds][o[:level]] # [min, base, max]
153
+ factor = 1.15 - 0.40 * heat_position(o)
154
+ clamp(JS.round(band[1] * factor).to_i, band[0], band[2])
155
+ end
156
+
157
+ def water(rounds, heat_min)
158
+ before = 1
159
+ between = [0, rounds - 1].max
160
+ after = if heat_min <= 20 then 2 elsif heat_min <= 40 then 3 else 4 end
161
+ glasses = before + between + after
162
+ {
163
+ before: before, between: between, after: after, glasses: glasses,
164
+ oz: glasses * GLASS_OZ,
165
+ ml: glasses * GLASS_ML,
166
+ liters: JS.round(glasses * GLASS_ML / 100.0) / 10
167
+ }
168
+ end
169
+
170
+ # The plan for { type:, level:, unit:, temp:, total: } (any of them may be missing).
171
+ def plan(input = nil)
172
+ o = normalize(input)
173
+ t = TYPES[o[:type]]
174
+ round_min = round_minutes(o)
175
+ rest_min = clamp(round_min, REST_MIN, REST_MAX)
176
+ cool_min = COOL_DOWN
177
+ max_rounds = t[:maxRounds][o[:level]]
178
+ rounds = 0
179
+ trimmed = false
180
+
181
+ # Most rounds that fit, final cool-down included.
182
+ max_rounds.downto(1) do |n|
183
+ if n * round_min + (n - 1) * rest_min + cool_min <= o[:total]
184
+ rounds = n
185
+ break
186
+ end
187
+ end
188
+ # Not even one round fits: shorten the cool-down first, then the round.
189
+ if rounds.zero?
190
+ rounds = 1
191
+ cool_min = COOL_DOWN_MIN
192
+ if round_min + cool_min > o[:total]
193
+ round_min = o[:total] - cool_min
194
+ trimmed = true
195
+ end
196
+ end
197
+
198
+ heat_min = rounds * round_min
199
+ used_min = heat_min + (rounds - 1) * rest_min + cool_min
200
+
201
+ segments = []
202
+ at = 0
203
+ (1..rounds).each do |i|
204
+ segments << { kind: "heat", index: i, min: round_min, start: at, label: "Round #{i}" }
205
+ at += round_min
206
+ next unless i < rounds
207
+
208
+ segments << { kind: "rest", index: i, min: rest_min, start: at, label: "Cool-down" }
209
+ at += rest_min
210
+ end
211
+ segments << { kind: "cool", index: rounds, min: cool_min, start: at, label: "Final cool-down" }
212
+
213
+ bench = nil
214
+ if t[:benches]
215
+ bench = case o[:level] when "new" then "lower" when "regular" then "either" else "upper" end
216
+ end
217
+
218
+ notes = []
219
+ notes << "This is the hot end of the usual range for this kind of sauna, so the rounds are shorter." if heat_position(o) >= 0.85
220
+ if %w[loyly banya].include?(o[:type])
221
+ notes << "Steam makes the same reading feel hotter. After a big ladle, move down a bench or step out early."
222
+ end
223
+ notes << "In saturated air sweat cannot evaporate and cool you. Leave early if it feels like work." if o[:type] == "steam"
224
+ if o[:type] == "infrared" && rounds == 1
225
+ notes << "Infrared sessions are usually one continuous stay. Step out for a minute whenever you want to."
226
+ end
227
+ notes << "The round was shortened to fit your time and still leave a cool-down." if trimmed
228
+ if rounds < max_rounds && !trimmed
229
+ notes << "With more time you could add another round. Do not make these ones longer instead."
230
+ end
231
+
232
+ {
233
+ input: o,
234
+ rounds: rounds,
235
+ roundMin: round_min,
236
+ restMin: rounds > 1 ? rest_min : 0,
237
+ coolMin: cool_min,
238
+ heatMin: heat_min,
239
+ usedMin: used_min,
240
+ spareMin: o[:total] - used_min,
241
+ trimmed: trimmed,
242
+ bench: bench,
243
+ water: water(rounds, heat_min),
244
+ segments: segments,
245
+ notes: notes
246
+ }
247
+ end
248
+
249
+ # Straight-line stratification anchored at the thermometer. Illustration only.
250
+ def ladder(input = nil)
251
+ o = normalize(input)
252
+ t = TYPES[o[:type]]
253
+ at_thermometer = o[:unit] == "c" ? o[:temp].to_f : f2c(o[:temp])
254
+ LADDER_LEVELS.map do |lv|
255
+ c = [ROOM_C, at_thermometer + (lv[:m] - THERMOMETER_M) * t[:gradient]].max
256
+ c = at_thermometer if lv[:thermometer]
257
+ {
258
+ key: lv[:key],
259
+ label: lv[:label],
260
+ meters: lv[:m],
261
+ feet: JS.round(lv[:m] * 3.28084 * 2) / 2,
262
+ thermometer: lv[:thermometer] ? true : false,
263
+ c: JS.round(c.to_f).to_i,
264
+ f: JS.round(c2f(c)).to_i
265
+ }
266
+ end
267
+ end
268
+
269
+ # Convert a temperature when the unit toggle flips; snaps into the range.
270
+ def convert_temp(type, temp, to_unit)
271
+ t = TYPES[type.to_s] || TYPES["dry"]
272
+ range = t[to_unit.to_s == "c" ? :c : :f]
273
+ v = to_unit.to_s == "c" ? f2c(temp) : c2f(temp)
274
+ v = JS.round(v / 5) * 5 unless to_unit.to_s == "c" # °F slider moves in fives
275
+ JS.round(clamp(v, range[:min], range[:max]).to_f).to_i
276
+ end
277
+ end
278
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SaunaPlanner
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sauna_planner/version"
4
+ require_relative "sauna_planner/js"
5
+ require_relative "sauna_planner/heater"
6
+ require_relative "sauna_planner/planner"
7
+
8
+ # Sauna heater sizing (kW from room volume, glass, stone and log walls, by the
9
+ # heater makers' published rules) and a simple round-by-round session plan.
10
+ # A Ruby port of the free DIVELUX sauna tools:
11
+ # https://diveluxsaunahat.com/pages/sauna-tools
12
+ module SaunaPlanner
13
+ module_function
14
+
15
+ # Heater size for a room in meters. See SaunaPlanner::Heater.calc.
16
+ def heater(input = nil)
17
+ Heater.calc(input)
18
+ end
19
+
20
+ # Session plan. See SaunaPlanner::Planner.plan.
21
+ def plan(input = nil)
22
+ Planner.plan(input)
23
+ end
24
+
25
+ # JSON exactly as the JavaScript originals write it (JSON.stringify).
26
+ def to_json(result)
27
+ JS.json(result)
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sauna_planner
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - DIVELUX
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-12-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby port of the free DIVELUX sauna tools. Sizes an electric sauna heater
14
+ (kW range) or a wood-burning stove (room volume) from the hot room's inside size,
15
+ uninsulated glass and stone, and log walls, using Harvia's and HUUM's published
16
+ sizing rules; and lays out a round-by-round sauna session plan with breaks, cool-down,
17
+ bench and water. Pure Ruby, no dependencies, with a sauna-planner command. Tested
18
+ against the JavaScript originals on 69,696 rooms and 42,534 plans.
19
+ email:
20
+ - diveluxstore@gmail.com
21
+ executables:
22
+ - sauna-planner
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - CHANGELOG.md
27
+ - LICENSE.txt
28
+ - README.md
29
+ - exe/sauna-planner
30
+ - lib/sauna_planner.rb
31
+ - lib/sauna_planner/cli.rb
32
+ - lib/sauna_planner/heater.rb
33
+ - lib/sauna_planner/js.rb
34
+ - lib/sauna_planner/planner.rb
35
+ - lib/sauna_planner/version.rb
36
+ homepage: https://diveluxsaunahat.com/pages/sauna-tools
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://diveluxsaunahat.com/pages/sauna-tools
41
+ documentation_uri: https://diveluxsaunahat.com/pages/sauna-tools#sauna-tools
42
+ source_code_uri: https://github.com/divelux/sauna_planner
43
+ bug_tracker_uri: https://github.com/divelux/sauna_planner/issues
44
+ changelog_uri: https://github.com/divelux/sauna_planner/blob/main/CHANGELOG.md
45
+ rubygems_mfa_required: 'true'
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.5.22
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Sauna heater size (kW) from room volume, glass, stone and log walls, plus
65
+ a sauna session plan.
66
+ test_files: []