コード例 #1
0
ファイル: api_pulse.py プロジェクト: Nesh108/python-sdk
def show_check():
    "Show some key numbers about the current state of the API."

    # For all this no credentials/token etc. are needed.
    api = Api()

    # Get server status.
    t0 = time.time()
    try:
        res = api.get_server_status()
        ok = res['database'] == 'ok'
    except:
        msg = 'Relayr API not reachable, sorry for that!'
        termcolor.cprint(msg, 'red')
        sys.exit(-1)
    t = time.time() - t0
    print('server status ok: %s (%.2f s)' % (ok, t))

    # Get number of all publishers.
    t0 = time.time()
    publishers = list(api.get_public_publishers())
    t = time.time() - t0
    print('%d publishers (%.2f s)' % (len(publishers), t))

    # Get number of all apps.
    t0 = time.time()
    apps = list(api.get_public_apps())
    t = time.time() - t0
    print('%d applications (%.2f s)' % (len(apps), t))

    # Get number of all public devices.
    t0 = time.time()
    devices = list(api.get_public_devices())
    t = time.time() - t0
    print('%d public devices (%.2f s)' % (len(devices), t))

    # Get number of all device models.
    t0 = time.time()
    models = list(api.get_public_device_models())
    t = time.time() - t0
    print('%d device models (%.2f s)' % (len(models), t))

    # Get number of all device model meanings.
    t0 = time.time()
    meanings = list(api.get_public_device_model_meanings())
    t = time.time() - t0
    print('%d device model meanings (%.2f s)' % (len(meanings), t))

    # Get a count of all public devices by meaning.
    counts = {}
    for device in devices:
        readings = device['model']['readings']
        for reading in readings:
            meaning = m = reading['meaning']
            counts[m] = counts[m] + 1 if counts.get(m, 0) else 1
    print('#public devices by meaning: %s' % json.dumps(counts, indent=4))
コード例 #2
0
def show_check():
    "Show some key numbers about the current state of the API."
    
    # For all this no credentials/token etc. are needed.
    api = Api()

    # Get server status.
    t0 = time.time()
    try:
        res = api.get_server_status()
        ok = res['database'] == 'ok'
    except:
        msg = 'Relayr API not reachable, sorry for that!'
        termcolor.cprint(msg, 'red')
        sys.exit(-1)
    t = time.time() - t0
    print('server status ok: %s (%.2f s)' % (ok, t))

    # Get number of all publishers.
    t0 = time.time()
    publishers = list(api.get_public_publishers())
    t = time.time() - t0
    print('%d publishers (%.2f s)' % (len(publishers), t))

    # Get number of all apps.
    t0 = time.time()
    apps = list(api.get_public_apps())
    t = time.time() - t0
    print('%d applications (%.2f s)' % (len(apps), t))
    
    # Get number of all public devices.
    t0 = time.time()
    devices = list(api.get_public_devices())
    t = time.time() - t0
    print('%d public devices (%.2f s)' % (len(devices), t))

    # Get number of all device models.
    t0 = time.time()
    models = list(api.get_public_device_models())
    t = time.time() - t0
    print('%d device models (%.2f s)' % (len(models), t))

    # Get number of all device model meanings.
    t0 = time.time()
    meanings = list(api.get_public_device_model_meanings())
    t = time.time() - t0
    print('%d device model meanings (%.2f s)' % (len(meanings), t))

    # Get a count of all public devices by meaning.
    counts = {}
    for device in devices:
        readings = device['model']['readings']
        for reading in readings:
            meaning = m = reading['meaning']
            counts[m] = counts[m] + 1 if counts.get(m, 0) else 1
    print('#public devices by meaning: %s' % json.dumps(counts, indent=4))