Mercurial > hg > ltpda
comparison m-toolbox/test/high_level_queries/test_high_level_query.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function objs = test_high_level_query | |
2 | |
3 % Try to get some data for a particular channel between t1 and t2 | |
4 % | |
5 % M Hewitson | |
6 | |
7 | |
8 channels = {'channelX', 'channelZ'}; | |
9 ts = timespan('2009-01-01 00:00:00', '2009-01-01 00:30:00'); | |
10 | |
11 hostname = 'btlab.science.unitn.it'; | |
12 database_name = 'ltpda_test'; | |
13 | |
14 | |
15 % Make db connection | |
16 conn = utils.mysql.connect(hostname, database_name); | |
17 | |
18 objs = hlq(conn, channels, ts); | |
19 | |
20 % Close connection | |
21 close(conn); | |
22 | |
23 | |
24 % A prototype for the kind of high-level query functions we might need | |
25 function objsOut = hlq(conn, channels, ts) | |
26 | |
27 objsOut = []; | |
28 | |
29 for j=1:length(channels) | |
30 | |
31 channel = channels{j}; | |
32 | |
33 q = ['select objmeta.obj_id from objmeta,ao,tsdata ' ... | |
34 'where objmeta.obj_id=ao.obj_id ' ... | |
35 'and ao.data_id=tsdata.id ' ... | |
36 sprintf('and objmeta.name=''%s''', channel) ... | |
37 sprintf('and tsdata.t0+INTERVAL tsdata.nsecs SECOND >= ''%s''', char(ts.startT)) ... | |
38 sprintf('and tsdata.t0 <= ''%s''', char(ts.endT))]; | |
39 | |
40 % execute query | |
41 info = utils.mysql.dbquery(conn, q) | |
42 | |
43 % collect objects | |
44 objs = ltpda_uo.retrieve(conn, [info{:}]); | |
45 | |
46 % join these up | |
47 ojn = join([objs{:}]); | |
48 | |
49 % split out the bit we want | |
50 os = split(ojn, plist('split_type', 'interval', 'timespan', ts)); | |
51 | |
52 objsOut = [objsOut os]; | |
53 | |
54 end | |
55 |