示例#1
0
 def load_pastweek(self, storage, k):
     now      = time.time()
     pasttime = funcs.datetime_fromtimestamp(now) - timedelta(days=7, seconds=TFF)
     currtime = funcs.datetime_fromtimestamp(now) + timedelta(seconds=TFF)
     start    = Timestamp._make((pasttime.year, pasttime.month, pasttime.day, pasttime.hour, pasttime.minute, pasttime.second))
     finish   = Timestamp._make((currtime.year, currtime.month, currtime.day, currtime.hour, currtime.minute, currtime.second))
     return(storage.load(self.kind(), k, start, finish, 7*24*60*60))
示例#2
0
 def load_pastweek(self, storage, k):
     now      = time.time()
     pasttime = funcs.datetime_fromtimestamp(now) - timedelta(days=7, seconds=TFF)
     currtime = funcs.datetime_fromtimestamp(now) + timedelta(seconds=TFF)
     start    = Timestamp._make((pasttime.year, pasttime.month, pasttime.day, pasttime.hour, pasttime.minute, pasttime.second))
     finish   = Timestamp._make((currtime.year, currtime.month, currtime.day, currtime.hour, currtime.minute, currtime.second))
     return(storage.load(self.kind(), k, start, finish, 7*24*60*60))
示例#3
0
 def __init__(self, name, value, timestamp):
     d = funcs.datetime_fromtimestamp(timestamp)
     self.n = funcs.norm_key(name)
     self.v = value
     self.t = timestamp
     self.d = Timestamp._make(
         (d.year, d.month, d.day, d.hour, d.minute, d.second))
示例#4
0
 def load(self, kind, key, start, finish, limit=100):
     t0    = funcs.datetime_fromtimestamp(funcs.timetuple_timestamp(start))
     t1    = funcs.datetime_fromtimestamp(funcs.timetuple_timestamp(finish))
     diff  = (t1.month + 12 * (t1.year - t0.year)) - t0.month
     if (t0 > t1):
         raise(ValueError("start > finish"))
     if (diff > 1):
         raise(ValueError("range too wide"))
     k0    = struct.pack(">i", marshall.serialize_key(*start, epoch=marshall.DEFAULT_EPOCH))
     k1    = struct.pack(">i", marshall.serialize_key(*finish, epoch=marshall.DEFAULT_EPOCH))
     f     = None
     delay = defer.Deferred()
     if (kind == event.Event.kind()):
         cf1 = CF_EVENTS % (start[1], start[0])
         cf2 = CF_EVENTS % (finish[1], finish[0])
         f   = unserialize_event
     else:
         cf1 = CF_DATA % (start[1], start[0])
         cf2 = CF_DATA % (finish[1], finish[0])
         f   = unserialize_data
     if (cf1 == cf2):
         d = self.get_slice(key           = encode_string(key),
                            start         = k1,
                            finish        = k0,
                            count         = limit,
                            column_family = cf1)
     else:
         d = merge(self.get_slice(key           = encode_string(key),
                                  start         = k1,
                                  finish        = k0,
                                  count         = limit,
                                  column_family = cf2),
                   self.get_slice(key           = encode_string(key),
                                  start         = k1,
                                  finish        = k0,
                                  count         = limit,
                                  column_family = cf1))
     d.addCallback(lambda xs: reversed(xs))
     d.addCallback(lambda cols: f(key, cols))
     d.addCallback(delay.callback)
     d.addErrback(delay.errback)
     return(delay)
示例#5
0
 def set_unixtimestamp(self, timestamp):
     d = funcs.datetime_fromtimestamp(timestamp)
     self.t = timestamp
     self.d = Timestamp._make(
         (d.year, d.month, d.day, d.hour, d.minute, d.second))
示例#6
0
def unserialize_key(k, epoch):
    e = funcs.timetuple_timestamp((epoch, 1, 1, 0, 0, 0))
    t = funcs.datetime_fromtimestamp(k + e)
    return(t.year, t.month, t.day, t.hour, t.minute, t.second)
示例#7
0
 def __init__(self, name, value, timestamp):
     d = funcs.datetime_fromtimestamp(timestamp)
     self.n = funcs.norm_key(name)
     self.v = value
     self.t = timestamp
     self.d = Timestamp._make((d.year, d.month, d.day, d.hour, d.minute, d.second))
示例#8
0
 def set_unixtimestamp(self, timestamp):
     d = funcs.datetime_fromtimestamp(timestamp)
     self.t = timestamp
     self.d = Timestamp._make((d.year, d.month, d.day, d.hour, d.minute, d.second))
示例#9
0
def unserialize_key(k, epoch):
    e = funcs.timetuple_timestamp((epoch, 1, 1, 0, 0, 0))
    t = funcs.datetime_fromtimestamp(k + e)
    return (t.year, t.month, t.day, t.hour, t.minute, t.second)