Created
August 21, 2013 20:01
-
-
Save bleakwood/6299443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Readings::BloodPressure < Readings::Base | |
has_data_fields [:diastolic, :systolic] | |
validates :diastolic, :numericality => {:greater_than => 0} | |
validates :systolic, :numericality => {:greater_than => 0} | |
def self.display_name | |
"Blood Pressure" | |
end | |
def self.get_data_for(raw_data) | |
{ :systolic => [], :diastolic => [] }.tap do |series| | |
raw_data.each do |d| | |
series[:systolic] << [d.reading_date.to_time.to_i * 1000, d.systolic] | |
series[:diastolic] << [d.reading_date.to_time.to_i * 1000, d.diastolic] | |
end | |
end | |
end | |
def self.get_display_value(raw_data) | |
# Monthly average | |
# FIXME: If the pairs are uneven, can't use raw_data.count | |
display_value = "" | |
sums = {:systolic => 0, :diastolic => 0} | |
raw_data.each do |d| | |
sums[:diastolic] += d.diastolic | |
sums[:systolic] += d.systolic | |
end | |
sums.each_with_index do |(context, sum), index| | |
display_value += (sum / raw_data.count).to_s unless raw_data.count == 0 | |
display_value += "/" if index < sums.length - 1 | |
end | |
display_value | |
end | |
def high_diastolic? | |
diastolic > 100 | |
end | |
def high_systolic? | |
systolic > 150 | |
end | |
def hypertension? | |
high_diastolic? && high_systolic? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment