Sha256: ec2aa23543902ae79df5dcdd248f55b183e4f03866f99684b3eaf8bfc6c60a5e
Contents?: true
Size: 1.62 KB
Versions: 9
Compression:
Stored size: 1.62 KB
Contents
require 'insulin' module Insulin class Day < Hash attr_reader :glucose_units, :date, :day def initialize date, mongo @date = date @mongo = mongo keys = [ "type", "subtype", "tag" ] self["all"] = [] @mongo.db.collection(date).find().each do |e| ev = Event.new(e) keys.each do |k| sub = ev[k] if self[sub] self[sub] << ev else self[sub] = [ev] end end self["all"] << ev @day = self["all"][0]["day"] end end def has_events? if self["all"].size > 0 return true end return false end def average_glucose t = 0 c = 0 begin self["glucose"].each do |g| @glucose_units = g["units"] t += g["value"] c += 1 end rescue NoMethodError return 0 end return t / c end def to_s s = "" s << @date s << "\n" self["all"].each do |e| s << " " s << e.simple s << "\n" end s << "\n" s << " " s << "average glucose: %4.2f %s" % [ self.average_glucose, @glucose_units ] s end def minimal s = "" s << @date s << "\n" self["all"].each do |e| # if ["breakfast", "lunch", "dinner", "bedtime"].include? e["tag"] and # ["medication", "glucose"].include? e["type"] if e.simple? s << " " s << e.simple s << "\n" end end s end end end
Version data entries
9 entries across 9 versions & 1 rubygems