lita-diabetter 0.1.1.alpha.18 → 0.1.1.alpha.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lita/handlers/diabetter.rb +42 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2f4db00d5949f1b8a71c565ed3195778f56efd0
|
4
|
+
data.tar.gz: 07ff8c8bca25a27b6a5d7179dbf0c29dd7f0032d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75913b24887283dbd85cd25f8af42098651513c5bdb72f207f3cad03aaad8fa022a045b53cfa863522348fd4e857e27c0b9754ff84300dffc485fcfbc84ded91
|
7
|
+
data.tar.gz: 6df2274cc8c9fadfa32411145e4f00ed898966f0943a57901433ab48849ef082629b08ba58798257f82443346b744aae0df671d933c0e6fa084da21a973bfe97
|
@@ -2,6 +2,9 @@ module Lita
|
|
2
2
|
module Handlers
|
3
3
|
class Diabetter < Handler
|
4
4
|
@@conversion_ratio = 18.0182
|
5
|
+
@@lower = 25.0 # Lower limit for mmol/L - mg/dL cutoff
|
6
|
+
@@upper = 50.0 # Upper limit for mmol/L - mg/dL cutoff
|
7
|
+
|
5
8
|
route(/(?:^|_)(\d{1,3}|\d{1,2}\.\d+)(?:$|_)/, :convert, command: false, help: {
|
6
9
|
'<number>' => 'Convert glucose between mass/molar concentration units.',
|
7
10
|
'_<number>_' => 'Convert glucose between mass/molar concentration units inline. E.g "I started at _125_ today"'
|
@@ -18,13 +21,10 @@ module Lita
|
|
18
21
|
if response.message.body.match(URI.regexp(%w(http https))).nil?
|
19
22
|
input = response.matches[0][0]
|
20
23
|
Lita.logger.debug('Converting BG for input "' + input + '"')
|
21
|
-
lower = 25.0
|
22
|
-
upper = 50.0
|
23
|
-
|
24
24
|
|
25
|
-
if input.to_f < lower
|
25
|
+
if input.to_f < @@lower
|
26
26
|
response.reply("#{input} mmol/L is #{mmol_to_mgdl(input).to_s} mg/dL")
|
27
|
-
elsif input.to_f >= lower && input.to_f < upper
|
27
|
+
elsif input.to_f >= @@lower && input.to_f < @@upper
|
28
28
|
mmol = mgdl_to_mmol(input).to_s
|
29
29
|
mgdl = mmol_to_mgdl(input).to_s
|
30
30
|
|
@@ -42,26 +42,52 @@ module Lita
|
|
42
42
|
def estimate_a1c(response)
|
43
43
|
input = response.matches[0][0]
|
44
44
|
Lita.logger.debug('Estimating a1c for input "' + input + '"')
|
45
|
-
mmol = 0
|
46
|
-
mgdl = 0
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
mmol = mgdl_to_mmol(mgdl)
|
51
|
-
else
|
46
|
+
|
47
|
+
if input.to_f < @@lower
|
52
48
|
mmol = input.to_f.round(1)
|
53
49
|
mgdl = mmol_to_mgdl(mmol)
|
50
|
+
|
51
|
+
type = 'mmol'
|
52
|
+
elsif input.to_f >= @@lower && input.to_f < @@upper
|
53
|
+
mmol = mgdl_to_mmol(input.to_f).round(1)
|
54
|
+
mgdl = mmol_to_mgdl(input.to_f)
|
55
|
+
|
56
|
+
type = 'unknown'
|
57
|
+
else
|
58
|
+
mgdl = input.to_i
|
59
|
+
mmol = mgdl_to_mmol(mgdl)
|
60
|
+
|
61
|
+
type = 'mgdl'
|
54
62
|
end
|
55
63
|
|
56
64
|
dcct = mgdl_to_dcct(mgdl)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
ifcc = dcct_to_ifcc(dcct).round(0).to_s
|
66
|
+
|
67
|
+
|
68
|
+
if type == 'unknown'
|
69
|
+
reply = "*I'm not sure if you entered mmol/L or mg/dL, so I'll give you both*\n"
|
70
|
+
reply += make_average_sentence('mmol', mmol, dcct.to_s, ifcc) + "\n"
|
71
|
+
reply += make_average_sentence('mgdl', mgdl, dcct.to_s, ifcc)
|
72
|
+
elsif type=='mmol'
|
73
|
+
reply = make_average_sentence('mmol', mmol, dcct.to_s, ifcc)
|
74
|
+
else
|
75
|
+
reply = make_average_sentence('mgdl', mgdl, dcct.to_s, ifcc)
|
76
|
+
end
|
77
|
+
|
62
78
|
response.reply(reply)
|
63
79
|
end
|
64
80
|
|
81
|
+
def make_average_sentence(type, value, dcct, ifcc)
|
82
|
+
if type == 'mmol'
|
83
|
+
string = "An average of **#{value} mmol/L** is about "
|
84
|
+
elsif type == 'mgdl'
|
85
|
+
string = "An average of **#{value} mg/dL** is about "
|
86
|
+
end
|
87
|
+
|
88
|
+
string += "**#{dcct}%** (DCCT) or **#{ifcc} mmol/mol** (IFCC)"
|
89
|
+
end
|
90
|
+
|
65
91
|
def estimate_average_from_a1c(response)
|
66
92
|
input = response.matches[0][0]
|
67
93
|
Lita.logger.debug('Converting a1c to BG for input "' + input + '"')
|