コード例 #1
0
ファイル: demo_filter_with.py プロジェクト: Debilski/xdapy
#print m.find_with("Session").parent(m.find("Observer", {"name": ["%Alex%", "%Frank%"]})).all()

from xdapy.operators import gt, lt
#trials = m.find_with("Trial", {"_id": lambda id: id*id < 300}).parent(m.find_with("Session", {"_id": lt(300)}).parent(m.find("Observer", {"name": "%Alex%"}))).all()


trials = m.find_with("Trial", {"_id": lambda id: id*id < 300,
    "_parent": ("Session", {"_id": lt(300), "_parent": ("Observer", {"name": "%Alex%"})}),
    "_with": lambda entity: entity.id != 10})


# find_complex is more powerful but does not use SQLAlchemy
trials2 = m.find_complex("Trial", {"_id": lambda id: id*id < 300,
    "_any": [{"_parent": ("Session", {"_id": lt(300), "_parent": ("Observer", {"name": "%Alex%"})})}, # %Alex% will not work
             {"_parent": ("Session", {"_id": lt(300), "_parent": ("Observer", {"name": "Alexander"})})}
    ],
    "_with": lambda entity: entity.id != 10})

for t in trials:
    print t, t.parent.parent

print "..."

for t in trials2:
    print t, t.parent.parent

print "T", trials, trials2

#m.find("Trial", {"child": [("Session", {'_id': "2"}), {"name": "Frank"}])
コード例 #2
0
t1.attach("Observer", o1)
t2.attach("Observer", o1)
t3.attach("Observer", o2)
t4.attach("Observer", o2)

m.save(o1, o2, e1, e2, e3, t1, t2, t3, t4, s1_1, s1_2, s2_1, s2_2, s3_1, s4_1)

print set(str(o.parent) for o in m.find_all("Session"))

#obs = m.find("Observer", {"name": "%Frank%"}).all()

from xdapy.operators import gt, lt

#trials = m.find_with("Session", {"_parent": ("Experiment", {"project": "%E1%"})})
trials = m.find_complex("Session", {"_parent": ("Trial", {"count": gt(2)})})

print "T", trials


print "---"

trials = m.find_complex("Session", {"_id": lambda id: id*id < 300,
    "_parent":
        {"_any":
        [
        ("Trial", {
            "_id": lt(300),
            "_parent": ("Experiment", {"project": "E1"})
            }),
        ("Trial", {"_id": lt(300), "_parent": ("Experiment", {"project": "%E2%", "experimenter": "%X1%"})}),