Example #1
0
 def _insert_hours(self,table,data):
   if data is not None:
     arg_epoch, arg_value = data
     arg_epoch = trunc_to_hour(arg_epoch)
     m = self.fetch_from_epoch('hours', trunc_to_hour(arg_epoch))
     if m is None:
       sql = """INSERT INTO {}(epoch,value) VALUES (?,?)""".format(table)
       self.conn.execute(sql, (arg_epoch,arg_value) )
     else:
       idx, epoch, value = m
       if arg_value < value:
         sql = """UPDATE hours SET epoch = ?,value=? WHERE id=?"""
         self.conn.execute(sql, (arg_epoch,arg_value,idx))
     self.conn.commit()
   else:
     return None
Example #2
0
  def test_save_hour(self):
    epoch = trunc_to_min(time.time())
    expired_data = [ (epoch + HOUR -x*MIN,x-2) for x in xrange(0,10)]
    for e in expired_data:
      self.rrd.save(e[0],e[1])
    retrive_data = self.rrd.db.fetch_all('hours',wnd_1(epoch))
    self.assertEqual([], retrive_data)

    valid_data = [(epoch -x*MIN,float(x+1)) for x in xrange(0,10)]
    valid_data.reverse()

    for e in valid_data:
      self.rrd.save(e[0],e[1])

    min_el = valid_data.pop()
    el = (trunc_to_hour(min_el[0]),min_el[1])
    self.assertEqual([el], self.rrd.db.fetch_all('hours',wnd_24(epoch)))