Producing a list of tags that record more history than they should

I have been tasked with identifying tags that are recording more history than they should. Currently we are storing some data as on change and some with a 10 second history. I figured I would be able to query all of my tags in a script and then check if each column has more than the expected number of non null entries. This is where my script is at currently:

results = system.tag.browse("[default]", {'tagType':'AtomicTag', "recursive":True}).results
tagPathList = []
for result in results:
	tagPathList.append(result['fullPath'])
tagPaths = []
count=0
tagCount = 0
data = system.tag.queryTagHistory(tagPathList,system.date.addMinutes(system.date.now(),-10),system.date.now(),-1)
print(data)
for i in range(data.getColumnCount()):
    count = 0
    for j in data.getColumnAsList(i):
        if j is not None:
            count += 1
    if count > 60:
        tagCount += 1
        tagPaths.append(tagPathList[i-1])
print(tagCount)
print(tagPaths)

My main issue currently is that if I select too much I get 0 rows returned by my query. I'm not sure if I need to only query tag history for tags that have history for it to work?

I just tried with tags that only have history and still get the same result, zero rows.

#obtain a list of all tag paths with the history enabled property added on.
tagPathListHist = []
results = system.tag.browse("[default]", {'tagType':'AtomicTag', "recursive":True}).results
for result in results:
	tagPathListHist.append(str(result['fullPath'])+'.HistoryEnabled')

#return a list of indices that reference tags with history enabled
index = 0
indices = []
historyEnabled = system.tag.readBlocking(tagPathListHist)
for path in historyEnabled:
	if path.value == True:
		indices.append(index)
	index += 1
	
#generate list of tag paths for tags that have history enabled.	
tagPathList = []
for item in indices:	
	tagPathList.append(results[item]['fullPath'])
count=0
tagCount = 0

#query tag history for history tags and iterate through to check if each column has more than the expected number of entries.
tagPaths = []
data = system.tag.queryTagHistory(tagPathList,system.date.addMinutes(system.date.now(),-10),system.date.now(),-1)
print(data)
for i in range(data.getColumnCount()):
    count = 0
    for j in data.getColumnAsList(i):
        if j is not None:
            count += 1
    if count > 60:
        tagCount += 1
        tagPaths.append(tagPathList[i-1])
print(tagCount)
print(tagPaths)

Improved readability with taghistory checking.

Have you tried the tag report tool?
https://docs.inductiveautomation.com/display/DOC81/Tag+Report+Tool

I haven't but I am unfortunately on an earlier version, might see if I can upgrade to the newest version.

I ended up just having to iterate through each tag and get the list that way. Managed to reduce my tag set slightly which sped things up. Took about 15 minutes to get through it all. Not sure why the queryTagHistory function was returning zero rows though.