insulin 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -63,10 +63,12 @@ OnTrack allows you to mail the exported CSV files to an email address. [This pag
63
63
  Next steps
64
64
  ==========
65
65
 
66
- * Get it generating custom CSVs for Spreadsheeting
67
- * Get it doing some analysis
66
+ * Generate custom CSVs for spreadsheeting
67
+ * Generate PDFs for daily mail reports
68
+ * Do some analysis
68
69
  * Generate some more detailed output (latest HbA1c, BP, etc)
69
70
  * Give it a [meteor](http://meteor.com/) front-end (might require some help from [Chris](https://github.com/mrchrisadams)). Graphs, yo
71
+ * Connect to the Google Drive API to pull the exported CSVs (OnTrack will push there) and push spreadsheetable CSVs
70
72
  * Possibly connect to [this API](http://platform.fatsecret.com/api/) to extract carb values from plain-text food descriptions (this may be a little ambitious, we'll see)
71
73
 
72
74
  ---
data/TODO.md CHANGED
@@ -1,4 +1,3 @@
1
- * Default 'day' for executable doesn't make much sense
2
1
  * Indexes
3
2
  * Map/reduce somewhere?
4
3
  * Jenkins?
@@ -8,3 +7,10 @@
8
7
  * empty time periods should return "nothing known"
9
8
  * https://github.com/prawnpdf/prawn
10
9
  * Fully detailed output showing latest HbA1c, BP, etc
10
+ * Work out Google Drive API
11
+ * Write some proper rubydocs
12
+ * Should not include HbA1c or BP in normal output. Also, these things need units. And BP is not really a number
13
+ * Number of tests &c per time period
14
+ * Somehow include cholesterol
15
+ * Test the insulin executable
16
+ * "Latest weight, change since last, overall trend" &c
data/files/on_track.csv CHANGED
@@ -21,6 +21,8 @@ N: new pot of strips"
21
21
  294,"Jul 1, 2012 9:57:09 AM",Medication,Humalog,Breakfast,4.0,"Boiled eggs, toast"
22
22
  293,"Jul 1, 2012 9:41:47 AM",Glucose,,Breakfast,6.4,""
23
23
  292,"Jul 1, 2012 12:40:24 AM",Medication,Lantus,Bedtime,14.0,""
24
+ 441,"Jun 30, 2012 3:46:29 PM",HbA1c,,,8.8,""
25
+ 440,"Jun 30, 2012 3:46:15 PM",Blood Pressure,,After Lunch,118/75,""
24
26
  291,"Jun 30, 2012 11:14:04 PM",Glucose,,Bedtime,17.5,"D:m"
25
27
  290,"Jun 30, 2012 7:56:20 PM",Glucose,,After Dinner,7.0,""
26
28
  289,"Jun 30, 2012 7:07:42 PM",Medication,Humalog,Dinner,6.0,"Prawns, egg-fried rice"
@@ -39,3 +41,4 @@ N: new pot of strips"
39
41
  276,"Jun 29, 2012 10:00:54 AM",Weight,,Breakfast,58.0,""
40
42
  275,"Jun 29, 2012 8:45:13 AM",Medication,Humalog,Breakfast,4.0,"F:2 eggs, 2 toast"
41
43
  274,"Jun 29, 2012 8:37:47 AM",Glucose,,Breakfast,3.9,""
44
+ 273,"Jun 29, 2012 3:46:29 PM",HbA1c,,,14.5,""
data/lib/insulin/day.rb CHANGED
@@ -30,6 +30,14 @@ module Insulin
30
30
  end
31
31
  end
32
32
 
33
+ def has_events?
34
+ if self["all"].size > 0
35
+ return true
36
+ end
37
+
38
+ return false
39
+ end
40
+
33
41
  def average_glucose
34
42
  t = 0
35
43
  c = 0
data/lib/insulin/event.rb CHANGED
@@ -11,7 +11,9 @@ module Insulin
11
11
  "glucose" => "mmol/L",
12
12
  "medication" => "x10^-5 L",
13
13
  "weight" => "kg",
14
- "exercise" => "minutes"
14
+ "exercise" => "minutes",
15
+ "blood pressure" => "sp/df",
16
+ "hba1c" => "%"
15
17
  }
16
18
 
17
19
  # An event before this time is considered part of the previous day. Because
@@ -59,8 +61,12 @@ module Insulin
59
61
  end
60
62
 
61
63
  def simple
62
- s = "%s | %-15s | %-10s | %-13s | %4.1f %s" % [
63
- self["time"],
64
+ value_format = "%6.1f"
65
+ if self["value"].is_a? String
66
+ value_format = "%6s"
67
+ end
68
+ s = "%s | %-15s | %-14s | %-13s | #{value_format} %s" % [
69
+ self["short_time"],
64
70
  self["tag"],
65
71
  self["type"],
66
72
  self["subtype"],
@@ -15,7 +15,9 @@ module Insulin
15
15
  d = (t + (i * 86400))
16
16
  if d <= today
17
17
  day = Day.new d.strftime("%F"), @mongo
18
- self << day
18
+ if day.has_events?
19
+ self << day
20
+ end
19
21
  @count += 1
20
22
  end
21
23
  end
@@ -24,12 +26,14 @@ module Insulin
24
26
  @count
25
27
  ]
26
28
 
29
+ @hba1c = @mongo.db.collection("hba1c").find.sort(:timestamp).to_a[-1]
27
30
  end
28
31
 
29
32
  def average_glucose
30
33
  total = 0
31
34
  self.each do |d|
32
35
  total += d.average_glucose
36
+ puts d.keys
33
37
  end
34
38
 
35
39
  return total / self.size
@@ -54,7 +58,15 @@ module Insulin
54
58
  @start_date,
55
59
  self.average_glucose,
56
60
  self[0].glucose_units
57
- ]
61
+ ]
62
+
63
+ s << "\n"
64
+ s << " "
65
+ s << "latest hba1c (from %s): %0.1f%s" % [
66
+ @hba1c["date"],
67
+ @hba1c["value"],
68
+ @hba1c["units"]
69
+ ]
58
70
 
59
71
  s
60
72
  end
@@ -22,7 +22,11 @@ module Insulin
22
22
  self["type"] = bits[3].downcase
23
23
  self["subtype"] = bits[4].downcase if not bits[4] == ""
24
24
  self["tag"] = bits[5].downcase
25
- self["value"] = bits[6].to_f
25
+ if self["type"] == "blood pressure"
26
+ self["value"] = bits[6]
27
+ else
28
+ self["value"] = bits[6].to_f
29
+ end
26
30
 
27
31
  # Notes get complicated. Everything from field 7 to the end will be part
28
32
  # of the notes
@@ -21,6 +21,7 @@ module Insulin
21
21
  self["day"] = t.strftime("%A").downcase
22
22
  self["date"] = t.strftime "%F"
23
23
  self["time"] = t.strftime "%T #{self['timezone']}"
24
+ self["short_time"] = t.strftime "%H:%M"
24
25
  end
25
26
  end
26
27
  end
@@ -1,5 +1,5 @@
1
1
  module Insulin
2
2
 
3
3
  # Current version
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/spec/day_spec.rb CHANGED
@@ -29,7 +29,9 @@ describe Insulin::Day do
29
29
  end
30
30
 
31
31
  it "should display correctly" do
32
- d.to_s.should include "19:07:42 BST | dinner | medication | humalog | 6.0 x10^-5 L"
32
+ d.to_s.should include "19:07 | dinner | medication | humalog | 6.0 x10^-5 L"
33
+ d.to_s.should include "15:46 | after lunch | blood pressure | | 118/75 sp/df"
34
+ d.to_s.should include "15:46 | | hba1c | | 8.8 %"
33
35
  end
34
36
 
35
37
  it "minimal display should be correct" do
data/spec/event_spec.rb CHANGED
@@ -64,5 +64,11 @@ N:other note"}
64
64
  mongo_event["time"].should == "10:21:05 BST"
65
65
  end
66
66
 
67
+ bp_event = Insulin::Event.new Insulin::OnTrack::CsvLine.new %q{440,"Jun 30, 2012 3:46:15 PM",Blood Pressure,,After Lunch,118/75,""}
68
+
69
+ it "should have the correct value" do
70
+ bp_event["value"].should == "118/75"
71
+ end
72
+
67
73
  mongo.drop_db
68
74
  end
data/spec/month_spec.rb CHANGED
@@ -20,9 +20,5 @@ describe Insulin::Month do
20
20
  m.average_glucose.should_not == nil
21
21
  end
22
22
 
23
- it "should say '15-day period'" do
24
- m.to_s.should include "15-day period"
25
- end
26
-
27
23
  drop_test_db
28
24
  end
@@ -6,12 +6,12 @@ describe Insulin::NDayPeriod do
6
6
 
7
7
  b = Insulin::NDayPeriod.new({
8
8
  "start_date" => "2012-06-29",
9
- "days" => 3,
9
+ "days" => 7,
10
10
  "mongo" => @mongo
11
11
  })
12
12
 
13
- it "should contain 3 items" do
14
- b.size.should == 3
13
+ it "should contain 4 items" do
14
+ b.size.should == 4
15
15
  end
16
16
 
17
17
  it "items should be days" do
@@ -20,19 +20,19 @@ describe Insulin::NDayPeriod do
20
20
  end
21
21
  end
22
22
 
23
- it "should have average glucose of 7.16" do
24
- ("%0.2f" % b.average_glucose).to_f.should == 7.16
23
+ it "should have average glucose of 6.87" do
24
+ ("%0.2f" % b.average_glucose).to_f.should == 6.87
25
25
  end
26
26
 
27
- c = Insulin::NDayPeriod.new(
28
- "start_date" => Time.new.strftime("%F"),
29
- "days" => 7,
30
- "mongo" => @mongo
31
- )
32
-
33
- it "should not go storming off into the future" do
34
- c.size.should == 1
35
- end
27
+ # c = Insulin::NDayPeriod.new(
28
+ # "start_date" => Time.new.strftime("%F"),
29
+ # "days" => 7,
30
+ # "mongo" => @mongo
31
+ # )
32
+ #
33
+ # it "should not go storming off into the future" do
34
+ # c.size.should == 1
35
+ # end
36
36
 
37
37
  t = Time.new
38
38
  t = t + 86400
@@ -19,6 +19,10 @@ describe Insulin::OnTrack::Date do
19
19
  otd["day"].should == "friday"
20
20
  end
21
21
 
22
+ it "should have the correct short time" do
23
+ otd["short_time"].should == "09:00"
24
+ end
25
+
22
26
  otd_gmt = Insulin::OnTrack::Date.new "Jan 22 2012 9:00:12 PM"
23
27
 
24
28
  it "should have the correct timestamp" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insulin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor