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

**URL:** <https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [December 2, 2024, 1:02pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302 "2024-12-02T13:02:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielps1818](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@danielps1818](https://forum.inductiveautomation.com/u/danielps1818)\
**Post date:** [December 2, 2024, 1:02pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302/1 "2024-12-02T13:02:02Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 2, 2024, 1:12pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302/2 "2024-12-02T13:12:58Z")

</div>

Are you familiar with [Quality Codes and Overlays | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/tags/quality-codes-and-overlays#quality-code-reference-table)?

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?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 2, 2024, 1:20pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302/3 "2024-12-02T13:20:03Z")

</div>

~~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

```python
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.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 2, 2024, 1:23pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302/4 "2024-12-02T13:23:59Z")

</div>

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

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

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/651ede298fca73811f942fcf066ac8037a1134e4.png)

---

<div class="post-metadata">

**Author:** ![Lynn\_Martineau](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@Lynn\_Martineau](https://forum.inductiveautomation.com/u/Lynn_Martineau)\
**Post date:** [December 2, 2024, 1:48pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302/5 "2024-12-02T13:48:52Z")

</div>

In this script, `sumQuality` will be true until it encounters a tag with bad quality, then it will stay false to the end.

```python
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

```

---

<div class="post-metadata">

**Author:** ![danielps1818](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@danielps1818](https://forum.inductiveautomation.com/u/danielps1818)\
**Post date:** [December 2, 2024, 1:54pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302/6 "2024-12-02T13:54:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 2, 2024, 2:11pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-up-qualities-if-you-its-possible/99302/7 "2024-12-02T14:11:47Z")

</div>

The QualityCode class has a function for this:

```python
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])

```
