Skip to main content

A client library for accessing nista.io

Project description

Welcome to nista_library’s documentation!

Tutorial

Create new Poetry Project

Navigate to a folder where you want to create your project and type

poetry new my-nista-client
cd my-nista-client

Add reference to your Project

Navigate to the newly created project and add the PyPI package

poetry add nista-library

Your first DataPoint

In order to receive your datapoint you need a workspaceID and a dataPointId. This can be retrieved from your browser.

  • Navigate to app.nista.io and login

  • Browse your DataLibrary and open a DataPoint

  • You can extract the information from the URL of your browser: https://app.nista.io/workspace/{WORKSPACE_ID}/dashboard/datalibrary/datapoint/{DATA_POINT_ID}

from data_point_client.models.get_data_request import GetDataRequest

from nista_library import KeyringNistaConnection, NistaDataPoint

connection = KeyringNistaConnection(workspace_id="YOUR_WORKSPACE_ID")

data_point_id = "DATA_POINT_ID"
data_point = NistaDataPoint(connection=connection, data_point_id=data_point_id)

request = GetDataRequest(
    window_seconds=600,
    remove_time_zone=True,
)

data_point_data = data_point.get_data_point_data(request=request, timeout=90)

if isinstance(data_point_data, list):
    print(data_point_data[0])

Run and Login

Run your file in poetry’s virtual environment

$ poetry install
$ poetry run python demo.py
2021-09-02 14:51.58 [info     ] Authentication has been started.

In order to login your browser will be openend. If not please copy the URL from the log message your Browser and follow the Login process. If you don’t want to login for every request, please use a Keystore.

Keystore

Once you loggedin, the library will try to store your access token in your private keystore. Next time you run your programm, it might request a password to access your keystore again to gain access to nista.io Please take a look at Keyring for details.

Examples

Show received Data in a plot

The most easy way to receive data is to adresse the Datapoint directly and Plot it. this is a snippet from the examples project

poetry new my-nista-client
cd my-nista-client
poetry add nista-library
poetry add structlog
poetry add matplotlib
poetry add tk
from structlog import get_logger
from data_point_client.models.get_data_request import GetDataRequest

from nista_library import NistaConnection, NistaDataPoint

from plotter import Plotter

log = get_logger()


def direct_sample(connection: NistaConnection):
    data_point_id = "DATA_POINT_ID"
    data_point = NistaDataPoint(connection=connection, data_point_id=data_point_id)

    request = GetDataRequest(
        window_seconds=600,
        remove_time_zone=True,
    )

    data_point_data = data_point.get_data_point_data(request=request, timeout=90)

    log.info("Data has been received. Plotting")
    if isinstance(data_point_data, list):
        Plotter.plot(data_point_data)

List DataPoints and filter by Name

You can list all DataPoints from your Workspace by querying the API. Use Filter lambda expressions in order to reduce the list to the entries you want.

In this example we use the Name in order to find DataPoints that start with “Chiller Cooling Power Production”

import matplotlib.pyplot as plt
from structlog import get_logger
from data_point_client.models.get_data_request import GetDataRequest

from nista_library import NistaConnection, NistaDataPoints

from plotter import Plotter

log = get_logger()


def filter_by_name(connection: NistaConnection):
    dataPoints = NistaDataPoints(connection=connection)
    data_point_list = list(dataPoints.get_data_point_list())

    for data_point in data_point_list:
        log.info(data_point)

    # Find Specific Data Points
    filtered_data_points = filter(
        lambda data_point: data_point.name.startswith(
            "Chiller Cooling Power Production"
        ),
        data_point_list,
    )
    for data_point in filtered_data_points:
        request = GetDataRequest(
            window_seconds=600,
            remove_time_zone=True,
        )

        data_point_data = data_point.get_data_point_data(request=request, timeout=90)

        if isinstance(data_point_data, list):
            Plotter.plot(data_point_data)

Filter by Physical Quantity

In order to find DataPoints by it’s Unit or Physical Quantity the filter query can be extended to load more data for every datapoint.

from typing import List
from structlog import get_logger
from data_point_client.models.get_data_request import GetDataRequest

from nista_library import NistaConnection, NistaDataPoints, NistaDataPoint

from plotter import Plotter

log = get_logger()


def filter_by_unit(connection: NistaConnection):
    dataPoints = NistaDataPoints(connection=connection)
    data_point_list: List[NistaDataPoint] = list(dataPoints.get_data_point_list())

    for data_point in data_point_list:
        log.info(data_point)

    # Find Specific Data Points
    filtered_data_points = filter(
        lambda data_point: data_point.data_point_response.store.gnista_unit.physical_quantity.startswith(
            "Energy"
        ),
        data_point_list,
    )
    for data_point in filtered_data_points:
        log.info(data_point)
        request = GetDataRequest(
            window_seconds=600,
            remove_time_zone=True,
        )

        data_point_data = data_point.get_data_point_data(request=request, timeout=90)

        if isinstance(data_point_data, list):
            Plotter.plot(
                data_point_data, data_point.data_point_response.store.gnista_unit.name
            )

Links

Website

image

nista.io

Source Code

image

Gitlab

PyPi

image

PyPi.io

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nista_library-6.6.0.tar.gz (53.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nista_library-6.6.0-py3-none-any.whl (156.5 kB view details)

Uploaded Python 3

File details

Details for the file nista_library-6.6.0.tar.gz.

File metadata

  • Download URL: nista_library-6.6.0.tar.gz
  • Upload date:
  • Size: 53.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.5 Linux/6.15.6-100.fc41.x86_64

File hashes

Hashes for nista_library-6.6.0.tar.gz
Algorithm Hash digest
SHA256 56d12ec0eba1b25524d4d5fc19d59bf5cd91bc96af3943d29eb470e8834a30a8
MD5 20a5dae74681fd1af5a414494b7b132e
BLAKE2b-256 fcdd188879ecacf7da19eb2a2a29cd021cc427ec40cdb93fded6c5d6aafcdde3

See more details on using hashes here.

File details

Details for the file nista_library-6.6.0-py3-none-any.whl.

File metadata

  • Download URL: nista_library-6.6.0-py3-none-any.whl
  • Upload date:
  • Size: 156.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.5 Linux/6.15.6-100.fc41.x86_64

File hashes

Hashes for nista_library-6.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d661d9013923f678acd225fd61d3bed6b53986338d57a68a08bbe6c38c128b3
MD5 426ef11b4fd72562c72bd94b0a883d60
BLAKE2b-256 e41e22d1f45bd75bea2a9d2535afe5fb7016e1bc09b242f9c3864c557496d4f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page