예제 #1
0
class Classifer(object):
    def __init__(self):
        self.channels = OrderedDictWithLists()

    def add_data(self, keyable, func):
        # hmm, this should rotate every 10 seconds or so, but moving over the
        # old data is hard (can't write out-of-order)
        #key = sha.sha(id(o)).hexdigest()[0]

        # this is technically round-robin
        key = keyable

        self.channels.push_to_row(key, func)

    def rem_data(self, key):
        try:
            l = self.channels.poprow(key)
            l.clear()
        except KeyError:
            pass

    def rotate_data(self):
        # the removes the top-most row from the ordereddict
        k = self.channels.iterkeys().next()
        l = self.channels.poprow(k)
        
        data = l.popleft()
        # this puts the whole row at the bottom of the ordereddict
        self.channels.setrow(k, l)
        
        return data
        
    def __len__(self):
        return len(self.channels)
예제 #2
0
 def __init__(self):
     self.channels = OrderedDictWithLists()