insulin 0.1.10 → 0.1.11

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.
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- insulin (0.1.9)
12
+ insulin (0.1.10)
13
13
  bson_ext
14
14
  ffi
15
15
  mongo
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?
@@ -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
- date = (Time.new - (7 * 86400)).strftime "%F"
58
- outfile = "/tmp/insulin.pdf"
59
- p = Insulin::Pdf.new Insulin::Week.new(date, @@mongo), outfile
60
- p.render
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
- 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
- )
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
@@ -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
- e["formatted_value_with_units"]
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"
@@ -1,5 +1,5 @@
1
1
  module Insulin
2
2
 
3
3
  # Current version
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.11"
5
5
  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.1.10
4
+ version: 0.1.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: