From bfcd1d3f1bc5585d309f02b3a125cb359539fdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beausoleil?= Date: Wed, 17 Aug 2016 03:29:25 +0000 Subject: [PATCH] Improve analytics readability The histogram needed to identify that there are N events in the X to Y group. Similarly, a frequency is an integer: there are no 1.3 observations of "slept between 2 and 3 hours". --- app.rb | 6 +++--- views/analytics.erb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app.rb b/app.rb index d95a9a5..496d5de 100644 --- a/app.rb +++ b/app.rb @@ -185,11 +185,11 @@ def table_name_from_user_id(user_id) GROUP BY 1, 2 EOSQL @hours_slept_histogram = hours_slept_histogram_ds.to_hash_groups([:sleep_type, :hour], :count).map do |key, value| - [[key.first, key.last.to_f], value.first.to_f] + [[key.first, key.last.to_f], value.first] end.to_h @max_hours = Hash.new - @max_hours["night"] = @hours_slept_histogram.select{|k, _| k[0] == "night"}.map(&:last).compact.sort.last.to_f - @max_hours["nap"] = @hours_slept_histogram.select{|k, _| k[0] == "nap"}.map(&:last).compact.sort.last.to_f + @max_hours["night"] = @hours_slept_histogram.select{|k, _| k[0] == "night"}.map(&:last).compact.sort.last + @max_hours["nap"] = @hours_slept_histogram.select{|k, _| k[0] == "nap"}.map(&:last).compact.sort.last @user_id = user_id @app = :analytics diff --git a/views/analytics.erb b/views/analytics.erb index 9aed1a6..1c06cc3 100644 --- a/views/analytics.erb +++ b/views/analytics.erb @@ -39,7 +39,7 @@ <% (0..23).each do |hour| %> <% next unless @hours_slept_histogram[[key, hour.to_f]] %> - <%= hour %> + <%= hour %> - <%= hour + 1 %> <%= @hours_slept_histogram.fetch([key, hour.to_f], "N/A") %>
%">