nista-library


Namenista-library JSON
Version 6.0.1 PyPI version JSON
download
home_pagehttps://nista.io
SummaryA client library for accessing nista.io
upload_time2024-10-25 10:03:10
maintainerNone
docs_urlNone
authorMarkus Pichler
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- nista_library documentation master file, created by
sphinx-quickstart on Thu May 18 13:55:53 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive. -->
# Welcome to nista_library’s documentation!

## Tutorial

### Create new Poetry Project

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

```shell
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

```shell
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](https://app.nista.io/workspace)/{WORKSPACE_ID}/dashboard/datalibrary/datapoint/{DATA_POINT_ID}

```default
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

```shell
$ 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](https://pypi.org/project/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

```shell
poetry new my-nista-client
cd my-nista-client
poetry add nista-library
poetry add structlog
poetry add matplotlib
poetry add tk
```

```default
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”

```default
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.

```default
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](https://app.nista.io/assets/wordmark.svg)

[nista.io](https://nista.io)

### Source Code



![image](https://about.gitlab.com/images/icons/logos/slp-logo.svg)

[Gitlab](https://gitlab.com/campfiresolutions/public/nista.io-python-library)

### PyPi



![image](https://pypi.org/static/images/logo-small.2a411bc6.svg)

[PyPi.io](https://pypi.org/project/nista-library/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://nista.io",
    "name": "nista-library",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Markus Pichler",
    "author_email": "markus.pichler@nista.io",
    "download_url": "https://files.pythonhosted.org/packages/53/d8/999d7648d6b4428b6a70ffbe1c841c38b02dfdfc24a98c2d52b6aff6412a/nista_library-6.0.1.tar.gz",
    "platform": null,
    "description": "<!-- nista_library documentation master file, created by\nsphinx-quickstart on Thu May 18 13:55:53 2023.\nYou can adapt this file completely to your liking, but it should at least\ncontain the root `toctree` directive. -->\n# Welcome to nista_library\u2019s documentation!\n\n## Tutorial\n\n### Create new Poetry Project\n\nNavigate to a folder where you want to create your project and type\n\n```shell\npoetry new my-nista-client\ncd my-nista-client\n```\n\n### Add reference to your Project\n\nNavigate to the newly created project and add the PyPI package\n\n```shell\npoetry add nista-library\n```\n\n### Your first DataPoint\n\nIn order to receive your datapoint you need a workspaceID and a dataPointId. This can be retrieved from your browser.\n\n\n* Navigate to app.nista.io and login\n\n\n* Browse your DataLibrary and open a DataPoint\n\n\n* You can extract the information from the URL of your browser: [https://app.nista.io/workspace](https://app.nista.io/workspace)/{WORKSPACE_ID}/dashboard/datalibrary/datapoint/{DATA_POINT_ID}\n\n```default\nfrom data_point_client.models.get_data_request import GetDataRequest\n\nfrom nista_library import KeyringNistaConnection, NistaDataPoint\n\nconnection = KeyringNistaConnection(workspace_id=\"YOUR_WORKSPACE_ID\")\n\ndata_point_id = \"DATA_POINT_ID\"\ndata_point = NistaDataPoint(connection=connection, data_point_id=data_point_id)\n\nrequest = GetDataRequest(\n    window_seconds=600,\n    remove_time_zone=True,\n)\n\ndata_point_data = data_point.get_data_point_data(request=request, timeout=90)\n\nif isinstance(data_point_data, list):\n    print(data_point_data[0])\n```\n\n### Run and Login\n\nRun your file in poetry\u2019s virtual environment\n\n```shell\n$ poetry install\n$ poetry run python demo.py\n2021-09-02 14:51.58 [info     ] Authentication has been started.\n```\n\nIn 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\u2019t want to login for every request, please use a Keystore.\n\n### Keystore\n\nOnce 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\nPlease take a look at [Keyring](https://pypi.org/project/keyring/) for details.\n\n## Examples\n\n### Show received Data in a plot\n\nThe most easy way to receive data is to adresse the Datapoint directly and Plot it.\nthis is a snippet from the examples project\n\n```shell\npoetry new my-nista-client\ncd my-nista-client\npoetry add nista-library\npoetry add structlog\npoetry add matplotlib\npoetry add tk\n```\n\n```default\nfrom structlog import get_logger\nfrom data_point_client.models.get_data_request import GetDataRequest\n\nfrom nista_library import NistaConnection, NistaDataPoint\n\nfrom plotter import Plotter\n\nlog = get_logger()\n\n\ndef direct_sample(connection: NistaConnection):\n    data_point_id = \"DATA_POINT_ID\"\n    data_point = NistaDataPoint(connection=connection, data_point_id=data_point_id)\n\n    request = GetDataRequest(\n        window_seconds=600,\n        remove_time_zone=True,\n    )\n\n    data_point_data = data_point.get_data_point_data(request=request, timeout=90)\n\n    log.info(\"Data has been received. Plotting\")\n    if isinstance(data_point_data, list):\n        Plotter.plot(data_point_data)\n```\n\n### List DataPoints and filter by Name\n\nYou 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.\n\nIn this example we use the Name in order to find DataPoints that start with \u201cChiller Cooling Power Production\u201d\n\n```default\nimport matplotlib.pyplot as plt\nfrom structlog import get_logger\nfrom data_point_client.models.get_data_request import GetDataRequest\n\nfrom nista_library import NistaConnection, NistaDataPoints\n\nfrom plotter import Plotter\n\nlog = get_logger()\n\n\ndef filter_by_name(connection: NistaConnection):\n    dataPoints = NistaDataPoints(connection=connection)\n    data_point_list = list(dataPoints.get_data_point_list())\n\n    for data_point in data_point_list:\n        log.info(data_point)\n\n    # Find Specific Data Points\n    filtered_data_points = filter(\n        lambda data_point: data_point.name.startswith(\n            \"Chiller Cooling Power Production\"\n        ),\n        data_point_list,\n    )\n    for data_point in filtered_data_points:\n        request = GetDataRequest(\n            window_seconds=600,\n            remove_time_zone=True,\n        )\n\n        data_point_data = data_point.get_data_point_data(request=request, timeout=90)\n\n        if isinstance(data_point_data, list):\n            Plotter.plot(data_point_data)\n```\n\n### Filter by Physical Quantity\n\nIn order to find DataPoints by it\u2019s Unit or Physical Quantity the filter query can be extended to load more data for every datapoint.\n\n```default\nfrom typing import List\nfrom structlog import get_logger\nfrom data_point_client.models.get_data_request import GetDataRequest\n\nfrom nista_library import NistaConnection, NistaDataPoints, NistaDataPoint\n\nfrom plotter import Plotter\n\nlog = get_logger()\n\n\ndef filter_by_unit(connection: NistaConnection):\n    dataPoints = NistaDataPoints(connection=connection)\n    data_point_list: List[NistaDataPoint] = list(dataPoints.get_data_point_list())\n\n    for data_point in data_point_list:\n        log.info(data_point)\n\n    # Find Specific Data Points\n    filtered_data_points = filter(\n        lambda data_point: data_point.data_point_response.store.gnista_unit.physical_quantity.startswith(\n            \"Energy\"\n        ),\n        data_point_list,\n    )\n    for data_point in filtered_data_points:\n        log.info(data_point)\n        request = GetDataRequest(\n            window_seconds=600,\n            remove_time_zone=True,\n        )\n\n        data_point_data = data_point.get_data_point_data(request=request, timeout=90)\n\n        if isinstance(data_point_data, list):\n            Plotter.plot(\n                data_point_data, data_point.data_point_response.store.gnista_unit.name\n            )\n```\n\n## Links\n\n### Website\n\n\n\n![image](https://app.nista.io/assets/wordmark.svg)\n\n[nista.io](https://nista.io)\n\n### Source Code\n\n\n\n![image](https://about.gitlab.com/images/icons/logos/slp-logo.svg)\n\n[Gitlab](https://gitlab.com/campfiresolutions/public/nista.io-python-library)\n\n### PyPi\n\n\n\n![image](https://pypi.org/static/images/logo-small.2a411bc6.svg)\n\n[PyPi.io](https://pypi.org/project/nista-library/)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A client library for accessing nista.io",
    "version": "6.0.1",
    "project_urls": {
        "Homepage": "https://nista.io",
        "Repository": "https://gitlab.com/campfiresolutions/public/nista.io-python-library.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "409f6164cb1eb23c941e6cee2224f89f1f81697f95edfaf3b60b0e2d980d6110",
                "md5": "f4773354010fec0500a74e2a394ff2ec",
                "sha256": "7a79ba0c6516c519ceb5313d6431132498cf0986b05db87813037258a4e998fe"
            },
            "downloads": -1,
            "filename": "nista_library-6.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f4773354010fec0500a74e2a394ff2ec",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 136870,
            "upload_time": "2024-10-25T10:03:08",
            "upload_time_iso_8601": "2024-10-25T10:03:08.885102Z",
            "url": "https://files.pythonhosted.org/packages/40/9f/6164cb1eb23c941e6cee2224f89f1f81697f95edfaf3b60b0e2d980d6110/nista_library-6.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "53d8999d7648d6b4428b6a70ffbe1c841c38b02dfdfc24a98c2d52b6aff6412a",
                "md5": "46eb2a20fd23672e3eec485445987899",
                "sha256": "b735e557857986b378c7acd68506520eadcf7981cb492e0a339a2328629a09c7"
            },
            "downloads": -1,
            "filename": "nista_library-6.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "46eb2a20fd23672e3eec485445987899",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 47448,
            "upload_time": "2024-10-25T10:03:10",
            "upload_time_iso_8601": "2024-10-25T10:03:10.419938Z",
            "url": "https://files.pythonhosted.org/packages/53/d8/999d7648d6b4428b6a70ffbe1c841c38b02dfdfc24a98c2d52b6aff6412a/nista_library-6.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-25 10:03:10",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "campfiresolutions",
    "gitlab_project": "public",
    "lcname": "nista-library"
}
        
Elapsed time: 0.41543s