Report data script to exclude negative numbers

I have a report data script that needs to exclude any values from the database that are negative numbers.

below is the current script.

endTime = system.date.now()
startTime = system.date.addHours(endTime,-24)

tagPaths = ['[IgnitionSQL]abiop_0401_fi',
		'[IgnitionSQL]cbiop_0903_fi',
		'[IgnitionSQL]ips2p_0254_fi',
		'[IgnitionSQL]pspsp_0311_fi',
		'[IgnitionSQL]rwpsp_0621_fi',
		'[IgnitionSQL]rwpsp_0622_fi',
		'[IgnitionSQL]ssubp_0661a_fi',
		'[IgnitionSQL]ssubp_0661b_fi',
		'[IgnitionSQL]ssubp_0662a_fi',
		'[IgnitionSQL]ssubp_0662b_fi',
		'[IgnitionSQL]ssubp_1031_fi',
		'[IgnitionSQL]sdbp_1113_fiq',
		'[IgnitionSQL]sdbp_1114_fiq']
		

data['tagData'] = system.tag.queryTagHistory(paths=tagPaths , returnSize = 24, aggregationMode='SimpleAverage', endDate=endTime, startDate=startTime)

Any help is appreciated.

system.tag.queryTagHistory returns a dataset. After reading the documentation I don’t see any argument you can provide to get this functionality built in, but you can do some manual logic iterating through the dataset.

ds =  system.tag.queryTagHistory(paths=tagPaths , returnSize = 24, aggregationMode='SimpleAverage', endDate=endTime, startDate=startTime)
rowsToDelete = []
for row in range(ds.getRowCount()):
    # do some logic here to determine if the row should be dropped or not - 
    #note that you are getting multiple tag paths per row so you might have 
    # some tags that are negative and others that are positive
    # up to you and your system to figure out what counts as a negative
    if deleteCondition:
        rowsToDelete.append(row)
ds = system.dataset.deleteRows(ds, rowsToDelete)
data['tagData'] = ds

Some additional reading about iterating through datasets - Datasets - Ignition User Manual 8.0 - Ignition Documentation

3 Likes

Officially, you can provide a custom aggregate function, although there are some hurdles to jump through.

Custom Tag History Aggregates

1 Like