Skip to main content

Python Connector for TeBIS from Steinhaus

Project description

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

pip install pytebis

Usage

Import the package

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.

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

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

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

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.

df = teb.getDataAsPD(['My_mst_1','My_mst_2'], 1581324153, 1581325153, 10)

as Json

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

as Rawvalues

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.

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)

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

pytebis-0.5.13.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

pytebis-0.5.13-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file pytebis-0.5.13.tar.gz.

File metadata

  • Download URL: pytebis-0.5.13.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for pytebis-0.5.13.tar.gz
Algorithm Hash digest
SHA256 6eb5fed3894e54b7a8edf6911463849c6766672a4d941fc22d6bae5ee979a310
MD5 c86a4eb15cd0a301a46ddf0fe35dc3dc
BLAKE2b-256 25c41b9a4bde45637845aefbc3e364dcaa2fd60f5d1573052218617443918dae

See more details on using hashes here.

File details

Details for the file pytebis-0.5.13-py3-none-any.whl.

File metadata

  • Download URL: pytebis-0.5.13-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for pytebis-0.5.13-py3-none-any.whl
Algorithm Hash digest
SHA256 487cc3dca37b9ab45cb6a9eb6a89187b946b7139ddbc9be318a191807876a89e
MD5 a72f27f495434059b92fe600089571fb
BLAKE2b-256 a52b35101ca171927465f6f184a87f59a887087873338db5d33733609d478cee

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