insulin 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +31 -2
- data/README.md +6 -0
- data/TODO.md +1 -1
- data/bin/insulin +31 -6
- data/conf/insulin_dev.yaml +7 -4
- data/insulin.gemspec +2 -0
- data/lib/insulin.rb +1 -0
- data/lib/insulin/day.rb +5 -3
- data/lib/insulin/event.rb +23 -10
- data/lib/insulin/n_day_period.rb +2 -0
- data/lib/insulin/pdf.rb +141 -0
- data/lib/insulin/version.rb +1 -1
- data/spec/day_spec.rb +2 -2
- data/spec/pdf_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -0
- metadata +36 -1
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,15 +1,26 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/prawnpdf/prawn.git
|
3
|
+
revision: baa6e80b1a11efac91a0160dfab257744bbf9bde
|
4
|
+
specs:
|
5
|
+
prawn (1.0.0.rc1)
|
6
|
+
pdf-reader (>= 0.9.0)
|
7
|
+
ttfunk (~> 1.0.3)
|
8
|
+
|
1
9
|
PATH
|
2
10
|
remote: .
|
3
11
|
specs:
|
4
|
-
insulin (0.1.
|
12
|
+
insulin (0.1.2)
|
5
13
|
bson_ext
|
6
14
|
ffi
|
7
15
|
mongo
|
16
|
+
pony
|
17
|
+
prawn
|
8
18
|
thor
|
9
19
|
|
10
20
|
GEM
|
11
21
|
remote: https://rubygems.org/
|
12
22
|
specs:
|
23
|
+
Ascii85 (1.0.1)
|
13
24
|
aruba (0.4.11)
|
14
25
|
childprocess (>= 0.2.3)
|
15
26
|
cucumber (>= 1.1.1)
|
@@ -31,9 +42,21 @@ GEM
|
|
31
42
|
gem-release (0.3.1)
|
32
43
|
gherkin (2.11.1)
|
33
44
|
json (>= 1.4.6)
|
45
|
+
i18n (0.6.0)
|
34
46
|
json (1.7.3)
|
47
|
+
mail (2.4.4)
|
48
|
+
i18n (>= 0.4.0)
|
49
|
+
mime-types (~> 1.16)
|
50
|
+
treetop (~> 1.4.8)
|
51
|
+
mime-types (1.19)
|
35
52
|
mongo (1.6.4)
|
36
53
|
bson (~> 1.6.4)
|
54
|
+
pdf-reader (1.1.1)
|
55
|
+
Ascii85 (~> 1.0.0)
|
56
|
+
ruby-rc4
|
57
|
+
polyglot (0.3.3)
|
58
|
+
pony (1.4)
|
59
|
+
mail (> 2.0)
|
37
60
|
rspec (2.10.0)
|
38
61
|
rspec-core (~> 2.10.0)
|
39
62
|
rspec-expectations (~> 2.10.0)
|
@@ -42,7 +65,12 @@ GEM
|
|
42
65
|
rspec-expectations (2.10.0)
|
43
66
|
diff-lcs (~> 1.1.3)
|
44
67
|
rspec-mocks (2.10.1)
|
45
|
-
|
68
|
+
ruby-rc4 (0.1.5)
|
69
|
+
thor (0.15.4)
|
70
|
+
treetop (1.4.10)
|
71
|
+
polyglot
|
72
|
+
polyglot (>= 0.3.1)
|
73
|
+
ttfunk (1.0.3)
|
46
74
|
|
47
75
|
PLATFORMS
|
48
76
|
ruby
|
@@ -52,4 +80,5 @@ DEPENDENCIES
|
|
52
80
|
cucumber
|
53
81
|
gem-release
|
54
82
|
insulin!
|
83
|
+
prawn!
|
55
84
|
rspec (~> 2.6)
|
data/README.md
CHANGED
@@ -51,6 +51,12 @@ Example:
|
|
51
51
|
|
52
52
|
average glucose: 5.46 mmol/L
|
53
53
|
|
54
|
+
A weekly PDF summary can be generated and mailed out
|
55
|
+
|
56
|
+
insulin pdf you@yourdmomain.com
|
57
|
+
|
58
|
+
The PDF class is currently a bit hacky, I'm still learning the excellent (prawn gem)[https://github.com/prawnpdf/prawn]
|
59
|
+
|
54
60
|
You can also run the tests, if you're into that sort of thing:
|
55
61
|
|
56
62
|
bundle exec rspec
|
data/TODO.md
CHANGED
@@ -9,8 +9,8 @@
|
|
9
9
|
* Fully detailed output showing latest HbA1c, BP, etc
|
10
10
|
* Work out Google Drive API
|
11
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
12
|
* Number of tests &c per time period
|
14
13
|
* Somehow include cholesterol
|
15
14
|
* Test the insulin executable
|
16
15
|
* "Latest weight, change since last, overall trend" &c
|
16
|
+
* Colours for low/good/high BG
|
data/bin/insulin
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
require 'insulin'
|
4
4
|
require 'thor'
|
5
5
|
|
@@ -7,13 +7,15 @@ module Insulin
|
|
7
7
|
class I < Thor
|
8
8
|
@@mongo = Insulin::MongoHandle.new ({"database" => "insulin"})
|
9
9
|
|
10
|
-
desc "ingest FILE",
|
10
|
+
desc "ingest FILE",
|
11
|
+
"ingest OnTrack CSV export FILE"
|
11
12
|
def ingest file
|
12
13
|
csv = Insulin::OnTrack::CsvFile.new file
|
13
14
|
csv.save_events @@mongo
|
14
15
|
end
|
15
16
|
|
16
|
-
desc "day DATE",
|
17
|
+
desc "day DATE",
|
18
|
+
"show stats for day DATE (default is today)"
|
17
19
|
def day date = nil
|
18
20
|
if not date
|
19
21
|
require 'time'
|
@@ -27,17 +29,19 @@ module Insulin
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
desc "week DATE",
|
32
|
+
desc "week DATE",
|
33
|
+
"show stats for week commencing DATE (defaults to previous 7 days)"
|
31
34
|
def week date = nil
|
32
35
|
if not date
|
33
36
|
require 'time'
|
34
|
-
date = (Time.new - (
|
37
|
+
date = (Time.new - (7 * 86400)).strftime "%F"
|
35
38
|
end
|
36
39
|
w = Insulin::Week.new date, @@mongo
|
37
40
|
puts w.to_s
|
38
41
|
end
|
39
42
|
|
40
|
-
desc "month DATE",
|
43
|
+
desc "month DATE",
|
44
|
+
"show stats for 30-day period commencing DATE (defaults to previous 30 days)"
|
41
45
|
def month date = nil
|
42
46
|
if not date
|
43
47
|
require 'time'
|
@@ -46,6 +50,27 @@ module Insulin
|
|
46
50
|
m = Insulin::Month.new date, @@mongo
|
47
51
|
puts m.to_s
|
48
52
|
end
|
53
|
+
|
54
|
+
desc "pdf RECIPIENT",
|
55
|
+
"generate a PDF for the last week and mail to RECIPIENT"
|
56
|
+
def pdf recipient = nil
|
57
|
+
date = (Time.new - (7 * 86400)).strftime "%F"
|
58
|
+
outfile = "/vagrant_data/insulin.pdf"
|
59
|
+
p = Insulin::Pdf.new Insulin::Week.new(date, @@mongo), outfile
|
60
|
+
p.render
|
61
|
+
|
62
|
+
# require 'pony'
|
63
|
+
# Pony.mail(
|
64
|
+
# :to => recipient,
|
65
|
+
# :from => "insulin@cruft.co",
|
66
|
+
# :subject => "insulin report",
|
67
|
+
# :body => "Attached",
|
68
|
+
# :attachments => {
|
69
|
+
# "insulin.pdf" => File.read(outfile)
|
70
|
+
# },
|
71
|
+
# :charset => 'utf-8'
|
72
|
+
# )
|
73
|
+
end
|
49
74
|
end
|
50
75
|
end
|
51
76
|
|
data/conf/insulin_dev.yaml
CHANGED
data/insulin.gemspec
CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency "mongo"
|
22
22
|
gem.add_dependency "bson_ext"
|
23
23
|
gem.add_dependency "ffi"
|
24
|
+
gem.add_dependency "prawn"
|
25
|
+
gem.add_dependency "pony"
|
24
26
|
|
25
27
|
gem.add_development_dependency "rspec", "~> 2.6"
|
26
28
|
gem.add_development_dependency "cucumber"
|
data/lib/insulin.rb
CHANGED
data/lib/insulin/day.rb
CHANGED
@@ -2,7 +2,7 @@ require 'insulin'
|
|
2
2
|
|
3
3
|
module Insulin
|
4
4
|
class Day < Hash
|
5
|
-
attr_reader :glucose_units
|
5
|
+
attr_reader :glucose_units, :date, :day
|
6
6
|
|
7
7
|
def initialize date, mongo
|
8
8
|
@date = date
|
@@ -27,6 +27,7 @@ module Insulin
|
|
27
27
|
end
|
28
28
|
|
29
29
|
self["all"] << ev
|
30
|
+
@day = self["all"][0]["day"]
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -80,8 +81,9 @@ module Insulin
|
|
80
81
|
s << "\n"
|
81
82
|
|
82
83
|
self["all"].each do |e|
|
83
|
-
if ["breakfast", "lunch", "dinner", "bedtime"].include? e["tag"] and
|
84
|
-
["medication", "glucose"].include? e["type"]
|
84
|
+
# if ["breakfast", "lunch", "dinner", "bedtime"].include? e["tag"] and
|
85
|
+
# ["medication", "glucose"].include? e["type"]
|
86
|
+
if e.simple?
|
85
87
|
s << " "
|
86
88
|
s << e.simple
|
87
89
|
s << "\n"
|
data/lib/insulin/event.rb
CHANGED
@@ -8,14 +8,23 @@ module Insulin
|
|
8
8
|
class Event < Hash
|
9
9
|
|
10
10
|
@@units = {
|
11
|
-
"glucose" => "mmol/L",
|
11
|
+
"glucose" => " mmol/L",
|
12
12
|
"medication" => "x10^-5 L",
|
13
13
|
"weight" => "kg",
|
14
|
-
"exercise" => "minutes",
|
15
|
-
"blood pressure" => "sp/df",
|
14
|
+
"exercise" => " minutes",
|
15
|
+
"blood pressure" => " sp/df",
|
16
16
|
"hba1c" => "%"
|
17
17
|
}
|
18
18
|
|
19
|
+
@@formats = {
|
20
|
+
"glucose" => "%0.1f",
|
21
|
+
"medication" => "%d",
|
22
|
+
"weight" => "%0.1f",
|
23
|
+
"exercise" => "%d",
|
24
|
+
"blood pressure" => "%s",
|
25
|
+
"hba1c" => "%0.1f",
|
26
|
+
}
|
27
|
+
|
19
28
|
# An event before this time is considered part of the previous day. Because
|
20
29
|
# sometimes, we stay up late
|
21
30
|
@@cut_off_time = "04:00"
|
@@ -25,6 +34,15 @@ module Insulin
|
|
25
34
|
self.update h
|
26
35
|
|
27
36
|
self["units"] = @@units[self["type"]]
|
37
|
+
self["formatted_value_with_units"] = "#{@@formats[self['type']]}%s" % [
|
38
|
+
self["value"],
|
39
|
+
self["units"]
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
def simple?
|
44
|
+
["breakfast", "lunch", "dinner", "bedtime"].include? self["tag"] and
|
45
|
+
["medication", "glucose"].include? self["type"]
|
28
46
|
end
|
29
47
|
|
30
48
|
# Save the event to Mongo via mongo_handle
|
@@ -61,17 +79,12 @@ module Insulin
|
|
61
79
|
end
|
62
80
|
|
63
81
|
def simple
|
64
|
-
|
65
|
-
if self["value"].is_a? String
|
66
|
-
value_format = "%6s"
|
67
|
-
end
|
68
|
-
s = "%s | %-15s | %-14s | %-13s | #{value_format} %s" % [
|
82
|
+
s = "%s | %-15s | %-14s | %-13s | %s" % [
|
69
83
|
self["short_time"],
|
70
84
|
self["tag"],
|
71
85
|
self["type"],
|
72
86
|
self["subtype"],
|
73
|
-
self["
|
74
|
-
self["units"]
|
87
|
+
self["formatted_value_with_units"]
|
75
88
|
]
|
76
89
|
|
77
90
|
s
|
data/lib/insulin/n_day_period.rb
CHANGED
data/lib/insulin/pdf.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'insulin'
|
2
|
+
require 'prawn'
|
3
|
+
|
4
|
+
module Insulin
|
5
|
+
class Pdf
|
6
|
+
def initialize period, outfile
|
7
|
+
@period = period
|
8
|
+
@outfile = outfile
|
9
|
+
|
10
|
+
@pdf = Prawn::Document.new
|
11
|
+
@pdf.font "Courier"
|
12
|
+
@pdf.font_size 12
|
13
|
+
|
14
|
+
@pdf.formatted_text [{
|
15
|
+
:text => "insulin",
|
16
|
+
:styles => [
|
17
|
+
:bold
|
18
|
+
],
|
19
|
+
:color => "AA0000",
|
20
|
+
:size => 16
|
21
|
+
},
|
22
|
+
{
|
23
|
+
:text => " report for %s beginning %s" % [
|
24
|
+
@period.descriptor,
|
25
|
+
@period.start_date
|
26
|
+
]
|
27
|
+
}]
|
28
|
+
|
29
|
+
s = " report for %s beginning %s" % [
|
30
|
+
@period.descriptor,
|
31
|
+
@period.start_date
|
32
|
+
]
|
33
|
+
@pdf.text "\n"
|
34
|
+
@pdf.text "\n"
|
35
|
+
|
36
|
+
@pdf.font_size 8
|
37
|
+
|
38
|
+
@pdf.table [
|
39
|
+
[
|
40
|
+
"latest hba1c (from %s)" % [
|
41
|
+
@period.hba1c["date"],
|
42
|
+
],
|
43
|
+
"%0.1f%s" % [
|
44
|
+
@period.hba1c["value"],
|
45
|
+
@period.hba1c["units"]
|
46
|
+
]
|
47
|
+
],
|
48
|
+
[
|
49
|
+
"average blood glucose for %s commencing %s" % [
|
50
|
+
@period.descriptor,
|
51
|
+
@period.start_date
|
52
|
+
],
|
53
|
+
"%0.2f%s" % [
|
54
|
+
@period.average_glucose,
|
55
|
+
@period[0].glucose_units
|
56
|
+
]
|
57
|
+
]
|
58
|
+
],
|
59
|
+
:position => :center,
|
60
|
+
:column_widths => [
|
61
|
+
300,
|
62
|
+
200
|
63
|
+
],
|
64
|
+
:row_colors =>
|
65
|
+
[
|
66
|
+
"F0F0F0",
|
67
|
+
"D0D0D0"
|
68
|
+
],
|
69
|
+
:cell_style => {
|
70
|
+
:border_color => "333333",
|
71
|
+
:border_width => 1
|
72
|
+
}
|
73
|
+
@pdf.text "\n"
|
74
|
+
@pdf.text "\n"
|
75
|
+
@pdf.text "\n"
|
76
|
+
|
77
|
+
@period.each do |d|
|
78
|
+
@grid = []
|
79
|
+
@grid << [{
|
80
|
+
:content => "%s (%s)" % [
|
81
|
+
d.date,
|
82
|
+
d.day
|
83
|
+
],
|
84
|
+
:colspan => 5
|
85
|
+
}]
|
86
|
+
|
87
|
+
d["all"].each do |e|
|
88
|
+
if e.simple?
|
89
|
+
@grid << [
|
90
|
+
e["short_time"],
|
91
|
+
e["tag"],
|
92
|
+
e["type"],
|
93
|
+
e["subtype"],
|
94
|
+
e["formatted_value_with_units"]
|
95
|
+
]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
@pdf.table @grid,
|
99
|
+
:position => :center,
|
100
|
+
:column_widths => [
|
101
|
+
100,
|
102
|
+
100,
|
103
|
+
100,
|
104
|
+
100,
|
105
|
+
100
|
106
|
+
],
|
107
|
+
:row_colors =>
|
108
|
+
[
|
109
|
+
"F0F0F0",
|
110
|
+
"D0D0D0"
|
111
|
+
],
|
112
|
+
:cell_style => {
|
113
|
+
:border_color => "333333",
|
114
|
+
:border_width => 1
|
115
|
+
},
|
116
|
+
:header => :true
|
117
|
+
@pdf.text "\n"
|
118
|
+
@pdf.text "\n"
|
119
|
+
@pdf.text "\n"
|
120
|
+
end
|
121
|
+
|
122
|
+
@pdf.stroke_horizontal_rule
|
123
|
+
@pdf.text "\n"
|
124
|
+
@pdf.text "\n"
|
125
|
+
@pdf.text "\n"
|
126
|
+
@pdf.formatted_text [{
|
127
|
+
:text => "insulin",
|
128
|
+
:color => "007700",
|
129
|
+
:link => "http://pikesley.github.com/insulin/"
|
130
|
+
|
131
|
+
},
|
132
|
+
{
|
133
|
+
:text => " written and maintained by Sam Pikesley"
|
134
|
+
}]
|
135
|
+
end
|
136
|
+
|
137
|
+
def render
|
138
|
+
@pdf.render_file @outfile
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/lib/insulin/version.rb
CHANGED
data/spec/day_spec.rb
CHANGED
@@ -29,9 +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 | dinner | medication | humalog |
|
32
|
+
d.to_s.should include "19:07 | dinner | medication | humalog | 6x10^-5 L"
|
33
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 | |
|
34
|
+
d.to_s.should include "15:46 | | hba1c | | 8.8%"
|
35
35
|
end
|
36
36
|
|
37
37
|
it "minimal display should be correct" do
|
data/spec/pdf_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'insulin'
|
2
|
+
require 'spec_helper.rb'
|
3
|
+
|
4
|
+
describe Insulin::Pdf do
|
5
|
+
config = Insulin::Config.new "conf/insulin_dev.yaml"
|
6
|
+
o = config.get_section "outputs"
|
7
|
+
|
8
|
+
load_test_db
|
9
|
+
|
10
|
+
p = Insulin::Pdf.new Insulin::Week.new("2012-06-29", @mongo), o["pdf_file"]
|
11
|
+
|
12
|
+
it "should generate a pdf" do
|
13
|
+
p.render
|
14
|
+
File.should exist o["pdf_file"]
|
15
|
+
end
|
16
|
+
|
17
|
+
drop_test_db
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,6 +75,38 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: prawn
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pony
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
78
110
|
- !ruby/object:Gem::Dependency
|
79
111
|
name: rspec
|
80
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,6 +207,7 @@ files:
|
|
175
207
|
- lib/insulin/on_track/date.rb
|
176
208
|
- lib/insulin/on_track/note.rb
|
177
209
|
- lib/insulin/on_track/note_set.rb
|
210
|
+
- lib/insulin/pdf.rb
|
178
211
|
- lib/insulin/version.rb
|
179
212
|
- lib/insulin/week.rb
|
180
213
|
- scripts/build.sh
|
@@ -189,6 +222,7 @@ files:
|
|
189
222
|
- spec/on_track/date_spec.rb
|
190
223
|
- spec/on_track/note_set_spec.rb
|
191
224
|
- spec/on_track/note_spec.rb
|
225
|
+
- spec/pdf_spec.rb
|
192
226
|
- spec/spec_helper.rb
|
193
227
|
- spec/week_spec.rb
|
194
228
|
homepage: http://pikesley.github.com/insulin/
|
@@ -227,5 +261,6 @@ test_files:
|
|
227
261
|
- spec/on_track/date_spec.rb
|
228
262
|
- spec/on_track/note_set_spec.rb
|
229
263
|
- spec/on_track/note_spec.rb
|
264
|
+
- spec/pdf_spec.rb
|
230
265
|
- spec/spec_helper.rb
|
231
266
|
- spec/week_spec.rb
|