You may need to provide an intervalHours or Minutes to the tag History Call. Also, You may want to investigate using the queryTagCalculations function to avoid iterating through the dataset.
Since what you are trying to do in this instance is provide a single return value from the aggregation then I think you could just call the value directly from the data set since it should always be in the same position.
startTime = event.source.StartTime
endTime = event.source.EndTime
dataSet = system.tag.queryTagCalculations(['SOMETAG'],['CountOn'],startTime,endTime)
event.source.Count = dataSet.getValueAt(0,1)
For what it’s worth IMHO, converting to a pyDataSet is really unneeded in a situation like this. I don’t feel like it does anything to really account for the extra overhead of calling the function to convert it. I also feel that it makes the code less readable and there by less pythonic.
Perhaps someone with more understanding of whats going on behind the scenes can speak to if it is more optimal or not. In my experience it isn’t.
I personally favor using the range function instead. Something like:
count = 0
for row in range(dataSet.rowCount):
for col in range(dataSet.columnCount):
count += 1
event.source.Count = count
Your code is perfectly valid, just thought I would share a different approach.