Created
November 3, 2020 18:14
-
-
Save lydonchandra/a89690aaf440099aec85dbd75a3dbcbc to your computer and use it in GitHub Desktop.
Get earliest and latest timestamp for PIPoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()}' ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from anaconda, do
*
conda install pandas xlrd openpyxl
*
pip install pythonnet