Exemplo n.º 1
0
def on_started():
	global ctx

	if len(sys.argv) == 3:
		if sys.argv[2].endswith(".json"):
			std.load_json(sys.argv[2]) 
		else:
			print("Unrecognized format <'" + sys.argv[2] + "'> !")

	print(ctx['g1'])
	og.bind_entity(ctx['g1'])
	nid = og.add_node("node1")
	og.set_node_attribute(nid, "og:space:color", "vec4", "1.0 0.0 0.0 1.0")

	print(ctx['g2'])
	og.bind_entity(ctx['g2'])
	nid = og.add_node("node2")
	og.set_node_attribute(nid, "og:world:geolocation", "vec2", "48.8742, 2.3470")
	og.set_node_attribute(nid, "og:world:color", "vec4", "1.0 1.0 0.0 1.0")
Exemplo n.º 2
0
def add_neighbor():
    if graphiti.count_selected_nodes() == 0:
        print("Please select a node !")
        return
    id = graphiti.get_selected_node(0)
    label = raw_input("New node label : ")
    t = raw_input("New node type : ")

    nid = graphiti.add_node(label)
    graphiti.set_node_attribute(nid, "type", "string", t)

    graphiti.add_link(id, nid)
Exemplo n.º 3
0
def on_started():
    global cities

    dico = {}

    for city in cities:
        nid = graphiti.add_node(city["name"])
        graphiti.set_node_attribute(nid, "og:world:geolocation", "vec2", std.vec2_to_str(city["geolocation"]))
        graphiti.set_node_attribute(nid, "og:world:color", "vec4", std.vec4_to_str(city["color"]))
        graphiti.set_node_attribute(nid, "og:world:size", "float", str(city["size"]))
        dico[city['name']] = nid

    eid = graphiti.add_edge(dico['Paris'], dico['San Francisco'])
    graphiti.set_edge_attribute(eid, "og:world:color", "vec4", "0.0 1.0 0.0 1.0")
Exemplo n.º 4
0
def on_started():
    global cities

    dico = {}

    for city in cities:
        nid = graphiti.add_node(city["name"])
        graphiti.set_node_attribute(nid, "og:world:geolocation", "vec2",
                                    std.vec2_to_str(city["geolocation"]))
        graphiti.set_node_attribute(nid, "og:world:color", "vec4",
                                    std.vec4_to_str(city["color"]))
        graphiti.set_node_attribute(nid, "og:world:size", "float",
                                    str(city["size"]))
        dico[city['name']] = nid

    eid = graphiti.add_edge(dico['Paris'], dico['San Francisco'])
    graphiti.set_edge_attribute(eid, "og:world:color", "vec4",
                                "0.0 1.0 0.0 1.0")
Exemplo n.º 5
0
def add_random_graph():
    node_count = int(raw_input("Number of nodes : "))
    edge_count = int(raw_input("Number of edges : "))

    nodes = []
    for i in range(node_count):
        id = graphiti.add_node(str(i))

        graphiti.set_node_attribute(id, "type", "string", str(i % 3))

        size = 1 + abs(math.sin(float(i)))
        graphiti.set_node_attribute(id, "og:space:size", "float", str(size))

        nodes.append(id)

    for j in range(edge_count):
        loop = True
        while loop:
            src = random.choice(nodes)
            dst = random.choice(nodes)
            if src != dst:
                loop = False
        id = graphiti.add_link(src, dst)
        graphiti.set_link_attribute(id, "type", "string", str(j % 3))
Exemplo n.º 6
0
def load_json(json_filename):
    nodes = {}
    edges = {}
    global node_attributes
    global edge_attributes

    print ("Loading \"" + json_filename + "\" ...")

    import json
    with open(json_filename, "r") as infile:
        data = json.load(infile)

    print("Loading meta information ...")
    # TODO : Find a more generic way of doing this
    if "meta" in data:
        if "title" in data["meta"].keys():
            if data["meta"]["title"] is not None:
                graphiti.set_attribute("raindance:space:title", "string", data["meta"]["title"])

    if "attributes" in data:
        for key in data["attributes"].keys():
            if key in reserved_attributes:
                continue
            att_info = get_attribute_info(data["attributes"][key])
            if att_info is None:
                print("Error: Couldn't parse key '" + key + "' with value '" + str(data["attributes"][key]) + "'!")
                continue
            graphiti.set_attribute(key, att_info[0], att_info[1])

    print(". Loading nodes ...")
    for n in data["nodes"]:
        n = prepare_node(n)

        label = ""
        if "label" in n:
            label = n["label"].encode("utf-8")
        
        nid = graphiti.add_node(label)
        nodes[n["id"]] = nid

        for key in n.keys():
            if key in reserved_attributes:
                continue
            att_info = get_attribute_info(n[key])
            if att_info is None:
                print("Error: Couldn't parse key '" + key + "' with value '" + str(n[key]) + "'!")
                continue
            graphiti.set_node_attribute(nid, key, att_info[0], att_info[1])

    print(". Loading edges ...")
    for e in data["edges"]:
        e = prepare_edge(e)

        if "src" in e:
            eid = graphiti.add_edge(nodes[e["src"]], nodes[e["dst"]])
        else:
            eid = graphiti.add_edge(nodes[e['source']], nodes[e['target']])
        edges[e["id"]] = eid

        for key in e.keys():
            if key in reserved_attributes:
                continue
            att_info = get_attribute_info(e[key])
            if att_info is None:
                print("Error: Couldn't parse key '" + key + "' with value '" + str(e[key]) + "'!")
                continue
            graphiti.set_edge_attribute(eid, key, att_info[0], att_info[1])

    if "timeline" in data:
        print(". Loading timeline ...")
        for c in data["timeline"]:
            # TODO : Get rid of this translation phase when possible.
            if c[1].startswith("graph:"):
                if c[1] in ["graph:remove_node", "graph:set_node_attribute"]:
                    c[2]["id"] = nodes[c[2]["id"]]
                elif c[1] in ["graph:remove_edge", "graph:set_edge_attribute"]:
                    c[2]["id"] = edges[c[2]["id"]]
                elif c[1] in ["graph:add_edge"]:
                    c[2]["src"] = nodes[c[2]["src"]]
                    c[2]["dst"] = nodes[c[2]["dst"]]
            graphiti.send_command(c[0], c[1], c[2])

    print("Done.")
Exemplo n.º 7
0
def on_idle():

    global queue
    global nodes
    global edges
    global t
    global job_id

    mutex.acquire()

    for element in queue:
        if og.count_nodes() > 1000:
            #og.register_script("#console", 'dashboard.shell.execute')
            og.remove_job(job_id)
            continue
        #print(element)

        # --- Space Document ---
        name = element['name']
        rr = element['rr']
        asn = element['geoip']['rr_asn']

        '''
        if asn is not None:
            asn = asn.split()[0][2:]
            if asn in nodes:

                t = time.time()
                r = 0.5 + math.cos(t)
                g = 0.5 + math.sin(t)
                b = 0.5 + math.sin(t + math.pi / 2)
                a = 0.5
                og.set_node_attribute(nodes[asn], 'og:space:color', 'vec4', "{0} {1} {2} {3}".format(r, g, b, a))
        '''
        
        if name not in nodes:
            nodes[name] = og.add_node(name)
            og.set_node_attribute(nodes[name], 'type', 'string', 'name')

        if rr not in nodes:
            nodes[rr] = og.add_node(rr)
            og.set_node_attribute(nodes[rr], 'type', 'string', 'ip')
        
        edge_key = "{0} -> {1}".format(name, rr)
        if edge_key not in edges:
            edges[edge_key] = og.add_edge(nodes[name], nodes[rr])
        

        # --- WorldMap + Globe Documents ---
        
        try:
            record = gi.record_by_addr(rr)
        except:
            continue
        if record is None:
            continue
        msg = {
            'function' : 'add',
            'latitude' : record['latitude'],
            'longitude' :  record['longitude'],
            'color.r' : random.uniform(0.3, 1.0),
            'color.g' : 0.0,
            'color.b' : 0.0,
            'color.a' : 0.75,
            'size' : 2.0
        }
        og.request(1, msg)
        og.request(2, msg)
        

    queue = list()
    
    mutex.release()