Utilize the data of PISystem for AI development

We utilize the timeseries database which is the master data storage for AI development.

PI System is a suite of software products such as database that are used for data collection as electric power collected by various resources.

It can be used for analytics, visualization and shareing.

In this tutorial, I will explain how to get the data from PISystem database to use python program and how to insert the data predicted by ReNom into PISystem database.

Environment construction

Construct an environment for PISystem following below url.

https://pisquare.osisoft.com/community/all-things-pi/japanese/japanpidevelopersclubkaihatsu

In addition, set the below configuration.

  1. About PI System

    • For inserting prediction value, insert the PI POINT which can be inserted future data.

    https://www.youtube.com/watch?v=yb-78aKiNm4

    • Configure the PI Web API Server not to deny foir access from development environment due to CSRF.
    • Configure PI Web API Server to allow POST request.
    • Configure the attribute whch insert prediction data to set the update authentication
  2. About Windows Server

    • Open the port to allow access from outside.
    • For basic authentication, widows accounts are needed.

Example

Connection settings

Import necessary libraries.

In [ ]:
import numpy as np
import pandas as pd
import renom as rm
from pi_interface.interface import PIInterface

Specify the IP address of the PI Web API server and the information of the basic authentication.

In [ ]:
host = 'https://path-to-server.com/piwebapi'
username = 'username'
password = 'password'
In [ ]:
client = PIInterface(host, username, password) # create instance for connection

Getting the data

Specify the path information of the attribute to get the value. In this example, get the data from seven days before to the present.

In [ ]:
get_params = {
    "assetserver": "assetserver",
    "database":  'database',
    "elements": ["element", "child_element"],
    "attributes": ["attribute", "child_attribute"],
    "start": "*-7d",
    "end": "*"
}

The meaning of each parameters are as follows.

  • assetserver: Asset server name
  • database: Database name
  • elements: Element name. If there exists parent-child relationship, describe from parent attribute.
  • attributes: Attribute name. If there exists parent-child relationship, describe from parent attribute.
  • start: Datetime when you start to get the data.
  • end: Datetime when you end to get the data.

Get the values of the attribute.

In [ ]:
get_df = client.get_values(**get_params)
In [14]:
get_df.head()
Out[14]:
Value
Timestamp
2018-05-15T02:52:15Z {'IsSystem': True, 'Name': 'No Data', 'Value':...
2018-05-15T02:42:55Z 99.4454
2018-05-15T01:36:25Z 87.2786
2018-05-14T15:59:17Z {'IsSystem': True, 'Name': 'Shutdown', 'Value'...
2018-05-14T14:39:02Z 99.1653

Inserting the data

Create the provisional data to insert to the PI System assets database.

The index of the PI system assets database correspond to the datetimeindex of the DataFrame.

In [ ]:
insert_df = pd.DataFrame([10, 11, 12, 13, 14], index=['20180520', '20180521', '20180522', '20180523', '20180524'])

Specify the path information to the attribute trying to insert the data.

In [ ]:
insert_params = {
    "assetserver": "assetserver",
    "database":  'database',
    "elements": ["element", "child_element"],
    "attributes": ["attribute", "focust"]
}

The meaning of each parameter is below.

  • assetserver: Assetserver name
  • database: Database name
  • elements: Element name. If there exists parent-child relationship, describe from parent attribute.
  • attributes: Attribute name. If there exsits parent-child relationship, describe from parent attribute.
In [ ]:
response = client.update_values(insert_df, **insert_params)

If inserting the data is successful, the HTTP status code 202 is returned.

In [22]:
print(response)
Out[22]:
({'items': None, 'links': None},
 202,
 HTTPHeaderDict({'Server': 'Microsoft-HTTPAPI/2.0', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Length': '0', 'Date': 'Tue, 15 May 2018 02:57:34 GMT'}))