How to sum up qualities? (if you it's possible)

Hi!

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.

Thanks!

Are you familiar with Quality Codes and Overlays | Ignition User Manual?

What do you mean by "the worst" quality? The OPC quality code values may not be in the order you require.

So I wanna sum up all the qualities or something like that to get an overall quality.

How's that going to work?

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.

Instead of summing qualities, you might want to have an expression that sums a count of bad qualities or similiar.

sum(
	isBadOrError({[.]Bool 1}),
	isBadOrError({[.]Bool 2}),
	isBadOrError({[.]Bool 3})
)

image

3 Likes

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

That is what I'm currently doing. But I break the loop whenever I find "not good" and take that quality

The QualityCode class has a function for this:

from com.inductiveautomation.ignition.common.model.values import QualityCode

tagPaths = ['Tag_1','Tag_2','Tag_3']
tagValues = system.tag.readBlocking(tagPaths)

worstQuality = QualityCode.worstOfAll([qv.quality for qv in tagValues])
7 Likes