Skip to content

Commit

Permalink
Improve analytics readability
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
francois committed Aug 17, 2016
1 parent 2dc7a97 commit bfcd1d3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion views/analytics.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<% (0..23).each do |hour| %>
<% next unless @hours_slept_histogram[[key, hour.to_f]] %></td>
<tr>
<td><%= hour %></td>
<td><%= hour %> - <%= hour + 1 %></td>
<td><%= @hours_slept_histogram.fetch([key, hour.to_f], "N/A") %></td>
<td>
<div class="graph-bar" style="width: <%= "%.1f" % [ 100.0 * @hours_slept_histogram.fetch([key, hour.to_f], 0.0) / @max_hours.fetch(key, 1.0) ] %>%">&nbsp;</div>
Expand Down

0 comments on commit bfcd1d3

Please sign in to comment.