def getPIWebApiClient(self): """ TODO: The PI Web API client must provide a user name and password when using “basic” authentication Store passwords outside of the code in a hardware TPM, trusted service (credential manager) or in a protected file. Code to return the user name and password is not shown here. """ return PIWebApiClient("https://devdata.osisoft.com/piwebapi", False, "webapiuser", "!try3.14webapi!", True)
def test_getBatch(self): client = PIWebApiClient("https://marc-rras.osisoft.int/piwebapi", useKerberos=False, username="******", password="******", verifySsl=False) landing = client.home.get() req1 = PIRequest() req2 = PIRequest() req3 = PIRequest() req1.method = "GET" req1.resource = "https://marc-rras.osisoft.int/piwebapi/points?path=\\\\MARC-PI2016\\sinusoid" req2.method = "GET" req2.resource = "https://marc-rras.osisoft.int/piwebapi/points?path=\\\\MARC-PI2016\\cdt158" req3.method = "GET" req3.resource = "https://marc-rras.osisoft.int/piwebapi/streamsets/value?webid={0}&webid={1}" req3.parameters = ["$.1.Content.WebId", "$.2.Content.WebId"] req3.parent_ids = ["1", "2"] batch = {"1": req1, "2": req2, "3": req3} batchResponse = client.batch.execute(batch) point1 = client.api_client.deserialize_object( batchResponse["1"].content, 'PIPoint') point2 = client.api_client.deserialize_object( batchResponse["2"].content, 'PIPoint') itemsStreamValue = client.api_client.deserialize_object( batchResponse["3"].content, 'PIItemsStreamValue') pass
def test_updatePoint(self): client = PIWebApiClient("https://marc-rras.osisoft.int/piwebapi", useKerberos=False, username="******", password="******", verifySsl=False) sinusoid_point = client.point.get_by_path("\\\\marc-pi2016\\sinusoid") updated_point = PIPoint() updated_point.descriptor = "New desc" client.point.update_with_http_info(sinusoid_point.web_id, updated_point) pass
def getPIWebApiClient(self): """ TODO: The PI Web API client must provide a user name and password when using “basic” authentication Store passwords outside of the code in a hardware TPM, trusted service (credential manager) or in a protected file. Code to return the user name and password is not shown here. """ url, username, password = self.getCredentials() #print ("url %s, username %s, password %s" % (url, username, password)) return PIWebApiClient(url, useKerberos=False, username=username, password=password, verifySsl=False)
def getPIWebApiClient(self): return PIWebApiClient("https://devdata.osisoft.com/piwebapi", False, "webapiuser", "!try3.14webapi!", True)
from osisoft.pidevclub.piwebapi.pi_web_api_client import PIWebApiClient from osisoft.pidevclub.piwebapi.rest import ApiException import urllib3 import json path_prefix = "" #path_prefix = "~/hack-davis-osi-bucket/" urllib3.disable_warnings() client = PIWebApiClient("https://ucd-pi-iis.ou.ad3.ucdavis.edu/piwebapi", useKerberos=False, verifySsl=False) buildings = [ 'Activities and Recreation Center', 'Genome & Biomedical Sciences Facility', 'Giedt Hall', 'Mrak Hall', 'Olson Hall', 'RMI Brewery, Winery, and Food Pilot Facility', 'Shields Library', 'Tercero 2', 'Tercero 3', 'Tercero Dining Commons' ] types = ["ChilledWater", "Electricity", "Steam"] attributes = ["Demand", "Cumulative Use"] query = "af:\\CEFS\\UCDAVIS\\Buildings\\{0}\\{1}|{2}" wifi_query = "af:\\REST POSTs to PI\\REST POSTs to PI\\UFL\\UFL\\Wifi Access Points\\ARC|Total_Count" # fields = "Items.value;Items.timestamp;Items.unitabbr" start = "*-7d" query_interval = "2m" # for b in buildings:
def __init__(self): self.client = PIWebApiClient("https://pi.dvnhackathon.com/piwebapi/", False, "hacker", "Pa$$w0rd", True) self._base_path = '\\\\OSISOFTPI-001\\Devon\\Skids\\Skid #77' self._skid_77 = self.client.element.get_by_path(self._base_path, None) self._attributes = self._get_attributes(self._skid_77)
def getPIWebApiClient(self): return PIWebApiClient("https://devdata.osisoft.com/piwebapi", useKerberos=False, username="******", password="******", verifySsl=False)
import json from osisoft.pidevclub.piwebapi.pi_web_api_client import PIWebApiClient import numpy import pandas from warnings import simplefilter simplefilter('ignore') #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# # # Methods # #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# pi_client = PIWebApiClient("https://pi.dvnhackathon.com/piwebapi/", False, "hacker", "Pa$$w0rd", True) df1 = pi_client.data.get_recorded_values( "af:\\\\OSISOFTPI-001\\Devon\\Skids\\Skid #77|Active Gel Breaker", None, None, '10-nov', None, None, 100000, None, '18-oct', None) skid_77 = pi_client.element.get_by_path('\\\\OSISOFTPI-001\\Devon\\Skids\\Skid #77', None) skid_77.links['Attributes'] #attributes = pi_client.attributes.get_by_path(skid_77.links['Attributes'], None) attributes = pi_client.element.get_attributes(skid_77.web_id, None, None, None, None, None, None, None, None, None, None, None, None)
from tzlocal import get_localzone import pickle #Não printar mensagens de segurança import warnings warnings.filterwarnings("ignore") #PI Web API Client import osisoft.pidevclub.piwebapi #Liberar acesso ao servidor user= #USER pw = #PASSWORD from osisoft.pidevclub.piwebapi.pi_web_api_client import PIWebApiClient client = PIWebApiClient('https://NAME_DIR/piwebapi', False, user, pw, False) #não dobrar as barras path = 'pi:\\\\NAME_DIR_LOCAL\\' #Web IDs das tags de predição de rigidez def web_ids(): point1 = client.point.get_by_path('\\\\fliptop21\\B6RIGIDEZ_L_FRC', None) point2 = client.point.get_by_path('\\\\fliptop21\\B6RIGIDEZ_T_FRC', None) webIds = list() webIds.append(point1.web_id) webIds.append(point2.web_id) return webIds #Descobrir data e hora do último valor das tags de predição def last_prediction(webIds):
def __init__(self, root="https://util-cs-iis.ou.ad3.ucdavis.edu/piwebapi/", data_server_path="\\\\UTIL-PI-P", asset_server_path="\\\\UTIL-AF", asset_database='Gimli', time_zone='America/Los_Angeles', use_kerberos=True, username=None, password=None): """ Parameters ---------- root - str PI web API root url -Read / write: https://util-cs-iis.ou.ad3.ucdavis.edu/piwebapi/ -Read only: https://ucd-pi-iis.ou.ad3.ucdavis.edu/piwebapi/ data_server_path - str Name of data server to access within PI asset_server_path - str Name of the asset server in PI asset_database - str Name of the database in the asset_server time_zone - str timezone name from TZ database https://www.iana.org/time-zones use_kerberos - Bool True - use the windows authentication for PI authentication False - Use a username/password basic authentication username - str or None or 'file' The users UCD email to authenticate in PI with If only he username is provdided, the user will be prompted for a password, and the password will be stored locally but as base64 encoded text to load the stored UN:PW data use username = '******' password - str or list of ordinals or None If str, try to authenticate with the username if list, the list will be converted element wise by chr(x) and joined into a single string if None and use_kerberos = False, then prompt user for password Returns ------- class instance (pi) """ self.default_web_id_source = 'generate' self.time_zone = time_zone # Athentication Section # Allows us to access the read only instance of the API if we want to # avoid authentication all together if root.lower() in ['readonly', 'read only', 'r', 'ro', 'read-only']: root = "https://ucd-pi-iis.ou.ad3.ucdavis.edu/piwebapi/" use_kerberos = False username = '******' password = '******' self.default_web_id_source = 'get' elif username is not None: use_kerberos = False if isinstance(password, list): password = ''.join([chr(x) for x in password]) if username == 'file': username, password = self._load_user_file() else: password = input(f"{username}, please provide your password\n>>") save_pw = input("save password? [y/n]\n>>") if save_pw == 'y': with open(os.path.join(local_path, 'file.txt'), 'w+') as f: save_string = self._xor_crypt_string(f'{username}:{password}') f.write(save_string) self.client = PIWebApiClient(root, useKerberos=use_kerberos, username=username, password=password, verifySsl=True) try: # Attempt to test connection # OPPM dataServer object self.dataServer = self.client.dataServer.get_by_path( data_server_path) except Exception as e: print(e) username, password = self._load_user_file() self.client = PIWebApiClient(root, useKerberos=False, username=username, password=password, verifySsl=True) try: # OPPM dataServer object self.dataServer = self.client.dataServer.get_by_path( data_server_path) except: print("FAILED TO AUTHENTICATE!! Returning None") return # /End authentication section asset_database_path = asset_server_path + '\\' + asset_database # OPPM assetDatabase object self.assetDatabase = self.client.assetDatabase.get_by_path( asset_database_path)
'DESVIO TRANSVERSAL DE ESPESSURA'] #categoria das tags cat = ['EXTERNO','EXTERNO','EXTERNO','EXTERNO','EXTERNO','INTERNO','EXTERNO','EXTERNO','INTERNO','HISTÓRICO', 'EXTERNO','HISTÓRICO','INTERNO','SCANNER','SCANNER','SCANNER','SCANNER','SCANNER'] print('OK!') #conectando e extraindo dados a serem analisados import osisoft.pidevclub.piwebapi user= #USER PARA ACESSO pw = #PASSWORD DO USER from osisoft.pidevclub.piwebapi.pi_web_api_client import PIWebApiClient client = PIWebApiClient('https://NAME_DIR/piwebapi', False, user, pw, False) #INCLUIR NAME_DIR path = 'NAME_DIR_LOCAL' #INCLUIR NAME_DIR_LOCAL paths = [] for tag in tags: paths.append(path + tag) #puxar dados do dia anterior a cada 1 min df1 = client.data.get_multiple_interpolated_values(paths, start_time = '*-1440m', end_time = '*',interval = '1m') print('OK!') df_aux = [df1] #pré-processamento: selecionar apenas as colunas de valores e uma coluna de Timestamp, renomear colunas dos df's numbers = np.arange(1,(len(tags)+1),1)
import requests from osisoft.pidevclub.piwebapi.pi_web_api_client import PIWebApiClient url = "https://cb-oakpi4-vis.dev.osisoft.int/piwebapi/" client = PIWebApiClient(url, False, "kfrank", "Dinosaur8!", True) print(client.data.get_recorded_values("pi:\\\\PIKFRANK\\internproject")) import requests from flask import Flask, render_template from flask_cors import CORS app = Flask(__name__) CORS(app) # @app.route("/") # def hello(): # return "Hello World!" # # print('testing') # @app.route("/getPoint") # def testing(): # url = "https://cb-oakpi4-vis.dev.osisoft.int/piwebapi/" # return getVal(url)
from osisoft.pidevclub.piwebapi.pi_web_api_client import PIWebApiClient client = PIWebApiClient("https://test.osisoft.com/piwebapi", False, "username", "password", True) #df1 = client.data.get_recorded_values("pi:\\\\JUPITER001\\cdt158", None, None, "*-9d", None, None, None, None, "*-10d", None) df1 = client.element.get_by_path("\\\\JUPITER001\\Universities\\UC Davis", None) # df4 = client.data.get_multiple_recorded_values(["pi:\\JUPITER001\sinusoid", "pi:\\JUPITER001\sinusoidu", "pi:\\JUPITER001\cdt158"], None, "*", None, None, None, None, "*-1d", None) # df2 = client.data.get_interpolated_values("pi:\\JUPITER001\\sinusoidu", None, "*", None, None, "2h", None, "*-1d", None) # df3 = client.data.get_plot_values("pi:\\\\JUPITER001\\sinusoidu", None, "*", 10, None, "*-3d", None) # df4 = client.data.get_recorded_values("pi:\\\\PISRV1\\sinusoid", None, None, "*", None, None, None, "items.value;items.timestamp", "*-1d", None) # df5 = client.data.get_recorded_values("pi:\\\\PISRV1\\sinusoid", None, None, "*", None, None, None, "items.good;items.questionable;items.substituted", "*-1d", None) print(df1)