Esempio n. 1
0
    def process(self):
        queue = []
        groups = []
        for a in self.location.simple_areas.order_by(SimpleArea.row,
                                                     SimpleArea.column):
            if a.most_popular_tag_count != None:
                queue.append(a)

        while len(queue) > 0:
            area = queue.pop(0)
            group = TagGroup(area)
            can_expand = True
            while can_expand:
                can_expand = False

                to_the_right = filter(lambda x: x.column == group.right + 1 and \
                    x.row <= group.top and x.row >= group.bottom,
                    queue)
                if len(to_the_right
                       ) == group.bottom - group.top + 1 and group.can_expand(
                           to_the_right):
                    can_expand = True
                    group.expand(to_the_right)
                    for a in to_the_right:
                        queue.remove(a)

                to_the_bottom = filter(lambda x: x.row == group.bottom + 1 and \
                    x.column <= group.right and x.column >= group.left,
                    queue)
                if len(to_the_bottom
                       ) == group.right - group.left + 1 and group.can_expand(
                           to_the_bottom):
                    can_expand = True
                    group.expand(to_the_bottom)
                    for a in to_the_bottom:
                        queue.remove(a)
            groups.append(group)

        with get_db().transaction():
            self._clear_old_groups()
            self._save_groups(groups)
Esempio n. 2
0
def after_request(response):
    db = get_db()
    db.close()
    return response
Esempio n. 3
0
def before_request():
    db = get_db()
    db.connect()
Esempio n. 4
0
 class Meta:
     database = get_db()
 class Meta:
     database = get_db()
     indexes = ((('area', 'max_stamp'), True), (('area', 'min_stamp'),
                                                True))
 class Meta:
     database = get_db()
     indexes = ((('hashtag', 'area_in_hour'), True), )