コード例 #1
0
ファイル: __init__.py プロジェクト: karstenw/Library
def cluster(concept, relation=None, context=None, author=None, depth=2, max=None, labeled=False, 
            wait=15):
    """ Returns the given Perception query as a graph of connected concept nodes.
    """
    try: graph._ctx = _ctx
    except:
        pass
    rules = query(concept, relation, context, author, depth, max, wait)
    concept = rules.disambiguate(concept)
    g = graph.create()
    style(g)
    if concept != None:
        g.add_node(concept, root=True)
    for rule in rules:
        e = g.add_rule(
            rule.concept1, 
            rule.relation, 
            rule.concept2,
            rule.context,
            rule.author,
            weight = 0.5 + VOTE*(rule.weight-1)
        )
        if e and labeled:
            e.label = rule.relation
    return g
コード例 #2
0
def cluster(concept,
            relation=None,
            context=None,
            author=None,
            depth=2,
            max=None,
            labeled=False,
            wait=15):
    """ Returns the given Perception query as a graph of connected concept nodes.
    """
    try:
        graph._ctx = _ctx
    except:
        pass
    rules = query(concept, relation, context, author, depth, max, wait)
    concept = rules.disambiguate(concept)
    g = graph.create()
    style(g)
    if concept != None:
        g.add_node(concept, root=True)
    for rule in rules:
        e = g.add_rule(rule.concept1,
                       rule.relation,
                       rule.concept2,
                       rule.context,
                       rule.author,
                       weight=0.5 + VOTE * (rule.weight - 1))
        if e and labeled:
            e.label = rule.relation
    return g
コード例 #3
0
def search(filename, origin, destination):
	origin = origin.upper()
	destination = destination.upper()
	#print("origin: " + origin)
	#print("destination: " + destination)
	stops = get_stops(filename)
	#print(stops)

	if(origin in stops and destination in stops):
		if(origin == destination):
			return "<p>Lähtö- ja päätepysäkki ovat samat!</p>"
		else:
			data = parse.parse(filename)		
			g = graph.create(data)
			#print_graph(g)		

			dijkstra = graph.dijkstra(g, g.get_vertex(origin), g.get_vertex(destination))

			target = g.get_vertex(destination)
			path = [target.id]
			graph.shortest(target, path)
			#print("The shortest path: {}".format(path[::-1]))

			return finder.find_lines_from_route(path[::-1], data)
	else:
		return None
コード例 #4
0
def workflow(request):
    if request.method == 'POST':
        if 'method' in request.POST:
            this = int(request.POST['next'].replace('flw', ''))
            now = int(request.POST['now'].replace('flw', ''))
            if request.POST['method'] == 'add':
                try:
                    ticket_flow_edges.objects.get(now=now, next=this)
                except Exception:
                    ticket_flow_edges(now_id=now, next_id=this).save(user=request.user)
                return HttpResponse('OK')

            elif request.POST['method'] == 'del':
                ticket_flow_edges.objects.filter(now=now, next=this).delete()
                return HttpResponse('OK')

    flows = ticket_flow.objects.all()
    edges = ticket_flow_edges.objects.all()
    nodes = {}

    offset_x = 30
    offset_y = 30

    min_x = 0
    min_y = 0
    max_x = 0
    max_y = 0

    g = graph.create()

    for flow in flows:
        g.add_node('flw%s' % flow.pk)

    for edge in edges:
        g.add_edge('flw%s' % edge.now_id, 'flw%s' % edge.next_id)
    g.solve()

    for id in g:
        # print '%s => %s,%s' % (id, g[id].x, g[id].y)
        nodes[id] = (g[id].x, g[id].y)
        min_x = min(min_x, g[id].x)
        min_y = min(min_y, g[id].y)
        max_x = max(max_x, g[id].x)
        max_y = max(max_y, g[id].y)

    if min_x < 0:
        min_x = min_x * (-1)
    if min_y < 0:
        min_y = min_y * (-1)

    for node in nodes:
        (x, y) = nodes[node]
        nodes[node] = (x + min_x + offset_x, y + min_y + offset_y)

    max_x = max_x + min_x + (offset_x * 2)
    max_y = max_y + min_y + (offset_y * 2)

    return render(request, 'tickets/workflow.html', {'layout': 'horizontal', 'flows': flows, 'edges': edges, 'nodes': nodes, 'width': max_x, 'height': max_y})
コード例 #5
0
ファイル: tickets.py プロジェクト: mediafactory/yats
def workflow(request):
    if request.method == 'POST':
        if 'method' in request.POST:
            this = int(request.POST['next'].replace('flw', ''))
            now = int(request.POST['now'].replace('flw', ''))
            if request.POST['method'] == 'add':
                try:
                    ticket_flow_edges.objects.get(now=now, next=this)
                except:
                    ticket_flow_edges(now_id=now, next_id=this).save(user=request.user)
                return HttpResponse('OK')

            elif request.POST['method'] == 'del':
                ticket_flow_edges.objects.filter(now=now, next=this).delete()
                return HttpResponse('OK')

    flows = ticket_flow.objects.all()
    edges = ticket_flow_edges.objects.all()
    nodes = {}

    offset_x = 30
    offset_y = 30

    min_x = 0
    min_y = 0
    max_x = 0
    max_y = 0

    g = graph.create()

    for flow in flows:
        g.add_node('flw%s' % flow.pk)

    for edge in edges:
        g.add_edge('flw%s' % edge.now_id, 'flw%s' % edge.next_id)
    g.solve()

    for id in g:
        # print '%s => %s,%s' % (id, g[id].x, g[id].y)
        nodes[id] = (g[id].x, g[id].y)
        min_x = min(min_x, g[id].x)
        min_y = min(min_y, g[id].y)
        max_x = max(max_x, g[id].x)
        max_y = max(max_y, g[id].y)

    if min_x < 0:
        min_x = min_x * (-1)
    if min_y < 0:
        min_y = min_y * (-1)

    for node in nodes:
        (x, y) = nodes[node]
        nodes[node] = (x + min_x + offset_x, y + min_y + offset_y)

    max_x = max_x + min_x + (offset_x * 2)
    max_y = max_y + min_y + (offset_y * 2)

    return render(request, 'tickets/workflow.html', {'layout': 'horizontal', 'flows': flows, 'edges': edges, 'nodes': nodes, 'width': max_x, 'height': max_y})
コード例 #6
0
ファイル: grafics.py プロジェクト: Peri86/tesismaster
def dibuixargraph():
    #graph =  ximport("graph")
    g = gra.create(iterations=500, distance=0.8)
    print g
    g.add_node("NodeBox")
    g.add_node("Core Image", category="library")
    g.add_edge("Core Image", "NodeBox")
    g.solve()
    g.draw()
    return
コード例 #7
0
def dibuixargraph():
    #graph =  ximport("graph")
    g = gra.create(iterations=500, distance=0.8)
    print g
    g.add_node("NodeBox")
    g.add_node("Core Image", category="library")
    g.add_edge("Core Image", "NodeBox")
    g.solve()
    g.draw()
    return
コード例 #8
0
ファイル: money.py プロジェクト: ReCore-sys/bottombot
 async def prices(self, ctx):
     utils.log(ctx)
     global prices
     global img
     if img is None:
         img = graph.create(prices[-288:])
     with BytesIO() as img_bin:
         img.save(img_bin, format="PNG")
         img_bin.seek(0)
         await ctx.send(
             file=discord.File(fp=img_bin, filename=f"{prices[-1][0]}.png"))
コード例 #9
0
    def __init__(self):

        self.gve = graph.create(depth=True)
        #self.user_data = UserData()
        self.states_dict = {}

        self.document = FSMDocument.new_document()
        self.start_state = None

        self.node = self.gve.node
        self.edge = self.gve.edge

        self.sm_thread = None
        self.status_cb_func = None
        self.last_outcome = None
コード例 #10
0
    def __init__(self):

        self.gve = graph.create(depth=True)
        #self.user_data = UserData()
        self.states_dict = {}

        self.document = FSMDocument.new_document()
        self.start_state = None

        self.node = self.gve.node
        self.edge = self.gve.edge

        self.sm_thread = None
        self.status_cb_func = None
        self.last_outcome = None
コード例 #11
0
ファイル: __init__.py プロジェクト: karstenw/Library
 def graph(self):
     """ Returns a graph with edges connecting concepts.
     Different unconnected clusters will be present in the graph.
     """
     try: graph._ctx = _ctx
     except:
         pass
     g = graph.create()
     for a, b in self:
         e = g.edge(b, a)
         if not e:
             e = g.add_edge(b, a)
         else:
             e.weight += 1
         if e: e.relation = self.relation.replace(" ", "-")
     style(g, relation=False)
     return g
コード例 #12
0
    def graph(self):
        """ Returns a graph with edges connecting concepts.
		Different unconnected clusters will be present in the graph.
		"""
        try:
            graph._ctx = _ctx
        except:
            pass
        g = graph.create()
        for a, b in self:
            e = g.edge(b, a)
            if not e:
                e = g.add_edge(b, a)
            else:
                e.weight += 1
            if e: e.relation = self.relation.replace(" ", "-")
        style(g, relation=False)
        return g
コード例 #13
0
import graph
import colors
size(500,500)
g = graph.create(iterations=1000, distance=2,layout="spring", depth=True)

d = {"friendfeed":    ["twitter", "reddit", "tumblr", "blog", "news.yc", "flickr"],
     "twitter":       [],
     "flickr":        [],
     "news.yc":       [],
     "reddit":        [],
     "tumblr":        ["flickr"],
     "blog":          [],
     "stackoverflow": [],
     "facebook":      [],
     "gmail":         []}

for k,vs in d.iteritems():
    g.add_node(k)
    for v in vs:
        g.add_edge(k, v)

g.solve()
g.layout.tweak(k=8, m=0.01, w=10, d=0.5, r=15)
g.styles.fontsize = 20
g.styles.textwidth=200
g.styles.background=color(.5,0.4,0.6)
g.draw(directed=True)
コード例 #14
0
import graph
import colors
size(500, 500)
g = graph.create(iterations=1000, distance=2, layout="spring", depth=True)

d = {
    "friendfeed": ["twitter", "reddit", "tumblr", "blog", "news.yc", "flickr"],
    "twitter": [],
    "flickr": [],
    "news.yc": [],
    "reddit": [],
    "tumblr": ["flickr"],
    "blog": [],
    "stackoverflow": [],
    "facebook": [],
    "gmail": []
}

for k, vs in d.iteritems():
    g.add_node(k)
    for v in vs:
        g.add_edge(k, v)

g.solve()
g.layout.tweak(k=8, m=0.01, w=10, d=0.5, r=15)
g.styles.fontsize = 20
g.styles.textwidth = 200
g.styles.background = color(.5, 0.4, 0.6)
g.draw(directed=True)
コード例 #15
0
ファイル: test3.py プロジェクト: weaver20/gcalc
import graph as gw
#basic test

graph1 = gw.create()
gw.addVertex(graph1, 'v1')
gw.addVertex(graph1, 'v2')
gw.addEdge(graph1, 'v1','v2')
gw.addVertex(graph1, 'v3')
gw.disp(graph1)

graph2 = gw.create()
gw.addVertex(graph2, 'v2')
gw.addVertex(graph2, 'v3')
gw.addEdge(graph2, 'v2','v3')
gw.disp(graph2)

graph3 = gw.create()
graph4 = gw.graphUnion(graph1, graph2, graph3)
gw.disp(graph4)
gw.disp(graph3)
コード例 #16
0
ファイル: test2.py プロジェクト: weaver20/gcalc
import graph as gw
#super basic test to check the first 5 functions

graph = gw.create()
gw.addVertex(graph, 'v1')
gw.addVertex(graph, 'v2')
gw.addEdge(graph, 'v1', 'v2')
gw.disp(graph)
gw.addEdge(graph, 'v2', 'v3')
gw.disp(graph)
gw.destroy(graph)
コード例 #17
0
import graph as gw
g1 = gw.create()
g1 = gw.addVertex(g1, 'v1')
g1 = gw.addVertex(g1, 'v2')
g1 = gw.addVertex(g1, 'v3')
g1 = gw.addVertex(g1, 'v4')
g1 = gw.addEdge(g1, 'v1', 'v2')
g1 = gw.addEdge(g1, 'v1', 'v3')
g1 = gw.addEdge(g1, 'v2', 'v1')
null1 = gw.addEdge(g1, 'v1', 'v1')  # self loop
null1 = gw.addEdge(g1, 'v1', 'v2')  # edge already exists
print('printing g1:')
gw.disp(g1)
g2 = gw.create()
g2 = gw.addVertex(g2, 'u1')
g2 = gw.addVertex(g2, 'u2')
g2 = gw.addVertex(g2, 'u3')
g2 = gw.addVertex(g2, 'u4')
g2 = gw.addEdge(g2, 'u1', 'u2')
g2 = gw.addEdge(g2, 'u2', 'u1')
print('printing g2:')
gw.disp(g2)

print('addEdge not exist vertex1:')
null1 = gw.addEdge(g2, 'v1', 'u2')  # edge not exists
print('printing null1:')
gw.disp(null1)
print('addEdge not exist vertex2:')
null1 = gw.addEdge(g2, 'u1', 'v2')  # edge not exists
print('addEdge not exist vertex1 and 2:')
null1 = gw.addEdge(g2, 'v1', 'v2')  # edge not exists
コード例 #18
0
import graph as gw

g1 = gw.create()
gw.disp(g1)
g1 = gw.addVertex(g1, 'a')
g1 = gw.addVertex(g1, 'b')
gw.disp(gw.addEdge(g1, 'a', 'b'))
gw.disp(gw.addEdge(g1, 'a', 'c'))
g2 = gw.create()
g2 = gw.addVertex(g2, 'c')
gw.disp(gw.graphUnion(g1, g2, g1))
gw.disp(g1)
gw.disp(gw.addVertex(g1, " hello"))
gw.disp(gw.addVertex(g1, "[;]"))
g3 = gw.create()
gw.disp(gw.graphUnion(g1, g2, g3))
gw.destroy(g2)
gw.destroy(g1)