def __init__(self): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Start initialization super(CSF, self).__init__() # Define report properties self.report = reporter.getPumpReport() self.branch = ["CSF"] # Read units units = self.report.get(["Units", "Carbs"]) # In case of grams if units == "g": self.units = "g/U" # In case of exchanges elif units == "exchange": self.units = "U/exchange" # Bad units else: raise ValueError("Bad CSF units.")
def __init__(self): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Start initialization super(BG, self).__init__() # Read units self.units = reporter.getPumpReport().get(["Units", "BG"]) # Define plot y-axis default limits # mmol/L if self.units == "mmol/L": self.ylim = [0, 15] # mg/dL elif self.units == "mg/dL": self.ylim = [0, 270] # Otherwise else: raise ValueError("Bad BG units.")
def __init__(self): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Start initialization super(Bolus, self).__init__() # Define profile zero self.zero = 0 # Define units self.units = "U/h" # Define bolus delivery rate self.rate = 90.0 # Read theoretical max self.max = reporter.getPumpReport().get(["Settings", "Max Bolus"]) # Define report properties self.reportType = reporter.TreatmentsReport self.branch = ["Boluses"]
def get(self): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GET ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Info Logger.debug("Reading recent data...") # Define dates today = self.now.date() yesterday = today - datetime.timedelta(days=1) then = self.now - datetime.timedelta(hours=24) # Build net insulin profile for last 24 hours _net = net.Net() _net.build(then, self.now, False) # Format and store its data self.data["net"] = dict( zip([lib.formatTime(T) for T in _net.T], [round(y, 2) for y in _net.y])) # Get pump data self.data["pump"] = reporter.getPumpReport().get() # Get recent BGs self.data["bgs"] = reporter.getDatedEntries(reporter.BGReport, [yesterday, today], []) # Get recent boluses self.data["boluses"] = reporter.getDatedEntries( reporter.TreatmentsReport, [yesterday, today], ["Boluses"]) # Get recent IOBs self.data["iobs"] = reporter.getDatedEntries(reporter.TreatmentsReport, [yesterday, today], ["IOB"]) # Get recent history self.data["history"] = reporter.getDatedEntries( reporter.HistoryReport, [yesterday, today], []) # Get recent sensor statuses (last session) # With n = 1, only today's history report would be considered, thus + 1 self.data["statuses"] = reporter.getRecentDatedEntries( reporter.HistoryReport, self.now, ["CGM", "Sensor Statuses"], MAX_SENSOR_AGE + 1) # Get recent calibrations self.data["calibrations"] = reporter.getDatedEntries( reporter.HistoryReport, [yesterday, today], ["CGM", "Calibrations"]) # Get recent errors self.data["errors"] = reporter.getDatedEntries(reporter.ErrorsReport, [today], [])
def buildProfiles(self, now, dt=5.0 / 60.0): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ BUILDPROFILES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dt: step size """ # Get DIA DIA = reporter.getPumpReport().get(["Settings", "DIA"]) # Define PIA (peak of insulin action) PIA = 1.25 # Define past/future reference times past = now - datetime.timedelta(hours=DIA) future = now + datetime.timedelta(hours=DIA) # Instanciate profiles self.profiles = { "IDC": idc.ExponentialIDC(DIA, PIA), "Basal": basal.Basal(), "Net": net.Net(), "BGTargets": targets.BGTargets(), "FutureISF": isf.FutureISF(), "FutureCSF": csf.FutureCSF(), "PastIOB": iob.PastIOB(), "FutureIOB": iob.FutureIOB(), "PastBG": bg.PastBG(), "FutureBG": bg.FutureBG() } # Build net insulin profile self.profiles["Net"].build(past, now) # Build past profiles self.profiles["Basal"].build(past, now) self.profiles["PastIOB"].build(past, now) self.profiles["PastBG"].build(past, now) # Build daily profiles self.profiles["BGTargets"].build(now, future) self.profiles["FutureISF"].build(now, future) #self.profiles["FutureCSF"].build(now, future) # Build future profiles self.profiles["FutureIOB"].build(self.profiles["Net"], self.profiles["IDC"], dt) self.profiles["FutureBG"].build(self.profiles["PastBG"], self.profiles["Net"], self.profiles["IDC"], self.profiles["FutureISF"], dt)
def __init__(self): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Start initialization super(BGTargets, self).__init__() # Define report properties self.report = reporter.getPumpReport() self.branch = ["BG Targets"] # Read units self.units = self.report.get(["Units", "BG"])
def __init__(self, profile="Standard"): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Start initialization super(Basal, self).__init__() # Define units self.units = "U/h" # Define report properties self.report = reporter.getPumpReport() self.branch = ["Basal Profile (" + profile + ")"] # Read theoretical max self.max = self.report.get(["Settings", "Max Basal"])
def __init__(self, pump): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Initialize power component super(Power, self).__init__(pump) # Define default session length (m) self.session = 10 # Instanciate corresponding command self.command = commands.Power(pump) # Define report self.report = reporter.getPumpReport()
def main(): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Get current time now = datetime.datetime.now() # Get IDC DIA = reporter.getPumpReport().get(["Settings", "DIA"]) PIA = 1.25 IDC = idc.ExponentialIDC(DIA, PIA) # Define timespan for autotune (h) t = 24 # Run analyze and plot results compareExpectedVsObservedBGDeltas(now, t, IDC)
def plotInsulinActivity(): """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PLOTINSULINACTIVITY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ # Get current time now = datetime.datetime.now() # Read DIA DIA = reporter.getPumpReport().get(["Settings", "DIA"]) # Define timestep (h) dt = 5 / 60. # Compute number of steps n = int(DIA / dt) # Generate time axis for all IOBs t = np.linspace(DIA * 3600, 0, 500) T = np.linspace(dt, DIA, n) # Convert time axis to hours t /= 3600.0 # FIXME # Build profiles manually # Build net insulin profile walsh = idc.WalshIDC(DIA) iob = FutureIOB() bg = FutureBG() net = Net() # Initialize plot mpl.rc("font", size=11, family="Ubuntu") plt.figure(0, figsize=(10, 8)) plt.subplot(111) # Define plot title plt.title("Insulin Decay Over Time (DIA = " + str(DIA) + ")", weight="semibold") # Define plot axis plt.xlabel("Time (h)", weight="semibold") plt.ylabel("Insulin Activity (-)", weight="semibold") # Add Walsh IDC to plot plt.plot(-t, walsh.f(t), ls="-", lw=1.5, c="red", label="Walsh IDC") # Add insulin net profile to plot plt.step(-net.T, np.append(0, net.y[:-1]), ls="-", lw=1.5, c="black", label="Net Profile") # Add future IOBs to plot plt.plot(T, iob.y, ls="-", lw=1.5, c="purple", label="Future IOB") # Add eventual BGs to plot plt.plot(T, bg.y, ls="-", lw=1.5, c="blue", label="Eventual BG") # Define plot legend legend = plt.legend(title="Legend", loc=0, borderaxespad=1.5, numpoints=1, markerscale=2) # Style legend plt.setp(legend.get_title(), fontweight="semibold") # Tighten up plt.tight_layout() # Show plot plt.show()