diff options
author | cos <cos> | 2020-08-30 14:47:31 +0200 |
---|---|---|
committer | cos <cos> | 2020-08-30 20:34:54 +0200 |
commit | 4d9649fee9bb8c8cf5ca18c2aa9c96283c229574 (patch) | |
tree | 7f329cf50b8e76bc5e4c2a2052c942d04103478c /lib | |
parent | 79e947d6a3d10dab9c20408f553759b02fbdb556 (diff) | |
download | postrunner-topic/prefix_daily_times.zip |
Make daily command indicate date of sleep eventstopic/prefix_daily_times
By prefixing the timestamps of sleep events with either a space ' ' when
they occured on the same day as the requested date, and prefixing with a
plus '+' when not on the same day, it becomes trivial to distinguish
events after midnight apart from events prior to midnight.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/postrunner/MonitoringStatistics.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/postrunner/MonitoringStatistics.rb b/lib/postrunner/MonitoringStatistics.rb index fb8daea..3bfb9fc 100644 --- a/lib/postrunner/MonitoringStatistics.rb +++ b/lib/postrunner/MonitoringStatistics.rb @@ -115,6 +115,10 @@ module PostRunner t.localtime(utc_offset).strftime('%H:%M') end + def prefix_for_time(t, a) + a.window_start_time.strftime('%Y-%m-%d') == t.strftime('%Y-%m-%d') ? ' ' : '+' + end + def daily_sleep_cycle_table(analyzer) ti = FlexiTable.new ti.head @@ -129,8 +133,8 @@ module PostRunner if last_to_time && c.from_time > last_to_time # We have a gap in the sleep cycles. ti.cell('Wake') - cell_right_aligned(ti, time_as_hm(last_to_time, utc_offset)) - cell_right_aligned(ti, time_as_hm(c.from_time, utc_offset)) + cell_right_aligned(ti, prefix_for_time(last_to_time, analyzer) + time_as_hm(last_to_time, utc_offset)) + cell_right_aligned(ti, prefix_for_time(c.from_time, analyzer) + time_as_hm(c.from_time, utc_offset)) cell_right_aligned(ti, "(#{secsToHM(c.from_time - last_to_time)})") ti.cell('') ti.cell('') @@ -139,8 +143,8 @@ module PostRunner end ti.cell((idx + 1).to_s, format) - ti.cell(c.from_time.localtime(utc_offset).strftime('%H:%M'), format) - ti.cell(c.to_time.localtime(utc_offset).strftime('%H:%M'), format) + ti.cell(prefix_for_time(c.from_time.localtime(utc_offset), analyzer) + c.from_time.localtime(utc_offset).strftime('%H:%M'), format) + ti.cell(prefix_for_time(c.to_time.localtime(utc_offset), analyzer) + c.to_time.localtime(utc_offset).strftime('%H:%M'), format) duration = c.to_time - c.from_time totals[:duration] += duration |