示例#1
0
 def test_find_related(self):
     res = self.m.find_related("Experiment", ("Observer", {"age": between(20, 30)}))
     self.assertEqual(set(res), set([self.e1, self.e2]))
     res = self.m.find_related("Experiment", ("Observer", {"age": between(22, 30)}))
     self.assertEqual(set(res), set([self.e1, self.e2]))
     res = self.m.find_related("Experiment", ("Observer", {"age": between(26, 30)}))
     self.assertEqual(set(res), set([self.e2]))
     res = self.m.find_related("Experiment", ("Observer", {"age": ge(30)}))
     self.assertEqual(set(res), set([self.e2]))
     res = self.m.find_related("Experiment", ("Observer", {"age": lt(15)}))
     self.assertEqual(set(res), set())
示例#2
0
obs = m.find("Observer", {"name": "%Frank%"}).all()

print obs[0].data

import pdb
pdb.set_trace()

#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 "..."
示例#3
0
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%"})}),
        t1
        ]
        }
        ,
    "_with": lambda entiy: entiy.id != 10
    }
    )


#find_with(Session,
#  _all(["_id": lambda id: id*id < 300,
#        "_parent": _any(