From 114366863b001af51cd599ef62989feb3af15119 Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 30 Aug 2020 14:47:31 +0200 Subject: Make daily command indicate date of sleep events 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. --- lib/postrunner/MonitoringStatistics.rb | 12 ++++++++---- 1 file 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 -- cgit v1.2.3