#!/usr/bin/env python # coding: utf-8 # In[2]: import math # In[8]: 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 # In[6]: r = range(0,240, 5) act = [boston.activity(t) for t in r] iob = [boston.iob(t) for t in r] # In[10]: printc(act) # In[ ]: