python/foglamp/services/core/api/browser.py
async def asset_averages(request):
    """ Browse all the assets for which we have recorded readings and
    return a series of averages per second, minute or hour.

    The readings averaged can also be time limited by use of the query
    parameter seconds=sss. This defines a number of seconds that the reading
    must have been processed in. Older readings than this will not be summarised.

    The readings averaged can also be time limited by use of the query
    parameter minutes=mmm. This defines a number of minutes that the reading
    must have been processed in. Older readings than this will not be summarised.

    The readings averaged can also be time limited by use of the query
    parameter hours=hh. This defines a number of hours that the reading
    must have been processed in. Older readings than this will not be summarised.

    Only one of hour, minutes or seconds should be supplied

    The amount of time covered by each returned value is set using the
    query parameter group. This may be set to seconds, minutes or hours

    Returns:
            on the basis of
            SELECT min((reading->>'reading')::float) AS "min",
                   max((reading->>'reading')::float) AS "max",
                   avg((reading->>'reading')::float) AS "average",
                   to_char(user_ts, 'YYYY-MM-DD HH24:MI:SS') AS "timestamp"
            FROM foglamp.readings
                   WHERE asset_code = 'asset_code' AND
                     reading ? 'reading'
            GROUP BY to_char(user_ts, 'YYYY-MM-DD HH24:MI:SS')
            ORDER BY timestamp DESC;

    :Example:
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series
            curl -sX GET "http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?limit=1&skip=1"
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?hours=1
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?minutes=60
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?seconds=3600
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=seconds
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=minutes
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=hours
    """
    asset_code = request.match_info.get('asset_code', '')
    reading = request.match_info.get('reading', '')

    ts_restraint = 'YYYY-MM-DD HH24:MI:SS'
    if 'group' in request.query and request.query['group'] != '':
        _group = request.query['group']
        if _group in ('seconds', 'minutes', 'hours'):
            if _group == 'seconds':
                ts_restraint = 'YYYY-MM-DD HH24:MI:SS'
            elif _group == 'minutes':
                ts_restraint = 'YYYY-MM-DD HH24:MI'
            elif _group == 'hours':
                ts_restraint = 'YYYY-MM-DD HH24'
        else:
            raise web.HTTPBadRequest(reason="{} is not a valid group".format(_group))

    _aggregate = PayloadBuilder().AGGREGATE(["min", ["reading", reading]], ["max", ["reading", reading]],
                                            ["avg", ["reading", reading]]) \
        .ALIAS('aggregate', ('reading', 'min', 'min'), ('reading', 'max', 'max'),
               ('reading', 'avg', 'average')).chain_payload()
    _where = PayloadBuilder(_aggregate).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
        _and_where = prepare_limit_skip_payload(request, _where)

    # Add the GROUP BY and ORDER BY timestamp DESC
    _group = PayloadBuilder(_and_where).GROUP_BY("user_ts").ALIAS("group", ("user_ts", "timestamp")) \
        .FORMAT("group", ("user_ts", ts_restraint)).chain_payload()
    payload = PayloadBuilder(_group).ORDER_BY(["user_ts", "desc"]).payload()
    results = {}
    try:
        _readings = connect.get_readings_async()
        results = await _readings.query(payload)
        response = results['rows']
    except KeyError:
        raise web.HTTPBadRequest(reason=results['message'])
    else:
        return web.json_response(response)
 Browse all the assets for which we have recorded readings and
    return a series of averages per second, minute or hour.

    The readings averaged can also be time limited by use of the query
    parameter seconds=sss. This defines a number of seconds that the reading
    must have been processed in. Older readings than this will not be summarised.

    The readings averaged can also be time limited by use of the query
    parameter minutes=mmm. This defines a number of minutes that the reading
    must have been processed in. Older readings than this will not be summarised.

    The readings averaged can also be time limited by use of the query
    parameter hours=hh. This defines a number of hours that the reading
    must have been processed in. Older readings than this will not be summarised.

    Only one of hour, minutes or seconds should be supplied

    The amount of time covered by each returned value is set using the
    query parameter group. This may be set to seconds, minutes or hours

    Returns:
            on the basis of
            SELECT min((reading->>'reading')::float) AS "min",
                   max((reading->>'reading')::float) AS "max",
                   avg((reading->>'reading')::float) AS "average",
                   to_char(user_ts, 'YYYY-MM-DD HH24:MI:SS') AS "timestamp"
            FROM foglamp.readings
                   WHERE asset_code = 'asset_code' AND
                     reading ? 'reading'
            GROUP BY to_char(user_ts, 'YYYY-MM-DD HH24:MI:SS')
            ORDER BY timestamp DESC;

    :Example:
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series
            curl -sX GET "http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?limit=1&skip=1"
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?hours=1
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?minutes=60
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?seconds=3600
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=seconds
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=minutes
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=hours
    
Browse all the assets for which we have recorded readings and
return a series of averages per second, minute or hour.

The readings averaged can also be time limited by use of the query
parameter seconds=sss. This defines a number of seconds that the reading
must have been processed in. Older readings than this will not be summarised.

The readings averaged can also be time limited by use of the query
parameter minutes=mmm. This defines a number of minutes that the reading
must have been processed in. Older readings than this will not be summarised.

The readings averaged can also be time limited by use of the query
parameter hours=hh. This defines a number of hours that the reading
must have been processed in. Older readings than this will not be summarised.

Only one of hour, minutes or seconds should be supplied

The amount of time covered by each returned value is set using the
query parameter group. This may be set to seconds, minutes or hours


Browse all the assets for which we have recorded readings and return a series of averages per second minute or hour . The readings averaged can also be time limited by use of the query parameter seconds = sss . This defines a number of seconds that the reading must have been processed in . Older readings than this will not be summarised . The readings averaged can also be time limited by use of the query parameter minutes = mmm . This defines a number of minutes that the reading must have been processed in . Older readings than this will not be summarised . The readings averaged can also be time limited by use of the query parameter hours = hh . This defines a number of hours that the reading must have been processed in . Older readings than this will not be summarised . Only one of hour minutes or seconds should be supplied The amount of time covered by each returned value is set using the query parameter group . This may be set to seconds minutes or hours
async def asset_averages(request):
    asset_code = request.match_info.get('asset_code', '')
    reading = request.match_info.get('reading', '')
    ts_restraint = 'YYYY-MM-DD HH24:MI:SS'
    if 'group' in request.query and request.query['group'] != '':
        _group = request.query['group']
        if _group in ('seconds', 'minutes', 'hours'):
            if _group == 'seconds':
                ts_restraint = 'YYYY-MM-DD HH24:MI:SS'
            elif _group == 'minutes':
                ts_restraint = 'YYYY-MM-DD HH24:MI'
            elif _group == 'hours':
                ts_restraint = 'YYYY-MM-DD HH24'
        else:
            raise web.HTTPBadRequest(reason="{} is not a valid group".format(_group))
    _aggregate = PayloadBuilder().AGGREGATE(["min", ["reading", reading]], ["max", ["reading", reading]],
                                            ["avg", ["reading", reading]]) \
        .ALIAS('aggregate', ('reading', 'min', 'min'), ('reading', 'max', 'max'),
               ('reading', 'avg', 'average')).chain_payload()
    _where = PayloadBuilder(_aggregate).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)
    _group = PayloadBuilder(_and_where).GROUP_BY("user_ts").ALIAS("group", ("user_ts", "timestamp")) \
        .FORMAT("group", ("user_ts", ts_restraint)).chain_payload()
    payload = PayloadBuilder(_group).ORDER_BY(["user_ts", "desc"]).payload()
    results = {}
    try:
        _readings = connect.get_readings_async()
        results = await _readings.query(payload)
        response = results['rows']
    except KeyError:
        raise web.HTTPBadRequest(reason=results['message'])
    else:
        return web.json_response(response)
async def asset_averages ( request ) : asset_code = request . match_info . get ( 'asset_code' , '' ) reading = request . match_info . get ( 'reading' , '' ) ts_restraint = 'YYYY-MM-DD HH24:MI:SS' if 'group' in request . query and request . query [ 'group' ] != '' : _group = request . query [ 'group' ] if _group in ( 'seconds' , 'minutes' , 'hours' ) : if _group == 'seconds' : ts_restraint = 'YYYY-MM-DD HH24:MI:SS' elif _group == 'minutes' : ts_restraint = 'YYYY-MM-DD HH24:MI' elif _group == 'hours' : ts_restraint = 'YYYY-MM-DD HH24' else : raise web . HTTPBadRequest ( reason = "{} is not a valid group" . format ( _group ) ) _aggregate = PayloadBuilder ( ) . AGGREGATE ( [ "min" , [ "reading" , reading ] ] , [ "max" , [ "reading" , reading ] ] , [ "avg" , [ "reading" , reading ] ] ) . ALIAS ( 'aggregate' , ( 'reading' , 'min' , 'min' ) , ( 'reading' , 'max' , 'max' ) , ( 'reading' , 'avg' , 'average' ) ) . chain_payload ( ) _where = PayloadBuilder ( _aggregate ) . 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 ) _group = PayloadBuilder ( _and_where ) . GROUP_BY ( "user_ts" ) . ALIAS ( "group" , ( "user_ts" , "timestamp" ) ) . FORMAT ( "group" , ( "user_ts" , ts_restraint ) ) . chain_payload ( ) payload = PayloadBuilder ( _group ) . ORDER_BY ( [ "user_ts" , "desc" ] ) . payload ( ) results = { } try : _readings = connect . get_readings_async ( ) results = await _readings . query ( payload ) response = results [ 'rows' ] except KeyError : raise web . HTTPBadRequest ( reason = results [ 'message' ] ) else : return web . json_response ( response )
Browse all the assets for which we have recorded readings and
return a series of averages per second, minute or hour.
Browse all the assets for which we have recorded readings and return a series of averages per second minute or hour .
""" Browse all the assets for which we have recorded readings and
    return a series of averages per second, minute or hour.

    The readings averaged can also be time limited by use of the query
    parameter seconds=sss. This defines a number of seconds that the reading
    must have been processed in. Older readings than this will not be summarised.

    The readings averaged can also be time limited by use of the query
    parameter minutes=mmm. This defines a number of minutes that the reading
    must have been processed in. Older readings than this will not be summarised.

    The readings averaged can also be time limited by use of the query
    parameter hours=hh. This defines a number of hours that the reading
    must have been processed in. Older readings than this will not be summarised.

    Only one of hour, minutes or seconds should be supplied

    The amount of time covered by each returned value is set using the
    query parameter group. This may be set to seconds, minutes or hours

    Returns:
            on the basis of
            SELECT min((reading->>'reading')::float) AS "min",
                   max((reading->>'reading')::float) AS "max",
                   avg((reading->>'reading')::float) AS "average",
                   to_char(user_ts, 'YYYY-MM-DD HH24:MI:SS') AS "timestamp"
            FROM foglamp.readings
                   WHERE asset_code = 'asset_code' AND
                     reading ? 'reading'
            GROUP BY to_char(user_ts, 'YYYY-MM-DD HH24:MI:SS')
            ORDER BY timestamp DESC;

    :Example:
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series
            curl -sX GET "http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?limit=1&skip=1"
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?hours=1
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?minutes=60
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?seconds=3600
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=seconds
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=minutes
            curl -sX GET http://localhost:8081/foglamp/asset/fogbench_humidity/temperature/series?group=hours
    """ # Add LIMIT, OFFSET # Add the GROUP BY and ORDER BY timestamp DESC
request
Example
None