Пример #1
0
def main():
    # Change URL to point to a valid portal node.
    # If you are not interested in any subarray specific information
    # (e.g. schedule blocks), then the number can be omitted, as below.
    # Note: if on_update_callback is set to None, then we cannot use the
    #       KATPortalClient.connect() method (i.e. no websocket access).
    portal_client = KATPortalClient('http://{}/api/client'.format(args.host),
                                    on_update_callback=None,
                                    logger=logger)

    # Get the names of sensors matching the patterns
    sensor_names = yield portal_client.sensor_names(args.sensors)
    print "\nMatching sensor names for pattern {}: {}".format(
        args.sensors, sensor_names)

    # Get the names of sensors matching a pattern
    # pattern = 'anc_w.*_device_status'
    # sensor_names = yield portal_client.sensor_names(pattern)
    # print "\nMatching sensor names for pattern {} : {}".format(pattern, sensor_names)
    # Example output:
    # Matching sensor names for pattern ['anc_w.*_device_status']:
    # [u'anc_wind_device_status', u'anc_weather_device_status']

    # Get the names of sensors matching a pattern
    # pattern = 'anc_(mean|gust)_wind_speed'
    # sensor_names = yield portal_client.sensor_names(pattern)
    # print "\nMatching sensor names for pattern {} : {}".format(pattern, sensor_names)
    # Example output:
    # Matching sensor names for pattern ['anc_(mean|gust)_wind_speed']:
    # [u'anc_mean_wind_speed', u'anc_gust_wind_speed']

    # Get the names of sensors matching a list of patterns
    # pattern = 'm01[12]_pos_request_base_azim'
    # sensor_names = yield portal_client.sensor_names(pattern)
    # print "\nMatching sensor names for pattern {} : {}".format(pattern, sensor_names)
    # Example output (if sensors is 'm01[12]_pos_request_base_azim'):
    # Matching sensor names for pattern ['m01[12]_pos_request_base_azim']:
    # [u'm011_pos_request_base_azim', u'm011_pos_request_base_azim']

    # Fetch the details for the sensors found.
    if len(sensor_names) == 0:
        print "No matching sensors found!"
    else:
        for sensor_name in sensor_names:
            sensor_detail = yield portal_client.sensor_detail(sensor_name)
            print "\nDetail for sensor {}:".format(sensor_name)
            for key in sensor_detail:
                print "    {}: {}".format(key, sensor_detail[key])
Пример #2
0
def main():
    # Change URL to point to a valid portal node.
    # If you are not interested in any subarray specific information
    # (e.g. schedule blocks), then the number can be omitted, as below.
    # Note: if on_update_callback is set to None, then we cannot use the
    #       KATPortalClient.connect() and subscribe() methods here.
    portal_client = KATPortalClient(
        'http://{host}/api/client'.format(**vars(args)),
        on_update_callback=None,
        logger=logger)

    # Get the names of sensors matching the patterns
    sensor_names = yield portal_client.sensor_names(args.sensors)
    print "\nMatching sensor names: {}".format(sensor_names)
    # Example output (if sensors is 'm01[12]_pos_request_base'):
    #   Matching sensor names: [u'm011_pos_request_base_azim',
    #   u'm012_pos_request_base_ra', u'm012_pos_request_base_dec',
    #   u'm011_pos_request_base_ra', u'm012_pos_request_base_elev',
    #   u'm011_pos_request_base_dec', u'm012_pos_request_base_azim',
    #   u'm011_pos_request_base_elev']

    # Fetch the details for the sensors found.
    for sensor_name in sensor_names:
        sensor_detail = yield portal_client.sensor_detail(sensor_name)
        print "\nDetail for sensor {}:".format(sensor_name)
        for key in sensor_detail:
            print "    {}: {}".format(key, sensor_detail[key])
        # Example output:
        #   Detail for sensor m011_pos_request_base_azim:
        #       name: m011_pos_request_base_azim
        #       systype: mkat
        #       component: m011
        #       site: deva
        #       katcp_name: m011.pos.request-base-azim
        #       params: [-195.0, 370.0]
        #       units: deg
        #       type: float
        #       description: Requested target azimuth

    num_sensors = len(sensor_names)
    if num_sensors == 0:
        print "\nNo matching sensors found - no history to request!"
    else:
        print("\nRequesting history for {} sensors, from {} to {}".format(
            num_sensors,
            datetime.utcfromtimestamp(
                args.start).strftime('%Y-%m-%dT%H:%M:%SZ'),
            datetime.utcfromtimestamp(
                args.end).strftime('%Y-%m-%dT%H:%M:%SZ')))
        if len(sensor_names) == 1:
            # Request history for just a single sensor - result is timestamp, value, status
            #    If value timestamp is also required, then add the additional argument: include_value_ts=True
            #    result is then timestmap, value_timestmap, value, status
            history = yield portal_client.sensor_history(
                sensor_names[0],
                args.start,
                args.end,
                timeout_sec=args.timeout)
            histories = {sensor_names[0]: history}
        else:
            # Request history for all the sensors - result is timestamp, value, status
            #    If value timestamp is also required, then add the additional argument: include_value_ts=True
            #    result is then timestmap, value_timestmap, value, status
            histories = yield portal_client.sensors_histories(
                sensor_names, args.start, args.end, timeout_sec=args.timeout)

        print "Found {} sensors.".format(len(histories))
        for sensor_name, history in histories.items():
            num_samples = len(history)
            print "History for: {} ({} samples)".format(
                sensor_name, num_samples)
            if num_samples > 0:
                print "\tindex,timestamp,value,status"
                for count in range(0, num_samples, args.decimate):
                    print "\t{},{}".format(count, history[count].csv())