Example #1
0
def dot_to_database(dot):
    dot_graph = pygraphviz.AGraph(string=dot)
    for node in dot_graph.iternodes():
        node_id = int(node[2:])
        split_pos = node.attr['pos'].split(',')
        x = float(split_pos[0])
        y = float(split_pos[1])
        post = graph.posts.get(node_id)
        if post:
            if post.x != x or post.y != y:
                debug(
                    'dot_to_database: moving post with id %s to position %s, %s'
                    % (node_id, x, y))
                post.x = x
                post.y = y
                post.save()
        else:
            error(
                "During flushing dot to database post with id %s wasn't in database"
                % (node_id, ))
    for edge in dot_graph.iteredges():
        edge_id = int(edge.attr['id'][2:])
        relationship = graph.replies.get(edge_id)
        relationship = element_to_model(relationship, Reply)
        if relationship:
            if relationship.get_graphviz_pos() != edge.attr['pos']:
                debug(
                    'dot_to_database: moving relationship with id %s to position %s'
                    % (edge_id, edge.attr['pos']))
                relationship.set_graphviz_pos(edge.attr['pos'])
                relationship.save()
        else:
            error(
                "During flushing dot to database relationship with id %s wasn't in database"
                % (edge_id, ))
Example #2
0
def dot_to_database(dot):
    dot_graph = pygraphviz.AGraph(string=dot)
    for node in dot_graph.iternodes():
        node_id = int(node[2:])
        split_pos = node.attr['pos'].split(',')
        x = float(split_pos[0])
        y = float(split_pos[1])
        post = graph.posts.get(node_id)
        if post:
            if post.x != x or post.y != y:
                debug('dot_to_database: moving post with id %s to position %s, %s' % (node_id, x, y))
                post.x = x
                post.y = y
                post.save()
        else:
            error("During flushing dot to database post with id %s wasn't in database" % (node_id,))
    for edge in dot_graph.iteredges():
        edge_id = int(edge.attr['id'][2:])
        relationship = graph.replies.get(edge_id)
        relationship = element_to_model(relationship, Reply)
        if relationship:
            if relationship.get_graphviz_pos() != edge.attr['pos']:
                debug('dot_to_database: moving relationship with id %s to position %s' % (edge_id, edge.attr['pos']))
                relationship.set_graphviz_pos(edge.attr['pos'])
                relationship.save()
        else:
            error("During flushing dot to database relationship with id %s wasn't in database" % (edge_id,))
Example #3
0
def by_tile():
    #import sys, hotshot
    #prof = hotshot.Profile('tile-profile.log')
    #prof.start()
    posts = set()
    replies = set()
    tile_xs = request.args.getlist('tile_x', type=int)
    tile_ys = request.args.getlist('tile_y', type=int)
    tiles = zip(tile_xs, tile_ys)
    if len(tile_xs) != len(tile_ys) or len(tile_xs) == 0:
        abort(400)
    for post in graph.posts.get_all():  # XXX: Bad, use an index
        for tile in tiles:
            if post.tile_x == tile[0] and post.tile_y == tile[1]:
                posts.add(post)
                for reply in post.inE("reply"):
                    replies.add(element_to_model(reply, Reply))
                for reply in post.outE("reply"):
                    replies.add(element_to_model(reply, Reply))
    result = jsonify(
        posts=[{
            'id': post.eid,
            'root': post.root,
            'title': post.title,
            'x': post.x,
            'y': post.y,
            'at': time.mktime(post.at.timetuple()),
            'parents': [parent.eid for parent in post.inE("reply")],
            'children': [child.eid for child in post.outE("reply")],
        } for post in posts],
        replies=[
            {
                'id': reply.eid,
                'pos': reply.pos if reply.pos else [],  # XXX: From, to
                'in_id': reply.inV().eid,
                'out_id': reply.outV().eid,
            } for reply in replies
        ])
    #prof.stop()
    return result
Example #4
0
def by_tile():
    #import sys, hotshot
    #prof = hotshot.Profile('tile-profile.log')
    #prof.start()
    posts = set()
    replies = set()
    tile_xs = request.args.getlist('tile_x', type=int)
    tile_ys = request.args.getlist('tile_y', type=int)
    tiles = zip(tile_xs, tile_ys)
    if len(tile_xs) != len(tile_ys) or len(tile_xs) == 0:
        abort(400)
    for post in graph.posts.get_all(): # XXX: Bad, use an index
        for tile in tiles:
            if post.tile_x == tile[0] and post.tile_y == tile[1]:
                posts.add(post)
                for reply in post.inE("reply"):
                    replies.add(element_to_model(reply, Reply))
                for reply in post.outE("reply"):
                    replies.add(element_to_model(reply, Reply))
    result = jsonify(
        posts=[{
            'id': post.eid,
            'root': post.root,
            'title': post.title,
            'x': post.x,
            'y': post.y,
            'at': time.mktime(post.at.timetuple()),
            'parents': [parent.eid for parent in post.inE("reply")],
            'children': [child.eid for child in post.outE("reply")],
        } for post in posts],
        replies=[{
            'id': reply.eid,
            'pos': reply.pos if reply.pos else [], # XXX: From, to
            'in_id': reply.inV().eid,
            'out_id': reply.outV().eid,
        } for reply in replies]
    )
    #prof.stop()
    return result
Example #5
0
def database_to_dot():
    dot_graph = pygraphviz.AGraph(directed=True, strict=False)
    for post in graph.posts.get_all():
        if post.x != None and post.y != None:
            dot_graph.add_node('n_%s' % (post.eid,), pos="%s,%s" % (post.x, post.y), **dot_node_attrs)
        else:
            dot_graph.add_node('n_%s' % (post.eid,), **dot_node_attrs)
        for relationship in post.outE():
            print "relationship.pos", relationship.pos
            relationship = element_to_model(relationship, Reply)
            if relationship.pos != None:
                print "relationship.pos", relationship.pos
                strpos = relationship.get_graphviz_pos()
                dot_graph.add_edge('n_%s' % (relationship.outV().eid,), 'n_%s' % (relationship.inV().eid,), 'e_%s' % (relationship.eid,), pos=strpos)
            else:
                dot_graph.add_edge('n_%s' % (relationship.outV().eid,), 'n_%s' % (relationship.inV().eid,), 'e_%s' % (relationship.eid,))
    return dot_graph
Example #6
0
 def move_posts_and_edges(self):
     to_remove = []
     for command in self.to_modify:
         if command[0] == 'node':
             post_to_modify = graph.posts.get(command[1])
             if post_to_modify:
                 to_remove.append(command)
                 debug("moving post id %s to %s, %s" % (command[1], command[2], command[3]))
                 post_to_modify.x = command[2]
                 post_to_modify.y = command[3]
                 post_to_modify.save()
         elif command[0] == 'edge':
             relation_to_modify = element_to_model(graph.replies.get(command[1]), Reply)
             if relation_to_modify:
                 to_remove.append(command)
                 debug("moving edge id %s to %s" % (command[1], command[2]))
                 relation_to_modify.set_graphviz_pos(command[2])
                 relation_to_modify.save()
     for command in to_remove:
         self.to_modify.remove(command)
Example #7
0
 def move_posts_and_edges(self):
     to_remove = []
     for command in self.to_modify:
         if command[0] == 'node':
             post_to_modify = graph.posts.get(command[1])
             if post_to_modify:
                 to_remove.append(command)
                 debug("moving post id %s to %s, %s" %
                       (command[1], command[2], command[3]))
                 post_to_modify.x = command[2]
                 post_to_modify.y = command[3]
                 post_to_modify.save()
         elif command[0] == 'edge':
             relation_to_modify = element_to_model(
                 graph.replies.get(command[1]), Reply)
             if relation_to_modify:
                 to_remove.append(command)
                 debug("moving edge id %s to %s" % (command[1], command[2]))
                 relation_to_modify.set_graphviz_pos(command[2])
                 relation_to_modify.save()
     for command in to_remove:
         self.to_modify.remove(command)
Example #8
0
def database_to_dot():
    dot_graph = pygraphviz.AGraph(directed=True, strict=False)
    for post in graph.posts.get_all():
        if post.x != None and post.y != None:
            dot_graph.add_node('n_%s' % (post.eid, ),
                               pos="%s,%s" % (post.x, post.y),
                               **dot_node_attrs)
        else:
            dot_graph.add_node('n_%s' % (post.eid, ), **dot_node_attrs)
        for relationship in post.outE():
            print "relationship.pos", relationship.pos
            relationship = element_to_model(relationship, Reply)
            if relationship.pos != None:
                print "relationship.pos", relationship.pos
                strpos = relationship.get_graphviz_pos()
                dot_graph.add_edge('n_%s' % (relationship.outV().eid, ),
                                   'n_%s' % (relationship.inV().eid, ),
                                   'e_%s' % (relationship.eid, ),
                                   pos=strpos)
            else:
                dot_graph.add_edge('n_%s' % (relationship.outV().eid, ),
                                   'n_%s' % (relationship.inV().eid, ),
                                   'e_%s' % (relationship.eid, ))
    return dot_graph