示例#1
0
def grapher():
    graph = Graph('foo2')
    def cleanup(): #@IgnorePep8
        graph._db.shutdown()
        import shutil
        shutil.rmtree('foo2')
    graph.on_abort(cleanup)
    with graph.transaction():
        graph.register(Tag)
        graph.register(Question)
        graph.register(Pro)
        graph.register(Con)
        graph.register(Idea)
        graph.nodes.w.create_index('roots')
        Question.referrer(user=1)
        Idea.referrer(user=1)
        Pro.referrer(user=1)
        Con.referrer(user=1)
        Tag.referrer(user=1)
        tag_1 = Tag.nodes.create(_status=1, text='wicked problem', user=1)
        tag_1.index_under('tags', 'name', 'wicked problem')
        tag_2 = Tag.nodes.create(text='avoid', user=1, _status=1)
        tag_2.index_under('tags', 'name', 'avoid')
        root = tag_2.n.root()
        root.data.public.text = 'This is the root'
        root.save()
        question_0 = Question.anchorer(user=1)
        question_1 = Question(
            _status=1,
            down=0,
            text='How do you avoid the wicked problem?',
            up=0,
            user=1,
        )
        question_1.save()
        question_1.weigh_anchor(user=1)
        question_1.index_under('questions', 'tag', 'wicked problem')
        tag_1.link('TAGGED', question_1)
        question_1.index_under('questions', 'tag', 'avoid')
        tag_2.link('TAGGED', question_1)
        question_1.index_under('questions', 'prime', True)
        question_2 = Question(
            _status=1,
            down=0,
            text="How do you even know it's a wicked problem?",
            up=0,
            user=1,
        )
        question_2.save()
        question_1.questions.add(question_2, user=1)
        idea_2 = question_2.ideas.create(
            _status=1,
            down=0,
            text="You are confused",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        pro_1 = idea_2.pros.create(
            _status=1,
            down=0,
            text="I'd certainly feel confused",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        pro_1.up = 6
        pro_1.text = "I'd certainly really feel confused"
        pro_1.user = 2
        pro_1.save()
        con_1 = idea_2.cons.create(
            _status=1,
            down=0,
            text="I don't feel confused",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        con_1.save()
        idea_3 = question_2.ideas.create(
            _status=1,
            down=0,
            text="You are flummoxed",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        question_3 = idea_3.questions.create(
            _status=1,
            down=0,
            text="Isn't that the same as confusion?",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        idea_4 = question_3.ideas.create(
            _status=1,
            down=0,
            text="No",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        idea_4.text = 'No, Really'
        idea_4.save()
        idea_5 = question_3.ideas.create(
            _status=1,
            down=0,
            text='Yes, but faster!',
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        con_3 = idea_5.cons.create(
            _status=1,
            down=0,
            text="Spans both positions",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        con_3.user = 2
        con_3.save()
        idea_6 = question_2.ideas.create(
            _status=1,
            down=0,
            text="You are surrounded by hellfire",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        question_4 = idea_6.questions.create(
            _status=1,
            down=0,
            text="Is there no appeal from hellfire?",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        idea_7 = question_4.ideas.create(
            _status=1,
            down=0,
            text="You better hope there's an appeal",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        idea_1 = question_1.ideas.create(
            _status=1,
            down=0,
            text='DUCK!',
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        question_5 = idea_7.questions.create(
            _status=1,
            down=0,
            text="Isn't that a simple problem?",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        question_5.up = 15
        question_5.save()
        pro_2 = idea_1.pros.create(
            _status=1,
            down=0,
            text="It's simple",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        pro_4 = pro_2.fork()
        pro_4.save()
        pro_2.user = pro_4.user
        pro_2.save()
        pro_3 = idea_1.pros.create(
            _status=1,
            down=0,
            text='It avoids wicked problems shaped like projectiles',
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        pro_3.down = 1
        pro_3.save()
        con_4 = idea_1.cons.create(
            _status=1,
            down=0,
            text="It may not actually avoid the problem",
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        con_4.up = 1
        con_4.save()
        con_5 = idea_1.cons.create(
            _status=1,
            _versions=0,
            down=0,
            text='Harder to do while asleep',
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        con_5.text = 'Harder to do while asleep with your eyes closed'
        con_5.save()
        con_5.text = 'Much harder to do while asleep with your eyes closed'
        con_5.save()
        pro_9 = idea_1.pros.create(
            _status=1,
            down=0,
            text='It avoids wicked problems shaped like projectiles',
            up=0,
            user=1,
            link_props=dict(user=1),
        )
        pro_9.delete()

    try:
        # questions
        ins = question_1.nodes.ins
        assert ins[3] == idea_1
        assert ins[2] == question_2
        assert ins[1] == question_0.anchor
        assert ins[0] == question_0.reference
        outs = question_1.nodes.outs
        questions = question_1.questions
        link_outs = question_1.links.outs
        assert link_outs[3].kind == 'IDEA_ABOUT'
        assert link_outs[3] == Idea.links.get(link_outs[3].id)
        assert link_outs[2].kind == 'QUESTION_ABOUT'
        assert link_outs[1].kind == 'QUESTION_ROOTED_IN'
        assert link_outs[0].kind == 'QUESTION_NODE_OF'
        link_ins = question_1.links.ins
        ideas = question_1.ideas
        tags = question_1.tags
        assert question_1.data.private._status == 1
        assert question_1.down == 0
        assert question_1.text == 'How do you avoid the wicked problem?'
        assert question_1.up == 0
        assert question_1.user == 1
        assert question_2.data.private._status == 1
        assert question_2.down == 0
        assert question_2.text == escape(
            "How do you even know it's a wicked problem?"
        )
        assert question_2.up == 0
        assert question_2.user == 1
        assert question_3.data.private._status == 1
        assert question_3.down == 0
        assert question_3.text == escape("Isn't that the same as confusion?")
        assert question_3.up == 0
        assert question_3.user == 1
        assert question_4.data.private._status == 1
        assert question_4.down == 0
        assert question_4.text == escape("Is there no appeal from hellfire?")
        assert question_4.up == 0
        assert question_4.user == 1
        assert question_5.data.private._status == 1
        assert question_5.down == 0
        assert question_5.up == 15
        assert question_5.text == escape("Isn't that a simple problem?")
        assert question_5.user == 1
        # ideas
        assert idea_1.data.private._status == 1
        assert idea_1.down == 0
        assert idea_1.text == 'DUCK!'
        assert idea_1.up == 0
        assert idea_1.user == 1
        assert idea_2.data.private._status == 1
        assert idea_2.down == 0
        assert idea_2.text == "You are confused"
        assert idea_2.up == 0
        assert idea_2.user == 1
        assert idea_3.data.private._status == 1
        assert idea_3.down == 0
        assert idea_3.text == "You are flummoxed"
        assert idea_3.up == 0
        assert idea_3.user == 1
        assert idea_4.data.private._status == 1
        assert idea_4.down == 0
        assert idea_4.text == 'No, Really'
        assert idea_4.up == 0
        assert idea_4.user == 1
        assert idea_5.data.private._status == 1
        assert idea_5.down == 0
        assert idea_5.text == 'Yes, but faster!'
        assert idea_5.up == 0
        assert idea_5.user == 1
        assert idea_6.data.private._status == 1
        assert idea_6.down == 0
        assert idea_6.text == "You are surrounded by hellfire"
        assert idea_6.up == 0
        assert idea_6.user == 1
        # pros
        assert pro_1.data.private._status == 1
        assert pro_1.down == 0
        assert pro_1.text == escape("I'd certainly really feel confused")
        assert pro_1.up == 6
        assert pro_1.user == 2
        assert pro_2.data.private._status == 1
        assert pro_2.down == 0
        assert pro_2.text == escape("It's simple")
        assert pro_2.up == 0
        assert pro_2.user == 1
        assert pro_3.data.private._status == 1
        assert pro_3.down == 1
        assert pro_3.text == escape(
            'It avoids wicked problems shaped like projectiles'
        )
        assert pro_3.up == 0
        assert pro_3.user == 1
        assert pro_4.data.private._status == 1
        assert pro_4.down == 0
        assert pro_4.text == escape("It's simple")
        assert pro_4.up == 0
        assert pro_4.user == 1
        # cons
        assert con_1.data.private._status == 1
        assert con_1.down == 0
        assert con_1.text == escape("I don't feel confused")
        assert con_1.up == 0
        assert con_1.user == 1
        assert con_3.data.private._status == 1
        assert con_3.down == 0
        assert con_3.text == "Spans both positions"
        assert con_3.up == 0
        assert con_3.user == 2
        assert con_4.data.private._status == 1
        assert con_4.down == 0
        assert con_4.text == "It may not actually avoid the problem"
        assert con_4.up == 1
        assert con_4.user == 1
        assert con_5.data.private._status == 1
        assert con_5.down == 0
        assert con_5.text == escape(
            'Much harder to do while asleep with your eyes closed'
        )
        assert con_5.up == 0
        assert con_5.user == 1
        con_6 = Con.n.get(con_5.id)
        assert con_6.user == con_5.user
        assert con_6.down == con_5.down
        assert con_6.text == con_5.text
        assert con_6.data.private._status == con_5.data.private._status
        # tags
        assert tag_1.text == 'wicked problem'
        assert tag_1.user == 1
        assert tag_2.text == 'avoid'
        assert tag_2.user == 1
        assert root.data.public.text == 'This is the root'
    finally:
        cleanup()
示例#2
0
def grapher():
    graph = Graph('foo')
    def cleanup(): #@IgnorePep8
        graph._db.shutdown()
        import shutil
        try:
            shutil.rmtree('foo')
        except OSError:
            pass
    graph.on_anyway(cleanup)
    with graph.transaction():
        gn = graph.nodes
        gn.w.create_index('roots')
        gn.w.create_index('questions')
        gn.w.create_index('question_text', fts=True)
        gn.w.create_index('ideas')
        gn.w.create_index('idea_text', fts=True)
        gn.w.create_index('pros')
        gn.w.create_index('pro_text', fts=True)
        gn.w.create_index('cons')
        gn.w.create_index('con_text', fts=True)
        gn.w.create_index('tags')
        root = gn.root()
        # question base create
        question = gn.create(text='question reference node')
        question.index_under('roots', 'reference', 'question')
        question.link('QUESTION_REFERENCE_FOR', root)
        # idea base create
        idea = gn.create(text='idea reference node')
        idea.index_under('roots', 'reference', 'idea')
        idea.link('IDEA_REFERENCE_FOR', root)
        # pro base create
        pro = gn.create(text='pro reference node')
        pro.index_under('roots', 'reference', 'pro')
        pro.link('PRO_REFERENCE_FOR', root)
        # con base create
        con = gn.create(text='con reference node')
        con.link('CON_REFERENCE_FOR', root)
        con.index_under('roots', 'reference', 'con')
        # tag base create
        tag = gn.create(text='tag reference node')
        tag.link('TAG_REFERENCE_FOR', root)
        tag.index_under('roots', 'reference', 'tag')
        # example tags
        tag_1 = gn.create(
            _model='tag', _status=1, text='wicked problem', user=1,
        )
        tag_1.index_under('tags', 'name', 'wicked problem')
        tag_1.link('TAG_NODE_OF', tag, user=1)
        tag_2 = gn.create(text='avoid', user=1, _model='tag', _status=1)
        tag_2.index_under('tags', 'name', 'avoid')
        tag_2.link('TAG_NODE_OF', tag, user=1)
        # prime question
        question_0 = gn.create(
            _model='root_question',
            text='What is the prime question?',
            user=1,
        )
        question_0.link('QUESTION_NODE_OF', question, user=1)
        question_0.index_under('roots', 'root', 'question')
        # root example question
        question_1 = gn.create(
            _model='question',
            _status=1,
            down=0,
            text='How do you avoid the wicked problem?',
            up=0,
            user=1,
        )
        question_1.index_by('questions', '_created', 'user')
        question_1.index_by('question_text', 'text')
        question_1.link('QUESTION_NODE_OF', question, user=1)
        question_1.link('QUESTION_ROOTED_IN', question_0, user=1)
        # tag example question
        question_1.index_under('questions', 'tag', 'wicked problem')
        tag_1.link('TAGGED', question_1)
        question_1.index_under('questions', 'tag', 'avoid')
        tag_2.link('TAGGED', question_1)
        question_1.index_under('questions', 'prime', True)
        question_2 = gn.create(
            _model='question',
            _status=1,
            down=0,
            text="How do you even know it's a wicked problem?",
            up=0,
            user=1,
        )
        question_2.index_by('questions', '_created', 'user')
        question_2.index_by('question_text', 'text')
        question_2.link('QUESTION_NODE_OF', question, user=1)
        question_2.link('QUESTION_ABOUT', question_1, user=1)
        idea_2 = gn.create(
            _model='idea',
            _status=1,
            down=0,
            text="You are confused",
            up=0,
            user=1,
        )
        idea_2.index_by('ideas', '_created', 'user')
        idea_2.index_by('idea_text', 'text')
        idea_2.link('IDEA_NODE_OF', idea, user=1)
        idea_2.link('IDEA_ABOUT', question_2, user=1)
        pro_1 = gn.create(
            _model='pro',
            _status=1,
            down=0,
            text="I'd certainly feel confused",
            up=0,
            user=1,
        )
        pro_1.index_by('pros', '_created', 'user')
        pro_1.index_by('pro_text', 'text')
        pro_1.link('PRO_NODE_OF', pro, user=1)
        pro_1.link('PRO_FOR', idea_2, user=1)
        con_1 = gn.create(
            _model='con',
            _status=1,
            down=0,
            text="I don't feel confused",
            up=0,
            user=1,
        )
        con_1.index_by('cons', '_created', 'user')
        con_1.index_by('con_text', 'text')
        con_1.link('CON_NODE_OF', con, user=1)
        con_1.link('CON_AGAINST', idea_2, user=1)
        idea_3 = gn.create(
            _model='idea',
            _status=1,
            down=0,
            text="You are flummoxed",
            up=0,
            user=1,
        )
        idea_3.index_by('ideas', '_created', 'user')
        idea_3.index_by('idea_text', 'text')
        idea_3.link('IDEA_NODE_OF', idea, user=1)
        idea_3.link('IDEA_ABOUT', question_2, user=1)
        question_3 = gn.create(
            _model='question',
            _status=1,
            down=0,
            text="Isn't that the same as confusion?",
            up=0,
            user=1,
        )
        question_3.index_by('questions', '_created', 'user')
        question_3.index_by('question_text', 'text')
        question_3.link('QUESTION_NODE_OF', question, user=1)
        question_3.link('QUESTION_ABOUT', idea_3, user=1,)
        idea_4 = gn.create(
            _model='idea',
            _status=1,
            down=0,
            text="No",
            up=0,
            user=1,
        )
        idea_4.index_by('ideas', '_created', 'user')
        idea_4.index_by('idea_text', 'text')
        idea_4.link('IDEA_NODE_OF', idea, user=1)
        idea_4.link('IDEA_ABOUT', question_3, user=1)
        idea_5 = gn.create(
            _model='idea',
            _status=1,
            down=0,
            text='Yes, but faster!',
            up=0,
            user=1,
        )
        idea_5.index_by('ideas', '_created', 'user')
        idea_5.index_by('idea_text', 'text')
        idea_5.link('IDEA_NODE_OF', idea, user=1)
        idea_5.link('IDEA_ABOUT', question_3, user=1)
        con_3 = gn.create(
            _model='con',
            _status=1,
            down=0,
            text="Spans both positions",
            up=0,
            user=1,
        )
        con_3.index_by('cons', '_created', 'user')
        con_3.index_by('con_text', 'text')
        con_3.link('CON_NODE_OF', con, user=1)
        con_3.link('CON_AGAINST', idea_5, user=1)
        idea_6 = gn.create(
            _model='idea',
            _status=1,
            down=0,
            text="You are surrounded by hellfire",
            up=0,
            user=1,
        )
        idea_6.index_by('ideas', '_created', 'user')
        idea_6.index_by('idea_text', 'text')
        idea_6.link('IDEA_NODE_OF', idea, user=1)
        idea_6.link('IDEA_ABOUT', question_2, user=1)
        question_4 = gn.create(
            _model='question',
            _status=1,
            down=0,
            text="Is there no appeal from hellfire?",
            up=0,
            user=1,
        )
        question_4.index_by('questions', '_created', 'user')
        question_4.index_by('question_text', 'text')
        question_4.link('QUESTION_NODE_OF', question, user=1)
        question_4.link('QUESTION_ABOUT', idea_6, user=1)
        idea_7 = gn.create(
            _model='idea',
            _status=1,
            down=0,
            text="You better hope there's an appeal",
            up=0,
            user=1,
        )
        idea_7.index_by('ideas', '_created', 'user')
        idea_7.index_by('idea_text', 'text')
        idea_7.link('IDEA_NODE_OF', idea, user=1)
        idea_7.link('IDEA_ABOUT', question_4, user=1)
        # idea 1 "DUCK"
        idea_1 = gn.create(
            _model='idea',
            _status=1,
            down=0,
            text='DUCK!',
            up=0,
            user=1,
        )
        idea_1.index_by('ideas', '_created', 'user')
        idea_1.index_by('idea_text', 'text')
        idea_1.link('IDEA_NODE_OF', idea, user=1)
        idea_1.link('IDEA_ABOUT', question_1, user=1)
        question_5 = gn.create(
            _model='pro',
            _status=1,

            down=0,
            text="Isn't that a simple problem?",
            up=0,
            user=1,
        )
        question_5.index_by('questions', '_created', 'user')
        question_5.index_by('question_text', 'text')
        question_5.link('QUESTION_NODE_OF', question, user=1)
        question_5.link('QUESTION_ABOUT', idea_7, user=1)
        # pros against idea 1
        pro_2 = gn.create(
            _model='pro',
            _status=1,
            down=0,
            text="It's simple",
            up=0,
            user=1,
        )
        pro_2.index_by('pros', '_created', 'user')
        pro_2.index_by('pro_text', 'text')
        pro_2.link('PRO_NODE_OF', pro, user=1)
        pro_2.link('PRO_FOR', idea_1, user=1)
        pro_3 = gn.create(
            _model='pro',
            _status=1,
            down=0,
            text='It avoids wicked problems shaped like projectiles',
            up=0,
            user=1,
        )
        pro_3.index_by('pros', '_created', 'user')
        pro_3.index_by('pro_text', 'text')
        pro_3.link('PRO_NODE_OF', pro, user=1)
        pro_3.link('PRO_FOR', idea_1, user=1)
        con_4 = gn.create(
            _model='con',
            _status=1,
            down=0,
            text="It may not actually avoid the problem",
            up=0,
            user=1,
        )
        con_4.index_by('cons', '_created', 'user')
        con_4.index_by('con_text', 'text')
        con_4.link('CON_NODE_OF', con, user=1)
        con_4.link('CON_AGAINST', idea_1, user=1)
        con_5 = gn.create(
            _model='con',
            _status=1,
            down=0,
            text='Harder to do while asleep',
            up=0,
            user=1,
        )
        con_5.index_by('cons', '_created', 'user')
        con_5.index_by('con_text', 'text')
        con_5.link('CON_NODE_OF', con, user=1)
        con_5.link('CON_AGAINST', idea_1, user=1)