import math
class boston:
K = 0.22
a1 = 0.02
a2 = 0.022
U0 = 1.
@classmethod
def activity(cls, t):
#p(t) = K U0 (e−α1t − e−α2t).
# where U0 is the subcutaneous-drug impulse dose in units (U), K is a constant, in dl−1, associated with the amplitude
# of the impulse response of p(t), and α1 and α2 are positive constants in min−1 (or s−1, depending on t). The latter
# three constants can all be identified from values of the peak absorption time, the peak absorption concentration, and
# the overall time of action associated with the pharmacokinetics of insulin, which depends on the the type of insulin
# used.
return cls.K*cls.U0*(math.exp(-cls.a1*t) - math.exp(-cls.a2*t))
@classmethod
def activityRolling(cls, ts):
now = len(ts)
s = 0
for t in range(0, len(ts)):
s += ts[t]*cls.activity(now-t)
return s
@classmethod
def iob(cls, t):
return ((cls.K*cls.U0)/(cls.a1*cls.a2))*(cls.a2*math.exp(-cls.a1*t) - cls.a1*math.exp(-cls.a2*t))
def printc(arr):
for a in arr:
print '\t%s,' % a
r = range(0,240, 5)
act = [boston.activity(t) for t in r]
iob = [boston.iob(t) for t in r]
printc(act)
0.0, 0.00198072220267, 0.00356663012541, 0.00481678719495, 0.00578239748955, 0.00650778685307, 0.00703126635251, 0.00738589180564, 0.00760013153584, 0.00769845311808, 0.00770183864414, 0.007628236939, 0.0074929601882, 0.00730903157386, 0.00708748975322, 0.00683765533609, 0.00656736391775, 0.00628316969227, 0.00599052320035, 0.00569392634914, 0.00539706747234, 0.00510293887253, 0.00481393899865, 0.00453196115612, 0.00425847042127, 0.00399457023178, 0.00374105994875, 0.00349848452972, 0.00326717731476, 0.00304729680581, 0.00283885821266, 0.00264176044389, 0.0024558091383, 0.00228073625832, 0.00211621670238, 0.00196188233647, 0.00181733379425, 0.00168215035183, 0.00155589814368, 0.00143813695266, 0.00132842577685, 0.00122632734971, 0.00113141176704, 0.00104325935394, 0.000961462887324, 0.000885629274022, 0.000815380770979, 0.000750355822145,