Skip to content

Instantly share code, notes, and snippets.

@lydonchandra
Created November 3, 2020 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydonchandra/a89690aaf440099aec85dbd75a3dbcbc to your computer and use it in GitHub Desktop.
Save lydonchandra/a89690aaf440099aec85dbd75a3dbcbc to your computer and use it in GitHub Desktop.
Get earliest and latest timestamp for PIPoint
import datetime
import glob
import pandas as pd
import datetime as dt
import functools
import os
import sys
import clr
# TODO check PI assembly path
sys.path.append( r'C:\Program Files (x86)\PIPC\AF\PublicAssemblies\4.0' )
clr.AddReference( 'OSIsoft.AFSDK' )
clr.AddReference( 'System.Collections' )
from OSIsoft.AF import *
from OSIsoft.AF.PI import *
from OSIsoft.AF.Asset import *
from OSIsoft.AF.Data import *
from OSIsoft.AF.Time import *
from OSIsoft.AF.UnitsOfMeasure import *
from System.Collections.Generic import Dictionary
from System import *
AFTimeFormat = "%d-%b-%Y %H:%M:%S"
checkDateList = pd.date_range( checkStartDate, checkEndDate )
piServers = PIServers()
# PIserver2 = piServers['PI2']
PIserver1 = piServers[ 'PI1' ]
tagName = 'TAG1'
pi1Pt = PIPoint.FindPIPoint( PIserver1, tagName )
pointCount = 1
isForward = True
filterExpression = ''
includeFilteredValues = False
earliestDtStr = dt.datetime( 1970, 1, 1 ).strftime( AFTimeFormat )
earliestDt = AFTime( earliestDtStr )
piPtEarliestValues = pi1Pt.RecordedValuesByCount(
earliestDt, pointCount, isForward, AFBoundaryType.Inside, filterExpression, includeFilteredValues )
latestDtStr = dt.date( 2030, 1, 1).strftime( AFTimeFormat )
latestDt = AFTime( latestDtStr )
isForward2 = False
piPtLatestValues = pi1Pt.RecordedValuesByCount(
latestDt, pointCount, isForward2, AFBoundaryType.Inside, filterExpression, includeFilteredValues )
for value in piPtEarliestValues:
print( f'EarliestTimestamp={value.Timestamp.LocalTime}, value={value.ValueAsDouble()}' )
for value in piPtLatestValues:
print( f'LatestTimestamp={value.Timestamp.LocalTime}, value={value.ValueAsDouble()}' )
@lydonchandra
Copy link
Author

from anaconda, do
* conda install pandas xlrd openpyxl
* pip install pythonnet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment