I have a list of tags and wanna get the worst quality of all of them.
So I wanna sum up all the qualities or something like that to get an overall quality. My current aproach is to go throught the list and pick the first non good value that I encounter. And this works. But this doesn't check all the tags.
Hope I explain what I'm looking to do. I don't really need it, just looking for some ideas to improve my current code.
There is a .worstOfAll method on the list of results you get from write blocking that may be of use nevermind that is on the quality itself.
I might do something like
def calcScore(results):
"""
Results: list of results from a writeBlocking
"""
score = 0
maxScore = len(results)
for result in results:
if result.good:
score+=1
elif result.bad:
score+=-1
elif result.error:
score+=0
return score / maxScore
Obviously you would need to choose how bad a bad or error affects a score. This score could potentially go negative if all writes were bad for instance.
I assumed this was for writing to tags, if it is for reading from tags - I would go with @dkhayes117 solution. Expressions will evaluate the fastest.
In this script, sumQuality will be true until it encounters a tag with bad quality, then it will stay false to the end.
tagPaths = ['your','List','Of','Tagpaths','Here']
tagValues = system.tag.readBlocking(tagPaths)
sumQuality = True
for tag in tagValues:
sumQuality = sumQuality and tag.quality.isGood()
print sumQuality