diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/test/high_level_queries/test_high_level_query.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,55 @@
+function objs = test_high_level_query
+
+% Try to get some data for a particular channel between t1 and t2
+%
+% M Hewitson
+
+
+channels = {'channelX', 'channelZ'};
+ts       = timespan('2009-01-01 00:00:00', '2009-01-01 00:30:00');
+
+hostname = 'btlab.science.unitn.it';
+database_name = 'ltpda_test';
+
+
+% Make db connection
+conn = utils.mysql.connect(hostname, database_name);
+
+objs = hlq(conn, channels, ts);
+
+% Close connection
+close(conn);
+
+
+% A prototype for the kind of high-level query functions we might need
+function objsOut = hlq(conn, channels, ts)
+
+objsOut = [];
+
+for j=1:length(channels)
+
+  channel = channels{j};
+
+  q =      ['select objmeta.obj_id from objmeta,ao,tsdata ' ...
+            'where objmeta.obj_id=ao.obj_id ' ...
+            'and ao.data_id=tsdata.id ' ...
+    sprintf('and objmeta.name=''%s''', channel) ...
+    sprintf('and tsdata.t0+INTERVAL tsdata.nsecs SECOND  >= ''%s''', char(ts.startT)) ...
+    sprintf('and tsdata.t0 <= ''%s''', char(ts.endT))];
+
+  % execute query
+  info = utils.mysql.dbquery(conn, q)
+  
+  % collect objects  
+  objs = ltpda_uo.retrieve(conn, [info{:}]);
+  
+  % join these up
+  ojn = join([objs{:}]);
+  
+  % split out the bit we want
+  os = split(ojn, plist('split_type', 'interval', 'timespan', ts));
+  
+  objsOut = [objsOut os];
+  
+end
+