diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-09-27 21:19:25 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-09-27 21:19:25 +0200 |
commit | 8ee6f9d77d9d1cf28b8e436873c84aecc8205569 (patch) | |
tree | 008fb64f3903ded7a9c2ca1d73f2ac988a8af605 | |
parent | f372c22bc56faa0abf41a7b31e51cf345c3dde82 (diff) | |
download | ramaskrik-program-8ee6f9d77d9d1cf28b8e436873c84aecc8205569.tar.gz ramaskrik-program-8ee6f9d77d9d1cf28b8e436873c84aecc8205569.tar.bz2 ramaskrik-program-8ee6f9d77d9d1cf28b8e436873c84aecc8205569.zip |
Round timascale up to complete timescale_division units.
-rw-r--r-- | room-schedule.rb | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/room-schedule.rb b/room-schedule.rb index 910a742..84864cc 100644 --- a/room-schedule.rb +++ b/room-schedule.rb @@ -169,12 +169,37 @@ EOL end private + + def timescale_unit + if timescale_divisions + timescale_divisions =~ /(\d+) ?(days|weeks|hours|minutes|seconds)?/ + division_units = $2 ? $2 : "days" + amount = $1.to_i + unit = nil + case division_units + when "weeks" + unit = 7 + when "days" + unit = 1 + when "hours" + unit = (1.0 / 24) + when "minutes" + unit = (1.0 / 1440) + when "seconds" + unit = (1.0 / 86400) + end + end + [ amount, unit ] + end + def x_range max_value = @data.map {|room| room[:data].map {|e| e.end_time}.max}.max min_value = @data.map {|room| room[:data].map {|e| e.start_time}.min}.min + amount, unit = timescale_unit + max_value += unit * (amount - (max_value.min % amount)) range = max_value - min_value - right_pad = range == 0 ? 10 : range / 20.0 + right_pad = 0 #range == 0 ? 10 : range / 20.0 scale_range = (max_value + right_pad) - min_value scale_division = scale_x_divisions || (scale_range / 10.0) @@ -190,27 +215,9 @@ EOL rv = [] min, max, scale_division = x_range if timescale_divisions - timescale_divisions =~ /(\d+) ?(days|weeks|hours|minutes|seconds)?/ - division_units = $2 ? $2 : "days" - amount = $1.to_i - if amount - step = nil - case division_units - when "weeks" - step = 7 * amount - when "days" - step = amount - when "hours" - step = (1.0 / 24) * amount - when "minutes" - step = (1.0 / 1440) * amount - when "seconds" - step = (1.0 / 86400) * amount - end - min.step( max, step ) {|v| rv << v} if step - - return rv - end + amount, unit = timescale_unit + min.step( max, amount * unit) {|v| rv << v} if amount + return rv end min.step(max, scale_division) {|v| rv << v} return rv |