コード例 #1
0
def main():
    logging.basicConfig(format = '%(levelname)s %(message)s')
    logger = logging.getLogger('redis')
    logger.parent.setLevel(logging.ERROR)

    #creating the graph object
    graph = Directed_graph(r_server, 'uniq', logger)

    RED = '\033[91m'
    ORANGE = '\033[93m'
    GREEN = '\033[92m'

    #adding some nodes
    node1 = convert('level_1_1☭')
    node2 = convert('level_1_2')
    node3 = convert('☭level_2_1')
    node4 = convert('level_2_2')
    node5 = convert('level_3_1')

    node1_predecessors = []
    node1_successors = [node3,node4]

    node2_predecessors = []
    node2_successors = [node3,node4]

    node3_predecessors = [node1,node2]
    node3_successors = [node5]

    node4_predecessors = [node1,node2]
    node4_successors = [node5]

    node5_predecessors = []
    node5_successors = []

    def clean():
        graph.remove_node(node1)
        graph.remove_node(node2)
        graph.remove_node(node3)
        graph.remove_node(node4)
        graph.remove_node(node5)
        graph.remove_node(graph.root)


    def clean1():
        graph.remove_node(node1)
        graph.remove_node(node2)
        graph.remove_node(node3)

    def clean2():
        graph.remove_node(node4)
        graph.remove_node(node5)

    def print_test(got,expected,node,nature):
        if got != expected:
            print(RED + "ERROR: "+ node + " " + nature +" is not as it should be")
            print(ORANGE +"GOT:")
            print(got )
            print("EXPECTED:")
            print(expected )
            clean()
            return 1
        else:
            print(GREEN + node + " " + nature +": Ok")


    attributes = {convert('☭jack'): set([convert('1'),convert('2')]), convert('spare☭'): convert('☭youpi')}
 #
    graph.write_on_node(node3, node3_successors, node3_predecessors, attributes)
    graph.write_on_node(node4, node4_successors, node4_predecessors, attributes)
    graph.write_on_node(node1, node1_successors, node1_predecessors, attributes)
    graph.write_on_node(node2, node2_successors, node2_predecessors, attributes)
    graph.write_on_node(node5, node5_successors, node5_predecessors, attributes)
 
    #printing some predecessors or successors
    name = graph.root
    got = graph.get_successors(name)
    expected = set([]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node1
    got = graph.get_successors(name)
    expected = set([node3, node4]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([])
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node2
    got = graph.get_successors(name)
    expected = set([node3, node4]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([])
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node3
    got = graph.get_successors(name)
    expected = set([node5]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([node2, node1]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1

 
    name = node4
    got = graph.get_successors(name)
    expected = set([node5]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([node2, node1])
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node5
    got = graph.get_successors(name)
    expected = set([])
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([node3, node4])
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
 
    clean1()
    print(GREEN + "printing attributs list after removing node[123]")

    #printing some predecessors or successors
    name = graph.root
    got = graph.get_successors(name)
    expected = set([]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node1
    got = graph.get_successors(name)
    expected = set([]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node2
    got = graph.get_successors(name)
    expected = set([]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node3
    got = graph.get_successors(name)
    expected = set([]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node4
    got = graph.get_successors(name)
    expected = set([node5]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node5
    got = graph.get_successors(name)
    expected = set([])
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([node4]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1

    clean2()

    name = node4
    got = graph.get_successors(name)
    expected = set([]) 
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 
    name = node5
    got = graph.get_successors(name)
    expected = set([])
    if print_test(got, expected, name, "successors") == 1:
        return 1
 
    got = graph.get_predecessors(name)
    expected = set([]) 
    if print_test(got, expected, name, "predecessors") == 1:
        return 1
 

    return 0
コード例 #2
0
def main():
    logging.basicConfig(format = '%(levelname)s %(message)s')
    logger = logging.getLogger('redis')
    logger.parent.setLevel(logging.ERROR)

    #creating the graph object
    graph = Directed_graph(r_server, 'uniq', logger, has_root = False)

    RED = '\033[91m'
    ORANGE = '\033[93m'
    GREEN = '\033[92m'

    #adding some nodes
    node1 = 'level_1_1'
    node2 = 'level_1_2'
    node3 = 'level_2_1'
    node4 = 'level_2_2'
    node5 = 'level_3_1'

    node1_predecessors = []
    node1_successors = [node3,node4]

    node2_predecessors = []
    node2_successors = [node3,node4]

    node3_predecessors = [node1,node2]
    node3_successors = [node5]

    node4_predecessors = [node1,node2]
    node4_successors = [node5]

    node5_predecessors = []
    node5_successors = []

    def clean():
        graph.remove_node(node1)
        graph.remove_node(node2)
        graph.remove_node(node3)
        graph.remove_node(node4)
        graph.remove_node(node5)
        graph.remove_node(graph.root)

    def print_test(got,expected,node,nature):
        if got != expected:
            print(RED + "ERROR: "+ node + " " + nature +" is not as it should be")
            print(ORANGE +"GOT:")
            print(got )
            print("EXPECTED:")
            print(expected )
            clean()
            return 1
        else:
            print(GREEN + node + " " + nature +": Ok")


    attributes1 = {'☭jack': set(['1','2']), 'spare☭': '☭youpi'}
    attributes2 = {'jacko': set(['1','2','test']), 'spare☭': '☭youpi', 'bip' : 'bip', 'bip' : 'bop'}
    attributes3 = {'☭jack': set(['1','2']), 'spare☭': '☭youpi'}
    attributes4 = {'☭jack': set(['1','2']), 'spare☭': '☭youpi'}
    attributes5 = {'jacko': set(['1','2','test']), 'spare☭': '☭youpi', 'bip' : 'bip'}
 #
    graph.write_on_node(node3, node3_successors, node3_predecessors, attributes3)
    graph.write_on_node(node4, node4_successors, node4_predecessors, attributes4)
    graph.write_on_node(node1, node1_successors, node1_predecessors, attributes1)
    graph.write_on_node(node2, node2_successors, node2_predecessors, attributes2)
    graph.write_on_node(node5, node5_successors, node5_predecessors, attributes5)
 
    #printing some attributs list

    name = node5
    got = graph.get_attribut_len(name,'jacko')
    expected = 3 
    if print_test(got, expected, name, "attribut length") == 1:
        return 1
    
    name = node5
    got = graph.get_attribut_len(name, convert('spare☭'))
    expected =  1
    if print_test(got, expected, name, "attribut length") == 1:
        return 1

    name = node5
    got = graph.get_attribut_len(name, convert('spare☭_does_not_exists'))
    expected =  0
    if print_test(got, expected, name, "attribut length") == 1:
        return 1

    clean()

    return 0
コード例 #3
0

print(OKBLUE + "creating " + str(node_number) + " nodes")
#calling the generation function
generate_tree(node_number)

#creating the redis connexion
r_server = redis.Redis("localhost")

#creating a basic logger
logging.basicConfig(format='%(message)s')
logger = logging.getLogger('redis')
logger.parent.setLevel(logging.CRITICAL)

#creating the graph object
graph = Directed_graph(r_server, 'uniq', logger, has_root=True)


#we define two process to write the nodes
def process_one():
    for i in range(0, node_number, 2):
        graph.write_on_node(nodes[i], successors[i], predecessors[i],
                            fix_attributes)


def process_two():
    for i in range(1, node_number, 2):
        graph.write_on_node(nodes[i], successors[i], predecessors[i],
                            fix_attributes)

コード例 #4
0
        predecessors.append(predecessors_node)

print(OKBLUE + "creating " + str(node_number)  + " nodes")
#calling the generation function
generate_tree(node_number)

#creating the redis connexion
r_server = redis.Redis("localhost")

#creating a basic logger
logging.basicConfig(format = '%(message)s')
logger = logging.getLogger('redis')
logger.parent.setLevel(logging.CRITICAL)

#creating the graph object
graph = Directed_graph(r_server, 'uniq', logger, has_root = True)

#we define two process to write the nodes
def process_one():
    for i in range(0,node_number,2):
        graph.write_on_node(nodes[i],successors[i],predecessors[i],fix_attributes)

def process_two():
    for i in range(1,node_number,2):
        graph.write_on_node(nodes[i],successors[i],predecessors[i],fix_attributes)

#we get the date before the insertion
t1 = datetime.now()
#create and launch the two processes
print(OKBLUE + "starting the insertion")
p1 = Process(target=process_one)
コード例 #5
0
ファイル: example.py プロジェクト: shawcsn/pygraph_redis
#importing directed_graph
from pygraph_redis.directed_graph import Directed_graph
import redis

#creating the redis connexion
r_server = redis.Redis("localhost")

#creating a basic logger
import logging
logging.basicConfig(format = u'%(message)s')
logger = logging.getLogger(u'redis')
logger.parent.setLevel(logging.DEBUG)

#creating the graph object
graph = Directed_graph(r_server, u'uniq', logger)

#adding some nodes
graph.write_on_node(u'm1', [u'c1', u'c2', u'c3', u'c4'], [u'p1', u'p2', u'p3'],{u'jack': set([u'1',u'2']), u'spare': u'youpi'})
graph.write_on_node(u"m2", [u"c1", u"c3", u"c4"], [u"p2", u"p3"],{u'sape': u'4139', u'guido': u'4127'})
graph.write_on_node(u"m3", [u"c1", u"c3", u"c4"], [u"p2", u"p3"],{})
graph.write_on_node(u"P1", [u"p2", u"p3"],[],{})

#printing some predecessors or successors
print graph.get_predecessors(u"m1")
print graph.get_successors(u"m1")
print graph.get_predecessors(u"p2")
print graph.get_successors(u"p2")
print graph.get_successors(u"c3")
print graph.get_successors(graph.root)
print graph.get_predecessors(u"c3")
コード例 #6
0
#importing directed_graph
from pygraph_redis.directed_graph import Directed_graph
import redis

#creating the redis connexion
r_server = redis.Redis("localhost")

#creating a basic logger
import logging
logging.basicConfig(format='%(message)s')
logger = logging.getLogger('redis')
logger.parent.setLevel(logging.DEBUG)

#creating the graph object
graph = Directed_graph(r_server, 'uniq', logger)

#adding some nodes
graph.write_on_node('m1', ['c1', 'c2', 'c3', 'c4'], ['p1', 'p2', 'p3'], {
    'jack': set(['1', '2']),
    'spare': 'youpi'
})
graph.write_on_node("m2", ["c1", "c3", "c4"], ["p2", "p3"], {
    'sape': '4139',
    'guido': '4127'
})
graph.write_on_node("m3", ["c1", "c3", "c4"], ["p2", "p3"], {})
graph.write_on_node("P1", ["p2", "p3"], [], {})

#printing some predecessors or successors
print(graph.get_predecessors("m1"))
コード例 #7
0

print(OKBLUE + "creating " + str(node_number) + " nodes")
#calling the generation function
generate_tree(node_number)

#creating the redis connexion
r_server = redis.Redis("localhost")

#creating a basic logger
logging.basicConfig(format='%(message)s')
logger = logging.getLogger('redis')
logger.parent.setLevel(logging.CRITICAL)

#creating the graph object
graph = Directed_graph(r_server, 'uniq', logger)


#we define two process to write the nodes
def process_one():
    for i in range(0, node_number, 2):
        graph.write_on_node(nodes[i], successors[i], predecessors[i],
                            fix_attributes)


def process_two():
    for i in range(1, node_number, 2):
        graph.write_on_node(nodes[i], successors[i], predecessors[i],
                            fix_attributes)

コード例 #8
0
ファイル: example.py プロジェクト: kakwa/pygraph_redis
#importing directed_graph
from pygraph_redis.directed_graph import Directed_graph
import redis

#creating the redis connexion
r_server = redis.Redis("localhost")

#creating a basic logger
import logging
logging.basicConfig(format = '%(message)s')
logger = logging.getLogger('redis')
logger.parent.setLevel(logging.DEBUG)

#creating the graph object
graph = Directed_graph(r_server, 'uniq', logger)

#adding some nodes
graph.write_on_node('m1', ['c1', 'c2', 'c3', 'c4'], ['p1', 'p2', 'p3'],{'jack': set(['1','2']), 'spare': 'youpi'})
graph.write_on_node("m2", ["c1", "c3", "c4"], ["p2", "p3"],{'sape': '4139', 'guido': '4127'})
graph.write_on_node("m3", ["c1", "c3", "c4"], ["p2", "p3"],{})
graph.write_on_node("P1", ["p2", "p3"],[],{})

#printing some predecessors or successors
print(graph.get_predecessors("m1"))
print(graph.get_successors("m1"))
print(graph.get_predecessors("p2"))
print(graph.get_successors("p2"))
print(graph.get_successors("c3"))
print(graph.get_successors(graph.root))
print(graph.get_predecessors("c3"))