insulin 0.0.18 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- insulin (0.0.16)
4
+ insulin (0.1.0)
5
5
  bson_ext
6
6
  ffi
7
7
  mongo
data/README.md CHANGED
@@ -28,26 +28,28 @@ This will take that file, parse it, and push the JSON into a number of collectio
28
28
  { "_id" : ObjectId("4ff07b371508cc259c8a8f0c"), "serial" : 266, "timestamp" : ISODate("2012-06-28T09:21:05Z"), "tzoffset" : "+0100", "timezone" : "BST", "unixtime" : 1340875265, "day" : "thursday", "date" : "2012-06-28", "time" : "10:21:05 BST", "type" : "medication", "subtype" : "humalog", "tag" : "breakfast", "value" : 4, "notes" : { "food" : [ "2 bacon", "2 toast" ], "note" : [ "test note" ] } }
29
29
  >
30
30
 
31
- Currently the only supported output operation is
31
+ Current output options are
32
32
 
33
33
  insulin day DATE
34
-
35
- to show stats for date DATE (in YYYY-MM-DD format) - defaults to 'today' if no date supplied. Note that insulin considers events that occur up to 04:00 as part of the previous actual day (because sometimes we stay up late, right?). Output will look something like
36
-
37
- 2012-07-06
38
- 06:50:54 BST glucose 6.4 mmol/L
39
- 07:05:38 BST weight 59.0 kg
40
- 09:43:33 BST glucose 6.7 mmol/L
41
- 09:50:23 BST medication humalog 4.0 x10^-5 L
42
- 13:17:43 BST glucose 4.7 mmol/L
43
- 13:31:44 BST medication humalog 4.0 x10^-5 L
44
- 15:57:12 BST glucose 6.2 mmol/L
45
- 20:01:41 BST glucose 6.2 mmol/L
46
- 20:05:21 BST medication humalog 6.0 x10^-5 L
47
- 21:42:38 BST glucose 9.0 mmol/L
48
- 00:34:22 BST glucose 9.5 mmol/L
49
- 00:49:27 BST medication lantus 12.0 x10^-5 L
50
- Average glucose: 6.96 mmol/L
34
+ insulin month DATE
35
+ insulin week DATE
36
+
37
+ Example:
38
+
39
+ $ insulin day 2012-07-01
40
+ 2012-07-01
41
+ 09:41:47 BST | breakfast | glucose | | 6.4 mmol/L
42
+ 09:57:09 BST | breakfast | medication | humalog | 4.0 x10^-5 L
43
+ 12:40:43 BST | lunch | weight | | 59.0 kg
44
+ 13:54:04 BST | lunch | glucose | | 5.0 mmol/L
45
+ 14:03:05 BST | lunch | medication | humalog | 4.0 x10^-5 L
46
+ 18:56:25 BST | dinner | glucose | | 4.9 mmol/L
47
+ 19:03:37 BST | dinner | medication | humalog | 6.0 x10^-5 L
48
+ 21:06:01 BST | after dinner | glucose | | 3.5 mmol/L
49
+ 22:32:32 BST | bedtime | glucose | | 7.5 mmol/L
50
+ 22:46:12 BST | bedtime | medication | lantus | 14.0 x10^-5 L
51
+
52
+ average glucose: 5.46 mmol/L
51
53
 
52
54
  You can also run the tests, if you're into that sort of thing:
53
55
 
@@ -63,6 +65,7 @@ Next steps
63
65
 
64
66
  * Get it generating custom CSVs for Spreadsheeting
65
67
  * Get it doing some analysis
68
+ * Generate some more detailed output (latest HbA1c, BP, etc)
66
69
  * Give it a [meteor](http://meteor.com/) front-end (might require some help from [Chris](https://github.com/mrchrisadams)). Graphs, yo
67
70
  * 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)
68
71
 
data/TODO.md CHANGED
@@ -1,8 +1,10 @@
1
- * Executable needs to handle config somehow (~/.insulinrc maybe)
1
+ * Default 'day' for executable doesn't make much sense
2
2
  * Indexes
3
3
  * Map/reduce somewhere?
4
4
  * Jenkins?
5
5
  * Food - combine available carbs data with meds object? or other way around?
6
6
  * Estimated HbA1c?
7
- * Have week and month options which default to the last week, last 30 days
8
- * https://github.com/svenfuchs/gem-release
7
+ * https://github.com/svenfuchs/gem-release - put these into rake tasks?
8
+ * empty time periods should return "nothing known"
9
+ * https://github.com/prawnpdf/prawn
10
+ * Fully detailed output showing latest HbA1c, BP, etc
@@ -7,8 +7,6 @@ module Insulin
7
7
  class I < Thor
8
8
  @@mongo = Insulin::MongoHandle.new ({"database" => "insulin"})
9
9
 
10
- # map "-i" => :ingest
11
-
12
10
  desc "ingest FILE", "ingest OnTrack CSV export FILE"
13
11
  def ingest file
14
12
  csv = Insulin::OnTrack::CsvFile.new file
@@ -39,7 +37,15 @@ module Insulin
39
37
  puts w.to_s
40
38
  end
41
39
 
42
- default_task :day
40
+ desc "month DATE", "show stats for 30-day period commencing DATE (defaults to previous 30 days)"
41
+ def month date = nil
42
+ if not date
43
+ require 'time'
44
+ date = (Time.new - (30 * 86400)).strftime "%F"
45
+ end
46
+ m = Insulin::Month.new date, @@mongo
47
+ puts m.to_s
48
+ end
43
49
  end
44
50
  end
45
51
 
@@ -3,7 +3,9 @@ require "insulin/config"
3
3
  require "insulin/mongo_handle"
4
4
  require "insulin/event"
5
5
  require "insulin/day"
6
+ require "insulin/n_day_period"
6
7
  require "insulin/week"
8
+ require "insulin/month"
7
9
  require "insulin/on_track/date"
8
10
  require "insulin/on_track/note"
9
11
  require "insulin/on_track/note_set"
@@ -16,5 +18,5 @@ require "insulin/on_track/csv_file"
16
18
  # OnTrack[https://play.google.com/store/apps/details?id=com.gexperts.ontrack&hl=en]
17
19
  # can export its data as a CSV. Insulin takes this data, parses it into
18
20
  # (possibly) useful formats, and stuffs it into MongoDB
19
- module Insulin
20
- end
21
+ #module Insulin
22
+ #end
@@ -2,6 +2,8 @@ require 'insulin'
2
2
 
3
3
  module Insulin
4
4
  class Day < Hash
5
+ attr_reader :glucose_units
6
+
5
7
  def initialize date, mongo
6
8
  @date = date
7
9
  @mongo = mongo
@@ -55,8 +57,9 @@ module Insulin
55
57
  s << "\n"
56
58
  end
57
59
 
60
+ s << "\n"
58
61
  s << " "
59
- s << "Average glucose: %4.2f %s" % [
62
+ s << "average glucose: %4.2f %s" % [
60
63
  self.average_glucose,
61
64
  @glucose_units
62
65
  ]
@@ -68,7 +71,6 @@ module Insulin
68
71
  s << @date
69
72
  s << "\n"
70
73
 
71
- # This needs a test!
72
74
  self["all"].each do |e|
73
75
  if ["breakfast", "lunch", "dinner", "bedtime"].include? e["tag"] and
74
76
  ["medication", "glucose"].include? e["type"]
@@ -0,0 +1,13 @@
1
+ require 'insulin'
2
+
3
+ module Insulin
4
+ class Month < NDayPeriod
5
+ def initialize date, mongo
6
+ super({
7
+ "start_date" => date,
8
+ "days" => 30,
9
+ "mongo" => mongo
10
+ })
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,62 @@
1
+ require 'insulin'
2
+ require 'time'
3
+
4
+ module Insulin
5
+ class NDayPeriod < Array
6
+ def initialize hash
7
+ @start_date = hash["start_date"]
8
+ @days = hash["days"]
9
+ @mongo = hash["mongo"]
10
+
11
+ t = Time.parse @start_date
12
+ today = Time.new
13
+ @count = 0
14
+ @days.times do |i|
15
+ d = (t + (i * 86400))
16
+ if d <= today
17
+ day = Day.new d.strftime("%F"), @mongo
18
+ self << day
19
+ @count += 1
20
+ end
21
+ end
22
+
23
+ @descriptor = "%d-day period" % [
24
+ @count
25
+ ]
26
+
27
+ end
28
+
29
+ def average_glucose
30
+ total = 0
31
+ self.each do |d|
32
+ total += d.average_glucose
33
+ end
34
+
35
+ return total / self.size
36
+ end
37
+
38
+ def to_s
39
+ s = "%s commencing %s" % [
40
+ @descriptor,
41
+ @start_date
42
+ ]
43
+ s << "\n"
44
+ s << "\n"
45
+
46
+ self.each do |d|
47
+ s << d.minimal
48
+ s << "\n"
49
+ end
50
+
51
+ s << " "
52
+ s << "average glucose for %s commencing %s: %0.2f %s" % [
53
+ @descriptor,
54
+ @start_date,
55
+ self.average_glucose,
56
+ self[0].glucose_units
57
+ ]
58
+
59
+ s
60
+ end
61
+ end
62
+ end
@@ -1,5 +1,5 @@
1
1
  module Insulin
2
2
 
3
3
  # Current version
4
- VERSION = "0.0.18"
4
+ VERSION = "0.1.0"
5
5
  end
@@ -1,45 +1,15 @@
1
1
  require 'insulin'
2
- require 'time'
3
2
 
4
3
  module Insulin
5
- class Week < Array
4
+ class Week < NDayPeriod
6
5
  def initialize date, mongo
7
- @date = date
8
- @mongo = mongo
6
+ super({
7
+ "start_date" => date,
8
+ "days" => 7,
9
+ "mongo" => mongo
10
+ })
9
11
 
10
- t = Time.parse @date
11
- 6.times do |i|
12
- d = (t + (i * 86400)).strftime "%F"
13
- day = Day.new d, @mongo
14
- self << day
15
- end
16
- end
17
-
18
- def average_glucose
19
- total = 0
20
- self.each do |d|
21
- total += d.average_glucose
22
- end
23
-
24
- return total / self.size
25
- end
26
-
27
- def to_s
28
- s = "Week commencing %s" % @date
29
- s << "\n"
30
- s << "\n"
31
-
32
- self.each do |d|
33
- s << d.minimal
34
- s << "\n"
35
- end
36
-
37
- s << " "
38
- s << "Average glucose for week commencing %s: %4.1f" % [
39
- @date,
40
- self.average_glucose
41
- ]
42
- s
12
+ @descriptor = "week"
43
13
  end
44
14
  end
45
15
  end
@@ -34,6 +34,7 @@ describe Insulin::Day do
34
34
 
35
35
  it "minimal display should be correct" do
36
36
  d.minimal.should_not include "exercise"
37
+ d.minimal.should_not include "after"
37
38
  end
38
39
 
39
40
  drop_test_db
@@ -0,0 +1,28 @@
1
+ require 'insulin'
2
+ require "spec_helper.rb"
3
+
4
+ describe Insulin::Month do
5
+ load_test_db
6
+
7
+ m = Insulin::Month.new "2012-06-29", @mongo
8
+
9
+ it "should contain something" do
10
+ m.size.should > 0
11
+ end
12
+
13
+ it "should have days" do
14
+ m.each do |d|
15
+ d.class.name.should == "Insulin::Day"
16
+ end
17
+ end
18
+
19
+ it "should have average glucose" do
20
+ m.average_glucose.should_not == nil
21
+ end
22
+
23
+ it "should say '15-day period'" do
24
+ m.to_s.should include "15-day period"
25
+ end
26
+
27
+ drop_test_db
28
+ end
@@ -0,0 +1,51 @@
1
+ require 'insulin'
2
+ require 'spec_helper.rb'
3
+
4
+ describe Insulin::NDayPeriod do
5
+ load_test_db
6
+
7
+ b = Insulin::NDayPeriod.new({
8
+ "start_date" => "2012-06-29",
9
+ "days" => 3,
10
+ "mongo" => @mongo
11
+ })
12
+
13
+ it "should contain 3 items" do
14
+ b.size.should == 3
15
+ end
16
+
17
+ it "items should be days" do
18
+ b.each do |d|
19
+ d.class.name.should == "Insulin::Day"
20
+ end
21
+ end
22
+
23
+ it "should have average glucose of 7.16" do
24
+ ("%0.2f" % b.average_glucose).to_f.should == 7.16
25
+ end
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
36
+
37
+ t = Time.new
38
+ t = t + 86400
39
+ d = Insulin::NDayPeriod.new(
40
+ "start_date" => t.strftime("%F"),
41
+ "days" => 7,
42
+ "mongo" => @mongo
43
+ )
44
+
45
+ it "should have nothing if start_date is in the future" do
46
+ d.size.should == 0
47
+ end
48
+
49
+ drop_test_db
50
+
51
+ end
@@ -20,5 +20,9 @@ describe Insulin::Week do
20
20
  w.average_glucose.should_not == nil
21
21
  end
22
22
 
23
+ it "should say 'week commencing'" do
24
+ w.to_s.should include "week commencing"
25
+ end
26
+
23
27
  drop_test_db
24
28
  end
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.0.18
4
+ version: 0.1.0
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-10 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -168,6 +168,8 @@ files:
168
168
  - lib/insulin/day.rb
169
169
  - lib/insulin/event.rb
170
170
  - lib/insulin/mongo_handle.rb
171
+ - lib/insulin/month.rb
172
+ - lib/insulin/n_day_period.rb
171
173
  - lib/insulin/on_track/csv_file.rb
172
174
  - lib/insulin/on_track/csv_line.rb
173
175
  - lib/insulin/on_track/date.rb
@@ -180,6 +182,8 @@ files:
180
182
  - spec/day_spec.rb
181
183
  - spec/event_spec.rb
182
184
  - spec/mongo_handle_spec.rb
185
+ - spec/month_spec.rb
186
+ - spec/n_day_period_spec.rb
183
187
  - spec/on_track/csv_file_spec.rb
184
188
  - spec/on_track/csv_line_spec.rb
185
189
  - spec/on_track/date_spec.rb
@@ -216,6 +220,8 @@ test_files:
216
220
  - spec/day_spec.rb
217
221
  - spec/event_spec.rb
218
222
  - spec/mongo_handle_spec.rb
223
+ - spec/month_spec.rb
224
+ - spec/n_day_period_spec.rb
219
225
  - spec/on_track/csv_file_spec.rb
220
226
  - spec/on_track/csv_line_spec.rb
221
227
  - spec/on_track/date_spec.rb