python/foglamp/services/core/api/browser.py
async def asset_all_readings_summary(request):
    """ Browse all the assets for which we have recorded readings and
    return a summary for all sensors values for an asset code. The values that are
    returned are the min, max and average values of the sensor.

    Only one of hour, minutes or seconds should be supplied, if more than one time unit
    then the smallest unit will be picked

    The number of records return is default to a small number (20), this may be changed by supplying
    the query parameter ?limit=xx&skip=xx and it will not respect when datetime units is supplied

    :Example:
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary?seconds=60
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary?limit=10
    """
    try:
        # Get readings from asset_code
        asset_code = request.match_info.get('asset_code', '')
        # TODO: Use only the latest asset read to determine the data points to use. This
        # avoids reading every single reading into memory and creating a very big result set See FOGL-2635
        payload = PayloadBuilder().SELECT("reading").WHERE(["asset_code", "=", asset_code]).LIMIT(1).ORDER_BY(["user_ts", "desc"]).payload()
        _readings = connect.get_readings_async()
        results = await _readings.query(payload)
        if not results['rows']:
            raise web.HTTPNotFound(reason="{} asset_code not found".format(asset_code))

        # TODO: FOGL-1768 when support available from storage layer then avoid multiple calls
        # Find keys in readings
        reading_keys = list(results['rows'][-1]['reading'].keys())
        response = []
        _where = PayloadBuilder().WHERE(["asset_code", "=", asset_code]).chain_payload()
        if 'seconds' in request.query or 'minutes' in request.query or 'hours' in request.query:
            _and_where = where_clause(request, _where)
        else:
            # Add limit, offset clause
            _and_where = prepare_limit_skip_payload(request, _where)

        for reading in reading_keys:
            _aggregate = PayloadBuilder(_and_where).AGGREGATE(["min", ["reading", reading]],
                                                              ["max", ["reading", reading]],
                                                              ["avg", ["reading", reading]]) \
                .ALIAS('aggregate', ('reading', 'min', 'min'),
                       ('reading', 'max', 'max'),
                       ('reading', 'avg', 'average')).chain_payload()
            payload = PayloadBuilder(_aggregate).payload()
            results = await _readings.query(payload)
            response.append({reading: results['rows'][0]})
    except (KeyError, IndexError) as ex:
        raise web.HTTPNotFound(reason=ex)
    except (TypeError, ValueError) as ex:
        raise web.HTTPBadRequest(reason=ex)
    else:
        return web.json_response(response)
 Browse all the assets for which we have recorded readings and
    return a summary for all sensors values for an asset code. The values that are
    returned are the min, max and average values of the sensor.

    Only one of hour, minutes or seconds should be supplied, if more than one time unit
    then the smallest unit will be picked

    The number of records return is default to a small number (20), this may be changed by supplying
    the query parameter ?limit=xx&skip=xx and it will not respect when datetime units is supplied

    :Example:
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary?seconds=60
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary?limit=10
    
Browse all the assets for which we have recorded readings and
return a summary for all sensors values for an asset code. The values that are
returned are the min, max and average values of the sensor.

Only one of hour, minutes or seconds should be supplied, if more than one time unit
then the smallest unit will be picked

The number of records return is default to a small number (20), this may be changed by supplying
the query parameter ?limit=xx&skip=xx and it will not respect when datetime units is supplied
Browse all the assets for which we have recorded readings and return a summary for all sensors values for an asset code . The values that are returned are the min max and average values of the sensor . Only one of hour minutes or seconds should be supplied if more than one time unit then the smallest unit will be picked The number of records return is default to a small number ( 20 ) this may be changed by supplying the query parameter ?limit = xx&skip = xx and it will not respect when datetime units is supplied
async def asset_all_readings_summary(request):
    try:
        asset_code = request.match_info.get('asset_code', '')
        payload = PayloadBuilder().SELECT("reading").WHERE(["asset_code", "=", asset_code]).LIMIT(1).ORDER_BY(["user_ts", "desc"]).payload()
        _readings = connect.get_readings_async()
        results = await _readings.query(payload)
        if not results['rows']:
            raise web.HTTPNotFound(reason="{} asset_code not found".format(asset_code))
        reading_keys = list(results['rows'][-1]['reading'].keys())
        response = []
        _where = PayloadBuilder().WHERE(["asset_code", "=", asset_code]).chain_payload()
        if 'seconds' in request.query or 'minutes' in request.query or 'hours' in request.query:
            _and_where = where_clause(request, _where)
        else:
            _and_where = prepare_limit_skip_payload(request, _where)
        for reading in reading_keys:
            _aggregate = PayloadBuilder(_and_where).AGGREGATE(["min", ["reading", reading]],
                                                              ["max", ["reading", reading]],
                                                              ["avg", ["reading", reading]]) \
                .ALIAS('aggregate', ('reading', 'min', 'min'),
                       ('reading', 'max', 'max'),
                       ('reading', 'avg', 'average')).chain_payload()
            payload = PayloadBuilder(_aggregate).payload()
            results = await _readings.query(payload)
            response.append({reading: results['rows'][0]})
    except (KeyError, IndexError) as ex:
        raise web.HTTPNotFound(reason=ex)
    except (TypeError, ValueError) as ex:
        raise web.HTTPBadRequest(reason=ex)
    else:
        return web.json_response(response)
async def asset_all_readings_summary ( request ) : try : asset_code = request . match_info . get ( 'asset_code' , '' ) payload = PayloadBuilder ( ) . SELECT ( "reading" ) . WHERE ( [ "asset_code" , "=" , asset_code ] ) . LIMIT ( 1 ) . ORDER_BY ( [ "user_ts" , "desc" ] ) . payload ( ) _readings = connect . get_readings_async ( ) results = await _readings . query ( payload ) if not results [ 'rows' ] : raise web . HTTPNotFound ( reason = "{} asset_code not found" . format ( asset_code ) ) reading_keys = list ( results [ 'rows' ] [ - 1 ] [ 'reading' ] . keys ( ) ) response = [ ] _where = PayloadBuilder ( ) . WHERE ( [ "asset_code" , "=" , asset_code ] ) . chain_payload ( ) if 'seconds' in request . query or 'minutes' in request . query or 'hours' in request . query : _and_where = where_clause ( request , _where ) else : _and_where = prepare_limit_skip_payload ( request , _where ) for reading in reading_keys : _aggregate = PayloadBuilder ( _and_where ) . AGGREGATE ( [ "min" , [ "reading" , reading ] ] , [ "max" , [ "reading" , reading ] ] , [ "avg" , [ "reading" , reading ] ] ) . ALIAS ( 'aggregate' , ( 'reading' , 'min' , 'min' ) , ( 'reading' , 'max' , 'max' ) , ( 'reading' , 'avg' , 'average' ) ) . chain_payload ( ) payload = PayloadBuilder ( _aggregate ) . payload ( ) results = await _readings . query ( payload ) response . append ( { reading : results [ 'rows' ] [ 0 ] } ) except ( KeyError , IndexError ) as ex : raise web . HTTPNotFound ( reason = ex ) except ( TypeError , ValueError ) as ex : raise web . HTTPBadRequest ( reason = ex ) else : return web . json_response ( response )
Browse all the assets for which we have recorded readings and
return a summary for all sensors values for an asset code.
Browse all the assets for which we have recorded readings and return a summary for all sensors values for an asset code .
""" Browse all the assets for which we have recorded readings and
    return a summary for all sensors values for an asset code. The values that are
    returned are the min, max and average values of the sensor.

    Only one of hour, minutes or seconds should be supplied, if more than one time unit
    then the smallest unit will be picked

    The number of records return is default to a small number (20), this may be changed by supplying
    the query parameter ?limit=xx&skip=xx and it will not respect when datetime units is supplied

    :Example:
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary?seconds=60
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/summary?limit=10
    """ # Get readings from asset_code # TODO: Use only the latest asset read to determine the data points to use. This # avoids reading every single reading into memory and creating a very big result set See FOGL-2635 # TODO: FOGL-1768 when support available from storage layer then avoid multiple calls # Find keys in readings # Add limit, offset clause
request
Example
None