pytebis


Namepytebis JSON
Version 0.5.12 PyPI version JSON
download
home_pagehttps://github.com/MrLight/pytebis
SummaryPython Connector for TeBIS from Steinhaus
upload_time2023-06-14 09:42:33
maintainer
docs_urlNone
authorMrLight
requires_python
licensemit
keywords python connector tebis steinhaus
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytebis Python Connector for TeBIS from Steinhaus

pytebis is a connector for interacting with a TeBIS Server.

The connector can return structured data in a defined timespan with defined measuring points.
There are function to get the data as structured NumPy Array, Pandas or as json.
For further interaction it is possible to load the measuring points, the groups and the tree.
Alarms are currently not supported.

## Install the package

```python
pip install pytebis
```

## Usage

### Import the package

```python
from pytebis import tebis
```

### Basic configuration

With the basic configuration it is possible to read data and to load the measuring point names and ids.
The advanced Configuration is needed to additional load the groups and tree config.

```python
configuration = {
    'host': '192.168.1.10', # The tebis host IP Adr
    'configfile': 'd:/tebis/Anlage/Config.txt' # Tebis config file loaction on the server -> ask your admin
}
teb = tebis.Tebis(configuration=configuration)
```

### Advanced configuration

```python
configuration = {
            'host': None, #Your Server IP-Adress
            'port': 4712, #Communication port [4712]
            'configfile': 'd:/tebis/Anlage/Config.txt', #Your tebis Instance to connect to.
            'useOracle': None,  # use Oracle true / false, Opt. if not defined a defined OracleDbConn.Host will set it to true. Use false to deactive Oracle usage
            'OracleDbConn': {
                'host': None,  # Host IP-Adr
                'port': 1521,  # host port [1521]
                'schema': None,  # schema name opt. if not set user is used as schema name
                'user': None,  # db user
                'psw': None,  # db pwd
                'service': 'XE'  # Oracle service name
            },
            'liveValues': {
                'enable': False,    # Use LiveValue Feature - This is used to compensate possible timedrifts between the Tebis Server and the Client.
                'recalcTimeOffsetEvery': 600,  # When using LiveValues recalc TimeOffset every x Seconds
                'offsetMstId': 100025,  # This is the Mst which is used to calculate the last available Timestamp. Use a always available mst.
            }
        }
teb = tebis.Tebis(configuration=configuration)
```

### read Data from TeBIS

There are different functions to read data from the TeBIS Server. All functions have the some parameters. Only the return is specific to the function.
Parameters:

`result = teb.getDataAsJson(names, start, end, rate=1)`

- names = Array of all mst-names to read. You can pass a array of IDs, names, TebisMst-Objects or Group-Objects (even mixed).
- start = Unix-Timestamp where to start the read
          - or -
          Unix-Timestamp in microsecond precision
          - or - 
          float value where the fraction is the microseconds part
          - or -
          DateTimeObject
          - or -
          String in Format '%Y-%m-%d %H:%M:%S.%f'
          (always the same timezone as the server is)
- end = Unix-Timestamp where to end the read
          - or -
          Unix-Timestamp in microsecond precision
          - or - 
          float value where the fraction is the microseconds part
          - or -
          DateTimeObject
          - or -
          String in Format '%Y-%m-%d %H:%M:%S.%f'
          (always the same timezone as the server is)
- rate = What reduction should be used for the read. If your System supports Values smaller than 1second use Fractions of Seconds. eg: 0.1 for 100ms

The Data which is returned by the TeBIS-Server is vectorized into a structured numpy array. Which is working super fast and is totally comparable with the performance of the TeBIS A Client. You can use different functions to get the data in std. Python formats for further analysis.

#### as Numpy structured array

```python
resNP = teb.getDataAsNP(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)
```

A structured Numpy Array is returned. There is a Column per mst-name, additional a column with the timestamp is added with index 0.
You can directly access the elements e.g. by indexing them by name `resNP["timestamp"]`

#### as Pandas

```python
df = teb.getDataAsPD(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)
```
will return a pandas dataframe


```python
df = teb.getDataAsPD([13, 14, 15, 16],  [[1626779900,1626779930],[1626779950,1626779960]],1)
```

The Pandas Function can even handel multiple slices of timeframes by adding start and endpoint into an array.



#### as Json

```python
resJSON = teb.getDataAsJson(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)
```

#### as RawValues

```python
resJSON = teb.getDataRAW(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)
```
Returns the raw tebis socket data. This could be used if the value calculation should happen on the clientside. e.g. if you want to save bandwidth and gain speed in a client server setup.

#### Example

This will show a plot containing the last hour of data of the point-ids 1 and 2. The reduction is 10 seconds.

```python
import time
import matplotlib.pyplot as plt
from pytebis import tebis

def example():
    configuration = {
        'host': '192.168.1.10',  # The tebis host IP Adr
        'configfile': 'd:/tebis/Anlage/Config.txt' # Tebis config file loaction on the server -> ask your admin
    }
    teb = tebis.Tebis(configuration=configuration)
    df = teb.getDataAsPD([1,2], time.time() - 3600, time.time(), 10)  # adjust which points you want to load pass id, name, mst- or group-Object
    df.plot()
    plt.show()

if __name__ == "__main__":
    example()
    pass
```

### Working with measuring points, groups and the tree

The measuring points and the virtual measuring points are loaded once at startup. This is always possible so you don't need to specify a db Connection.

If you want to load the Groups, Group Members and the Tree as it is configured in the TeBIS A client you must have a working db Connection.

If you have a long running service it is a good idea to reload the information in a regular interval. (e.g. all 10min)

Just call ```teb.refreshMsts()``` to reload the data.


### Logging

The package is implementing a logger using the std. logging framework of Python. The loggername is: ```pytebis```. There is no handler configured. To setup a specific log-level for the package use a config like this after ```logging.basicConfig()``` e.g. ```logging.getLogger('pytebis').setLevel(logging.INFO)``` 

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/MrLight/pytebis",
    "name": "pytebis",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Python,Connector,TeBIS,Steinhaus",
    "author": "MrLight",
    "author_email": "mrlight1@gmx.de",
    "download_url": "https://files.pythonhosted.org/packages/4a/c6/5644334a656ec0896a66be4c20aca6f4ebde6e2de9d2511ade23e59079d1/pytebis-0.5.12.tar.gz",
    "platform": null,
    "description": "# pytebis Python Connector for TeBIS from Steinhaus\r\n\r\npytebis is a connector for interacting with a TeBIS Server.\r\n\r\nThe connector can return structured data in a defined timespan with defined measuring points.\r\nThere are function to get the data as structured NumPy Array, Pandas or as json.\r\nFor further interaction it is possible to load the measuring points, the groups and the tree.\r\nAlarms are currently not supported.\r\n\r\n## Install the package\r\n\r\n```python\r\npip install pytebis\r\n```\r\n\r\n## Usage\r\n\r\n### Import the package\r\n\r\n```python\r\nfrom pytebis import tebis\r\n```\r\n\r\n### Basic configuration\r\n\r\nWith the basic configuration it is possible to read data and to load the measuring point names and ids.\r\nThe advanced Configuration is needed to additional load the groups and tree config.\r\n\r\n```python\r\nconfiguration = {\r\n    'host': '192.168.1.10', # The tebis host IP Adr\r\n    'configfile': 'd:/tebis/Anlage/Config.txt' # Tebis config file loaction on the server -> ask your admin\r\n}\r\nteb = tebis.Tebis(configuration=configuration)\r\n```\r\n\r\n### Advanced configuration\r\n\r\n```python\r\nconfiguration = {\r\n            'host': None, #Your Server IP-Adress\r\n            'port': 4712, #Communication port [4712]\r\n            'configfile': 'd:/tebis/Anlage/Config.txt', #Your tebis Instance to connect to.\r\n            'useOracle': None,  # use Oracle true / false, Opt. if not defined a defined OracleDbConn.Host will set it to true. Use false to deactive Oracle usage\r\n            'OracleDbConn': {\r\n                'host': None,  # Host IP-Adr\r\n                'port': 1521,  # host port [1521]\r\n                'schema': None,  # schema name opt. if not set user is used as schema name\r\n                'user': None,  # db user\r\n                'psw': None,  # db pwd\r\n                'service': 'XE'  # Oracle service name\r\n            },\r\n            'liveValues': {\r\n                'enable': False,    # Use LiveValue Feature - This is used to compensate possible timedrifts between the Tebis Server and the Client.\r\n                'recalcTimeOffsetEvery': 600,  # When using LiveValues recalc TimeOffset every x Seconds\r\n                'offsetMstId': 100025,  # This is the Mst which is used to calculate the last available Timestamp. Use a always available mst.\r\n            }\r\n        }\r\nteb = tebis.Tebis(configuration=configuration)\r\n```\r\n\r\n### read Data from TeBIS\r\n\r\nThere are different functions to read data from the TeBIS Server. All functions have the some parameters. Only the return is specific to the function.\r\nParameters:\r\n\r\n`result = teb.getDataAsJson(names, start, end, rate=1)`\r\n\r\n- names = Array of all mst-names to read. You can pass a array of IDs, names, TebisMst-Objects or Group-Objects (even mixed).\r\n- start = Unix-Timestamp where to start the read\r\n          - or -\r\n          Unix-Timestamp in microsecond precision\r\n          - or - \r\n          float value where the fraction is the microseconds part\r\n          - or -\r\n          DateTimeObject\r\n          - or -\r\n          String in Format '%Y-%m-%d %H:%M:%S.%f'\r\n          (always the same timezone as the server is)\r\n- end = Unix-Timestamp where to end the read\r\n          - or -\r\n          Unix-Timestamp in microsecond precision\r\n          - or - \r\n          float value where the fraction is the microseconds part\r\n          - or -\r\n          DateTimeObject\r\n          - or -\r\n          String in Format '%Y-%m-%d %H:%M:%S.%f'\r\n          (always the same timezone as the server is)\r\n- rate = What reduction should be used for the read. If your System supports Values smaller than 1second use Fractions of Seconds. eg: 0.1 for 100ms\r\n\r\nThe Data which is returned by the TeBIS-Server is vectorized into a structured numpy array. Which is working super fast and is totally comparable with the performance of the TeBIS A Client. You can use different functions to get the data in std. Python formats for further analysis.\r\n\r\n#### as Numpy structured array\r\n\r\n```python\r\nresNP = teb.getDataAsNP(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)\r\n```\r\n\r\nA structured Numpy Array is returned. There is a Column per mst-name, additional a column with the timestamp is added with index 0.\r\nYou can directly access the elements e.g. by indexing them by name `resNP[\"timestamp\"]`\r\n\r\n#### as Pandas\r\n\r\n```python\r\ndf = teb.getDataAsPD(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)\r\n```\r\nwill return a pandas dataframe\r\n\r\n\r\n```python\r\ndf = teb.getDataAsPD([13, 14, 15, 16],  [[1626779900,1626779930],[1626779950,1626779960]],1)\r\n```\r\n\r\nThe Pandas Function can even handel multiple slices of timeframes by adding start and endpoint into an array.\r\n\r\n\r\n\r\n#### as Json\r\n\r\n```python\r\nresJSON = teb.getDataAsJson(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)\r\n```\r\n\r\n#### as RawValues\r\n\r\n```python\r\nresJSON = teb.getDataRAW(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)\r\n```\r\nReturns the raw tebis socket data. This could be used if the value calculation should happen on the clientside. e.g. if you want to save bandwidth and gain speed in a client server setup.\r\n\r\n#### Example\r\n\r\nThis will show a plot containing the last hour of data of the point-ids 1 and 2. The reduction is 10 seconds.\r\n\r\n```python\r\nimport time\r\nimport matplotlib.pyplot as plt\r\nfrom pytebis import tebis\r\n\r\ndef example():\r\n    configuration = {\r\n        'host': '192.168.1.10',  # The tebis host IP Adr\r\n        'configfile': 'd:/tebis/Anlage/Config.txt' # Tebis config file loaction on the server -> ask your admin\r\n    }\r\n    teb = tebis.Tebis(configuration=configuration)\r\n    df = teb.getDataAsPD([1,2], time.time() - 3600, time.time(), 10)  # adjust which points you want to load pass id, name, mst- or group-Object\r\n    df.plot()\r\n    plt.show()\r\n\r\nif __name__ == \"__main__\":\r\n    example()\r\n    pass\r\n```\r\n\r\n### Working with measuring points, groups and the tree\r\n\r\nThe measuring points and the virtual measuring points are loaded once at startup. This is always possible so you don't need to specify a db Connection.\r\n\r\nIf you want to load the Groups, Group Members and the Tree as it is configured in the TeBIS A client you must have a working db Connection.\r\n\r\nIf you have a long running service it is a good idea to reload the information in a regular interval. (e.g. all 10min)\r\n\r\nJust call ```teb.refreshMsts()``` to reload the data.\r\n\r\n\r\n### Logging\r\n\r\nThe package is implementing a logger using the std. logging framework of Python. The loggername is: ```pytebis```. There is no handler configured. To setup a specific log-level for the package use a config like this after ```logging.basicConfig()``` e.g. ```logging.getLogger('pytebis').setLevel(logging.INFO)``` \r\n",
    "bugtrack_url": null,
    "license": "mit",
    "summary": "Python Connector for TeBIS from Steinhaus",
    "version": "0.5.12",
    "project_urls": {
        "Homepage": "https://github.com/MrLight/pytebis"
    },
    "split_keywords": [
        "python",
        "connector",
        "tebis",
        "steinhaus"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7bbfb6babd439e5a29f750ee491ca171c8187ff59ee7e406c8dbd3664f3215d",
                "md5": "cefcbc0c75ad02db645ead9fc0a1521e",
                "sha256": "584a165b5a14ad336d151880153c83e4d565b37c5f0d985a0983e1ec62d56b31"
            },
            "downloads": -1,
            "filename": "pytebis-0.5.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cefcbc0c75ad02db645ead9fc0a1521e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15342,
            "upload_time": "2023-06-14T09:42:32",
            "upload_time_iso_8601": "2023-06-14T09:42:32.761911Z",
            "url": "https://files.pythonhosted.org/packages/f7/bb/fb6babd439e5a29f750ee491ca171c8187ff59ee7e406c8dbd3664f3215d/pytebis-0.5.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4ac65644334a656ec0896a66be4c20aca6f4ebde6e2de9d2511ade23e59079d1",
                "md5": "edc227931260affa963c0cbdb5755259",
                "sha256": "f2c17f295bdf8f46f7eea76468360d2f7649bcd3aeee231b6410922bf10d2c1c"
            },
            "downloads": -1,
            "filename": "pytebis-0.5.12.tar.gz",
            "has_sig": false,
            "md5_digest": "edc227931260affa963c0cbdb5755259",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 17410,
            "upload_time": "2023-06-14T09:42:33",
            "upload_time_iso_8601": "2023-06-14T09:42:33.995791Z",
            "url": "https://files.pythonhosted.org/packages/4a/c6/5644334a656ec0896a66be4c20aca6f4ebde6e2de9d2511ade23e59079d1/pytebis-0.5.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-14 09:42:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MrLight",
    "github_project": "pytebis",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pytebis"
}
        
Elapsed time: 0.08597s