Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
mood, pulse, and sleep should be most recent
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Hopkins committed Oct 14, 2013
1 parent 4157ead commit ffd006a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
12 changes: 12 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@ class User < ActiveRecord::Base
end

scope :admin, -> { where(admin: true).first }

def current_sleep
Sleep.where(user: User.admin).order(:created_at).reverse_order.first
end

def current_mood
Mood.where(user: User.admin).order(:created_at).reverse_order.first
end

def current_pulse
Pulse.where(user: User.admin).order(:created_at).reverse_order.first
end
end
18 changes: 9 additions & 9 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
</aside>
</li>
<li class="sleep" data-row="1" data-col="5" data-sizex="2" data-sizey="2">
<div id="quality" class="css-animation <%= if (@user.sleep.quality == 100) then 'three' end %>"><%= @user.sleep.quality %></div>
<canvas id="sleep-canvas" height="225" width="225" data-light="<%= @user.sleep.light_sleep %>" data-deep="<%= @user.sleep.deep_sleep %>"></canvas>
<p id="deep">Deep Sleep: <span><%= Time.at(@user.sleep.deep_sleep).gmtime.strftime("%l:%M") %></span></p>
<p id="light">Light Sleep: <span><%= Time.at(@user.sleep.light_sleep).gmtime.strftime("%l:%M") %></span></p>
<div id="quality" class="css-animation <%= if (@user.current_sleep.quality == 100) then 'three' end %>"><%= @user.current_sleep.quality %></div>
<canvas id="sleep-canvas" height="225" width="225" data-light="<%= @user.current_sleep.light_sleep %>" data-deep="<%= @user.current_sleep.deep_sleep %>"></canvas>
<p id="deep">Deep Sleep: <span><%= Time.at(@user.current_sleep.deep_sleep).gmtime.strftime("%l:%M") %></span></p>
<p id="light">Light Sleep: <span><%= Time.at(@user.current_sleep.light_sleep).gmtime.strftime("%l:%M") %></span></p>
</li>
<!-- End of Row 1 -->

Expand All @@ -28,13 +28,13 @@
<canvas id="steps-canvas" height="225" width="569"></canvas>
</li>
<li class="mood" data-row="1" data-col="6" data-sizex="1" data-sizey="1">
<p id="title"><%= @user.mood.title %></p>
<p id="title"><%= @user.current_mood.title %></p>
<canvas id="mood-canvas" height="105" width="105"></canvas>
</li>
<li class="pulse" data-row="2" data-col="5" data-sizex="2" data-sizey="1">
<i id="heart" data-icon="&hearts;" data-aria="hidden"></i>
<div id="rate" class="css-animation"><%= @user.pulse.rate %></div>
<span id="updated"><%= @user.pulse.updated_at.in_time_zone("Eastern Time (US & Canada)").strftime("%a %k:%S") %> EST</span>
<div id="rate" class="css-animation"><%= @user.current_pulse.rate %></div>
<span id="updated"><%= @user.current_pulse.updated_at.in_time_zone("Eastern Time (US & Canada)").strftime("%a %k:%S") %> EST</span>
</li>
<!-- End of Row 2 -->

Expand Down Expand Up @@ -82,9 +82,9 @@
labels : [""],
datasets : [
{
fillColor : "<%= if @user.mood.title == 'No Data' then '#f7464a' else 'rgba(224,228,204,0.5)' end %>",
fillColor : "<%= if @user.current_mood.title == 'No Data' then '#f7464a' else 'rgba(224,228,204,0.5)' end %>",
strokeColor : "rgba(224,228,204,1)",
data : ["<%= @user.mood.sub_type %>"]
data : ["<%= @user.current_mood.sub_type %>"]
}
]
};
Expand Down
2 changes: 1 addition & 1 deletion lib/dashboard/jawbone_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def new_sleep
deep = sleep_summary['items'].first['details']['deep']
end

if last = @admin.sleep
if last = @admin.current_sleep
unless (light == last.light_sleep && deep == last.deep_sleep && quality == last.quality)
create_sleep(light, deep, quality)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dashboard/withings_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def new_pulse(admin)
if raw_data = @user.measurement_groups(measurement_type: 11).first
data = raw_data.to_s
rate = data[/.*@([^,]*)/,1].strip.to_i
if last = @admin.pulse
if last = @admin.current_pulse
if rate != last.rate
create_pulse(rate)
end
Expand Down

0 comments on commit ffd006a

Please sign in to comment.