示例#1
0
    def query_index(self, domain, metric, start_time, end_time):
        """Query index for keys.
        """
        now = util.now()
        max_time = now
        min_time = now - AVAILABLE_HISTORY

        #TODO: debug logging
        #     print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
        #     print 'min_time:  ', min_time,   '\n', \
        #           'start_time:', start_time, '\n', \
        #           'max_time:  ', max_time,   '\n', \
        #           'end_time:  ', end_time,   '\n', \
        #           'diff:      ', end_time - start_time

        start_time, end_time = min(max(min_time, start_time), max_time), \
                               max(min(max_time, end_time), min_time)

        #     print 'start_time:', start_time, '\n', \
        #           'end_time:  ', end_time,   '\n', \
        #           'diff:      ', end_time - start_time
        #     print "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"

        if start_time == end_time: return []

        ret = []
        for block in filter(lambda v: v, [
                self.get_block(t)
                for t in range(start_time, end_time + BLOCK_SIZE, BLOCK_SIZE)
        ]):
            ret.extend(block.query_index(domain, metric, start_time, end_time))
        return ret
示例#2
0
    def create(connection, max_wait=120):
        master = Table.create(config.table_name('dp_master'),
                              schema=[
                                  HashKey('n', data_type=NUMBER),
                                  RangeKey('tbase', data_type=NUMBER)
                              ],
                              throughput={
                                  'read': 5,
                                  'write': 5
                              },
                              connection=connection)

        wait_for_active(master, max_wait)

        now = util.now()
        for i in range(BLOCKS):
            next_block = now + i * BLOCK_SIZE
            master.put_item({
                'n': block_pos(next_block),
                'tbase': base_time(next_block),
                'state': 'INITIAL'
            })
示例#3
0
 def create_current(self):
     """Create the block for the current time.
     """
     return self.create_block(util.now())
示例#4
0
 def create_next(self):
     """Create the next block.
     """
     return self.create_block(util.now() + BLOCK_SIZE)
示例#5
0
 def previous(self):
     """Return previous block or None if previous block is not yet created.
     """
     return self.get_block(util.now() - BLOCK_SIZE)
示例#6
0
 def next(self):
     """Return next block or None if next block is not yet created.
     """
     return self.get_block(util.now() + BLOCK_SIZE)
示例#7
0
 def current(self):
     """Return current block or None if current block is not yet created.
     """
     return self.get_block(util.now())
示例#8
0
 def time_remaining(self):
     """Return time remaining until next block.
     """
     now = util.now()
     remaining = base_time(now) + BLOCK_SIZE - now
     return remaining, int(round(100. * remaining / BLOCK_SIZE))
示例#9
0
 def time_expired(self):
     """Return time expired since the previous block.
     """
     now = util.now()
     expired = now - base_time(now)
     return expired, int(round(100. * expired / BLOCK_SIZE))