PercentTrue in Python

Discussion created by Sagarakunso on Sep 26, 2019
Latest reply on Sep 27, 2019 by jyi


I am trying to calculate, in a day in terms of percentage, how long each digital tag is in a particular digital set by using Python. For example, the digital tag CDM158 has 5 states, I would like to know how many percent of the day CDM158=Auto.


I have built the code below, stuck with percentGood part.

AFCalculation.PercentTrue Method 


import sys
import clr


sys.path.append('C:\\Program Files (x86)\\PIPC\\AF\\PublicAssemblies\\4.0\\')


from OSIsoft.AF import *
from OSIsoft.AF.PI import *
from OSIsoft.AF.Asset import *
from OSIsoft.AF.Data import *
from OSIsoft.AF.Time import *

piServer = PIServers().DefaultPIServer
piExpr = '\'CDM158\' = \"Auto\"'
timerange = AFTimeRange('Y', 'T')
timespan = AFTimeSpan.Parse('1s')


myCalc = AFCalculation.PercentTrue(piServer,piExpr,timerange,AFTimeSpan.Parse('1d'),AFTimeSpan.Parse('1s'))


I get the error below when the code runs.

Exception has occurred: TypeError
No method matches given arguments for PercentTrue