Class: Insulin::Event
- Inherits:
-
Hash
- Object
- Hash
- Insulin::Event
- Defined in:
- lib/insulin/event.rb
Overview
This class represents a single OnTrack event (BG, meds, etc)
Constant Summary collapse
- @@units =
{ "glucose" => "mmol/L", "medication" => "x10^-5 L", "weight" => "kg", "exercise" => "minutes" }
- @@cut_off_time =
An event before this time is considered part of the previous day. Because sometimes, we stay up late
"04:00"
Instance Method Summary collapse
-
#initialize(h) ⇒ Event
constructor
We expect to be passed a hash.
-
#save(mongo_handle) ⇒ Object
Save the event to Mongo via mongo_handle.
- #simple ⇒ Object
Constructor Details
#initialize(h) ⇒ Event
We expect to be passed a hash
22 23 24 25 26 |
# File 'lib/insulin/event.rb', line 22 def initialize h self.update h self["units"] = @@units[self["type"]] end |
Instance Method Details
#save(mongo_handle) ⇒ Object
Save the event to Mongo via mongo_handle
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/insulin/event.rb', line 29 def save mongo_handle # See above date_collection = self["date"] if self["time"] < @@cut_off_time date_collection = (Time.parse(self["date"]) - 86400).strftime "%F" end # Save to each of these collections clxns = [ "events", self["type"], self["subtype"], date_collection ] clxns.each do |c| if c mongo_handle.db.collection(c).update( { "serial" => self["serial"] }, self, { # Upsert: update if exists, otherwise insert :upsert => true } ) end end end |
#simple ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/insulin/event.rb', line 61 def simple s = " %s %-10s %-10s %4.1f %s" % [ self["time"], self["type"], self["subtype"], self["value"], self["units"] ] s end |