Exemple #1
0
    def render_GET(self, request):
        """The GET method exposes a RESTful API to ARD functions.

        This lets clients look at tags and get data.
        """
        if len(request.prepath) == 1:
            return self.send_reply((request, {'Contents': ['streams', 'query', 'data', 
                                                           'next', 'prev', 'tags',
                                                           'operators']}))
        # start by looking up the set of streams we are going to operate on
        path = map(lambda x: x.replace('__', '/'), request.prepath[2:])
        path = map(urllib.unquote, path)
        method = request.prepath[1]

        # dispatch based on the method name
        if method != 'query':
            if len(path) % 2 != 0:
                request.setResponseCode(400)
                request.finish()
                return server.NOT_DONE_YET
            path.append('uuid')            
        if method == 'query':
            if 'q' in request.args:
                return self.render_POST(request, request.args['q'][0])
            else:
                # this allows a user to enumerate tags
                d = build_query(self.db,
                                request,
                                zip(path[::2], 
                                    path[1::2] + [None]))
                d.addCallback(lambda r: self.generic_extract_result(request, r))
                d.addCallback(self.send_reply)
        elif method == 'tags':
            # retrieve tags
            d = build_tag_query(self.db,
                                request, 
                                zip(path[::2], 
                                    path[1::2] + [None]))
            d.addCallback(lambda r: self.tag_extract_result(request, r))
            d.addCallback(self.send_reply)
        elif method in ['data', 'next', 'prev']:
            # retrieve data
            d = self.db.runQuery("""SELECT uuid, id FROM stream WHERE
id IN """ + build_inner_query(request,
                              zip(path[::2], 
                                  path[1::2] + [None]))[0])
            d.addCallback(log_time, time.time())
            d.addCallback(lambda r: data_load_result(request, method, r))
            d.addCallback(lambda d: (request, d))
            d.addCallback(self.send_data_reply)
        elif method == 'operators':
            self.send_reply((request, stream.installed_ops.keys()))
        else:
            request.setResponseCode(404)
            request.finish()

        return server.NOT_DONE_YET
Exemple #2
0
    def render_GET(self, request):
        """The GET method exposes a RESTful API to ARD functions.

        This lets clients look at tags and get data.
        """
        if len(request.prepath) == 1:
            return self.send_reply((request, {
                'Contents': [
                    'streams', 'query', 'data', 'next', 'prev', 'tags',
                    'operators'
                ]
            }))
        # start by looking up the set of streams we are going to operate on
        path = map(lambda x: x.replace('__', '/'), request.prepath[2:])
        path = map(urllib.unquote, path)
        method = request.prepath[1]

        # dispatch based on the method name
        if method != 'query':
            if len(path) % 2 != 0:
                request.setResponseCode(400)
                request.finish()
                return server.NOT_DONE_YET
            path.append('uuid')
        if method == 'query':
            if 'q' in request.args:
                return self.render_POST(request, request.args['q'][0])
            else:
                # this allows a user to enumerate tags
                d = build_query(self.db, request,
                                zip(path[::2], path[1::2] + [None]))
                d.addCallback(
                    lambda r: self.generic_extract_result(request, r))
                d.addCallback(self.send_reply)
        elif method == 'tags':
            # retrieve tags
            d = build_tag_query(self.db, request,
                                zip(path[::2], path[1::2] + [None]))
            d.addCallback(lambda r: self.tag_extract_result(request, r))
            d.addCallback(self.send_reply)
        elif method in ['data', 'next', 'prev']:
            # retrieve data
            d = self.db.runQuery("""SELECT uuid, id FROM stream WHERE
id IN """ + build_inner_query(request, zip(path[::2], path[1::2] + [None]))[0])
            d.addCallback(log_time, time.time())
            d.addCallback(lambda r: data_load_result(request, method, r))
            d.addCallback(lambda d: (request, d))
            d.addCallback(self.send_data_reply)
        elif method == 'operators':
            self.send_reply((request, stream.installed_ops.keys()))
        else:
            request.setResponseCode(404)
            request.finish()

        return server.NOT_DONE_YET
def extract_data(streams, method, start, end, limit=10, streamlimit=10, ndarray=False):
    request = Request()
    request.args = {
        'starttime' : [start],
        'endtime' : [end],
        'limit' : [limit],
        'streamlimit' : [streamlimit]
        }
    d = data_load_result(request, method, streams, ndarray=ndarray, as_smapobj=True)
    d.addCallback(_extract_data)
    d.addErrback(_errback)    
    return d
Exemple #4
0
def extract_data(streams,
                 method,
                 start,
                 end,
                 limit=10,
                 streamlimit=10,
                 ndarray=False):
    request = Request()
    request.args = {
        'starttime': [start],
        'endtime': [end],
        'limit': [limit],
        'streamlimit': [streamlimit]
    }
    d = data_load_result(request,
                         method,
                         streams,
                         ndarray=ndarray,
                         as_smapobj=True)
    d.addCallback(_extract_data)
    d.addErrback(_errback)
    return d