示例#1
0
 def decode (data):
   i = 0
   schedule = [ ]
   end = [ 0, 0, 0 ]
   none = [ 0, 0, 0x3F ]
   for i in xrange(len(data)/3):
     off = i*3
     r, z, m = data[off : off + 3]
     if [r,z,m] in [end, none]:
       break
     schedule.append(dict(i=i, minutes=m*30, start=str(lib.basal_time(m)), rate=r*.025))
   return schedule
示例#2
0
 def decode(data):
     i = 0
     schedule = []
     end = [0, 0, 0]
     none = [0, 0, 0x3F]
     for i in xrange(len(data) / 3):
         off = i * 3
         r, z, m = data[off:off + 3]
         if [r, z, m] in [end, none]:
             break
         schedule.append(dict(start=str(lib.basal_time(m)), rate=r * .025))
     return schedule
示例#3
0
 def decode_ratios (klass, data, units=0):
   schedule = [ ]
   for x in range(len(data)/ 3):
     start = x * 3
     end = start + 3
     (i, q, r) = data[start:end]
     if x > 0 and i == 0:
       break
     ratio = r/10.0
     if q:
       ratio = lib.BangInt([q, r]) / 1000.0
     schedule.append(dict(x=x, i=i, start=lib.basal_time(i), offset=i*30, q=q, ratio=ratio, r=r))
   return schedule
示例#4
0
 def decode_ratios (klass, data, units=0):
   data = data[0:(8 *2)]
   schedule = [ ]
   for x in range(len(data)/ 2):
     start = x * 2
     end = start + 2
     (i, r) = data[start:end]
     if x > 0 and i == 0:
       break
     ratio = int(r)
     if units == 2:
       ratio = r / 10.0
     schedule.append(dict(x=x, i=i, start=lib.basal_time(i), offset=i*30, ratio=ratio, r=r))
   return schedule
示例#5
0
 def getData (self):
   # isFast = data[17] == 0
   isFast = self.data[0] is 1
   data = self.data[1:1+16]
   schedule = [ ]
   for x in range(8):
     start = x * 2
     end = start + 2
     (i, sensitivity) = data[start:end]
     if x > 0 and i == 0:
       break
     schedule.append(dict(x=x, i=i, start=lib.basal_time(i), offset=i*30, sensitivity=sensitivity))
   labels = { True: 'Fast', False: 'Regular' }
   return dict(sensitivities=schedule, first=self.data[0], action_type=labels[isFast])
示例#6
0
 def getData (self):
   units = self.data[0]
   labels = { 1 : 'mg/dL', 2: 'mmol/L' }
   data = self.data[1:1+24]
   schedule = [ ]
   for x in range(8):
     start = x * 3
     end = start + 3
     (i, low, high) = data[start:end]
     if x > 0 and i == 0:
       break
     if units is 2:
       low = low / 10.0
       high = high / 10.0
     schedule.append(dict(x=x, i=i, start=lib.basal_time(i), offset=i*30, low=low, high=high))
   return dict(targets=schedule, units=labels.get(units), first=self.data[0], raw=' '.join('0x{:02x}'.format(x) for x in self.data))
示例#7
0
 def getData (self):
   # isFast = data[17] == 0
   isFast = self.data[0] is 1
   units = self.data[0]
   data = self.data[1:1+16]
   schedule = [ ]
   for x in range(8):
     start = x * 2
     end = start + 2
     (i, sensitivity) = data[start:end]
     if x > 0 and i == 0:
       break
     if units == 2:
       sensitivity = sensitivity / 10.0
     schedule.append(dict(x=x, i=i, start=lib.basal_time(i), offset=i*30, sensitivity=sensitivity))
   labels = { True: 'Fast', False: 'Regular' }
   return dict(sensitivities=schedule, first=self.data[0], units=self.UNITS.get(units))
示例#8
0
 def validate (self, data):
   i = 0
   valid = True
   last = None
   for profile in data:
     start = str(lib.basal_time(profile['minutes']/30))
     if 'rate' in profile and profile['i'] == i and start == profile['start']:
       if i == 0:
         if profile['minutes'] != 0:
           template = "{name} first scheduled item should be 00:00:00."
           msg = template.format(name=self.__class__.__name__)
           msg = "%s\n%s" % (msg, profile)
           raise BadResponse(msg)
       if last and profile['minutes'] <= last['minutes']:
         template = "{name} next scheduled item occurs before previous"
         msg = template.format(name=self.__class__.__name__)
         msg = "%s\n%s" % (msg, profile)
         raise BadResponse(msg)
     else:
       bad_profile = """Current profile: %s""" % (profile)
       template = """{bad_profile} Found in response to {name}
         i: {i} matches? {matches_i}
         our calcstart: {start}
         profile start: {profile_start}
         has a rate: {has_rate}
         start matches: {matches_start}
       """
       raise BadResponse(template.format(bad_profile=bad_profile
                 , name=self.__class__.__name__
                 , start=start
                 , profile_start=profile['start']
                 , has_rate= 'rate' in profile
                 , matches_i= profile['i'] == i
                 , matches_start=  start == profile['start']
                 , i=i))
       valid = False
     last = profile
     i = i + 1
   return True
示例#9
0
 def decode(data):
   units = data[0]
   data = data[1:1+16]
   schedule = [ ]
   for x in range(8):
     # Each entry in the sensitivity schedule consists of 2 bytes.
     # The first byte is used as follows:
     #   - the highest bit is 0
     #   - the next highest bit is an overflow bit that is set when the sensitivity is > 255
     #   - the low 6 bits are an index from 0-47 representing the scheduled time
     # The second byte is the insulin sensitivity. When the sensitivity is >255, the overflow bit above will be set and this byte will
     # show the remainder (e.g. for 256 the overflow bit will be set and this byte will be 0).
     start = x * 2
     i = data[start] & 0x3F
     sensitivity_overflow = (data[start] & 0x40) << 2
     sensitivity = data[start+1] + sensitivity_overflow
     if x > 0 and i == 0:
       break
     if units == 2:
       sensitivity = sensitivity / 10.0
     schedule.append(dict(x=x, i=i, start=str(lib.basal_time(i)), offset=i*30, sensitivity=sensitivity))
   return dict(sensitivities=schedule, first=units, units=ReadInsulinSensitivities.UNITS.get(units))