insulin 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/TODO.md +1 -2
- data/bin/insulin +19 -15
- data/lib/insulin/pdf.rb +28 -4
- data/lib/insulin/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/TODO.md
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
* Food - combine available carbs data with meds object? or other way around?
|
5
5
|
* Estimated HbA1c?
|
6
6
|
* https://github.com/svenfuchs/gem-release - put these into rake tasks?
|
7
|
-
* empty time periods should return "nothing known"
|
8
7
|
* https://github.com/prawnpdf/prawn
|
9
8
|
* Fully detailed output showing latest HbA1c, BP, etc
|
10
9
|
* Work out Google Drive API
|
@@ -13,4 +12,4 @@
|
|
13
12
|
* Somehow include cholesterol
|
14
13
|
* Test the insulin executable
|
15
14
|
* "Latest weight, change since last, overall trend" &c
|
16
|
-
* Colours for low/good/high BG
|
15
|
+
* Colours for low/good/high BG - gradient of colours depending on distance from ideal?
|
data/bin/insulin
CHANGED
@@ -54,22 +54,26 @@ module Insulin
|
|
54
54
|
desc "pdf RECIPIENT",
|
55
55
|
"generate a PDF for the last week and mail to RECIPIENT"
|
56
56
|
def pdf recipient = nil
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
begin
|
58
|
+
date = (Time.new - (7 * 86400)).strftime "%F"
|
59
|
+
outfile = "/tmp/insulin.pdf"
|
60
|
+
p = Insulin::Pdf.new Insulin::Week.new(date, @@mongo), outfile
|
61
|
+
p.render
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
63
|
+
require 'pony'
|
64
|
+
Pony.mail(
|
65
|
+
:to => recipient,
|
66
|
+
:from => "insulin@cruft.co",
|
67
|
+
:subject => "insulin report",
|
68
|
+
:body => "Attached",
|
69
|
+
:attachments => {
|
70
|
+
"insulin.pdf" => File.read(outfile)
|
71
|
+
},
|
72
|
+
:charset => 'utf-8'
|
73
|
+
)
|
74
|
+
rescue ArgumentError
|
75
|
+
puts "RECIPIENT is required"
|
76
|
+
end
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
data/lib/insulin/pdf.rb
CHANGED
@@ -6,6 +6,7 @@ module Insulin
|
|
6
6
|
def initialize period, outfile
|
7
7
|
@period = period
|
8
8
|
@outfile = outfile
|
9
|
+
@default_colour = "007700"
|
9
10
|
|
10
11
|
@pdf = Prawn::Document.new
|
11
12
|
@pdf.font "Courier"
|
@@ -35,6 +36,13 @@ module Insulin
|
|
35
36
|
|
36
37
|
@pdf.font_size 8
|
37
38
|
|
39
|
+
colour = @default_colour
|
40
|
+
if @period.average_glucose < 4
|
41
|
+
colour = 'FF0000'
|
42
|
+
end
|
43
|
+
if @period.average_glucose > 8
|
44
|
+
colour = '0000FF'
|
45
|
+
end
|
38
46
|
@pdf.table [
|
39
47
|
[
|
40
48
|
"latest hba1c (from %s)" % [
|
@@ -50,7 +58,8 @@ module Insulin
|
|
50
58
|
@period.descriptor,
|
51
59
|
@period.start_date
|
52
60
|
],
|
53
|
-
"%0.2f%s" % [
|
61
|
+
"<color rgb='%s'>%0.2f%s</color>" % [
|
62
|
+
colour,
|
54
63
|
@period.average_glucose,
|
55
64
|
@period[0].glucose_units
|
56
65
|
]
|
@@ -68,7 +77,8 @@ module Insulin
|
|
68
77
|
],
|
69
78
|
:cell_style => {
|
70
79
|
:border_color => "333333",
|
71
|
-
:border_width => 1
|
80
|
+
:border_width => 1,
|
81
|
+
:inline_format => true
|
72
82
|
}
|
73
83
|
@pdf.text "\n"
|
74
84
|
@pdf.text "\n"
|
@@ -88,13 +98,26 @@ module Insulin
|
|
88
98
|
@grid = []
|
89
99
|
@pdf.font_size 8
|
90
100
|
d["all"].each do |e|
|
101
|
+
colour = "000000"
|
91
102
|
if e.simple?
|
103
|
+
if e["type"] == "glucose"
|
104
|
+
colour = @default_colour
|
105
|
+
if e["value"] < 4
|
106
|
+
colour = "0000FF"
|
107
|
+
end
|
108
|
+
if e["value"] > 8
|
109
|
+
colour = "FF0000"
|
110
|
+
end
|
111
|
+
end
|
92
112
|
@grid << [
|
93
113
|
e["short_time"],
|
94
114
|
e["tag"],
|
95
115
|
e["type"],
|
96
116
|
e["subtype"],
|
97
|
-
|
117
|
+
"<color rgb='%s'>%s</color>" % [
|
118
|
+
colour,
|
119
|
+
e["formatted_value_with_units"]
|
120
|
+
]
|
98
121
|
]
|
99
122
|
end
|
100
123
|
end
|
@@ -114,7 +137,8 @@ module Insulin
|
|
114
137
|
],
|
115
138
|
:cell_style => {
|
116
139
|
:border_color => "333333",
|
117
|
-
:border_width => 1
|
140
|
+
:border_width => 1,
|
141
|
+
:inline_format => true
|
118
142
|
}
|
119
143
|
@pdf.text "\n"
|
120
144
|
@pdf.text "\n"
|
data/lib/insulin/version.rb
CHANGED