Package: nista-library
Welcome to nista_library’s documentation!TutorialCreate new Poetry ProjectNavigate to a folder where you want to create your project and typepoetrynewmy-nista-clientcdmy-nista-clientAdd reference to your ProjectNavigate to the newly created project and add the PyPI packagepoetryaddnista-libraryYour first DataPointIn 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 loginBrowse your DataLibrary and open a DataPointYou 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 LoginRun your file in poetry’s virtual environment$poetryinstall
$poetryrunpythondemo.py2021-09-0214:51.58[info]Authenticationhasbeenstarted.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.KeystoreOnce 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 atKeyringfor details.ExamplesShow received Data in a plotThe most easy way to receive data is to adresse the Datapoint directly and Plot it.
this is a snippet from the examples projectpoetrynewmy-nista-clientcdmy-nista-client
poetryaddnista-library
poetryaddstructlog
poetryaddmatplotlib
poetryaddtkfrom 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 NameYou 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 QuantityIn 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
            )LinksWebsitenista.ioSource CodeGitlabPyPiPyPi.io