History Tag Reporting exclude 0s

I’m trying to figure out how to get average speed of our machine running from history tags. I have figured out how to do it where it gives me say the total average over a 1hr period or what have you, but it includes the 0 samples. How would I determine what the average speed is when it’s actually running (above 0)

I am currently trying to return it as part of JSON, but wasn’t sure how to do it using the build in reporting tools either.

This is a doGet I have setup in WebDev at the moment

# Handle and except inputs
	params = request['params']
		res = params['res']
		return RestHelper.GenError("Parameter (res) is required", "history/bpms?res=403&range=-1&rangeType=hours")
	range = int(RestHelper.DefaultParam(params, 'range', -24))
	rangeType = RestHelper.DefaultParam(params, 'rangeType', 'hours')
	plcPath = "[DEFAULT-RT]PLCs/" + res
	# Run query for range of inputs
	if rangeType == 'hours':
		returnSizeVar = (abs(range) * 60) * (60 / 5) # (range * secondsInHour) * (secondsInMinute / desiredSampleSizeInSeconds)
		dataSet = system.tag.queryTagHistory(paths=[plcPath + "/Status/BPM"], returnSize=returnSizeVar, rangeHours=range, aggregationMode="Average", returnFormat='Wide')
		returnSizeVar = abs(range) * (60 / 5) # range * (secondsInMinute / desiredSampleSizeInSeconds)
		dataSet = system.tag.queryTagHistory(paths=[plcPath + "/Status/BPM"], returnSize=returnSizeVar, rangeMinutes=range, aggregationMode="Average", returnFormat='Wide')
	pyData = system.dataset.toPyDataSet(dataSet)
	output = []
	# The for loop pulls out the whole row, so typically the variable row is used.
	for row in pyData:
		# Now that we have a single row, we can loop through the columns just like a list.
		output.append({ "timestamp": row[0], "value": row[1] })
	return {'json': output }