# Script about calculate the cumulative downtime

**URL:** <https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [December 10, 2023, 1:34am UTC](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940 "2023-12-10T01:34:03Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![chen\_zhe](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@chen\_zhe](https://forum.inductiveautomation.com/u/chen_zhe)\
**Post date:** [December 11, 2023, 12:47pm UTC](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940/21 "2023-12-11T12:47:31Z")

</div>

i have no idea about the tag history i will try the script first ,if it can't be ,i will try tag history,thanks very much all

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 11, 2023, 1:33pm UTC](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940/22 "2023-12-11T13:33:25Z")

</div>

Oh no! You are using a user interface component to run your process!

Don't do that! Any disruption to your client will break your process.

Run your script in a gateway event.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 11, 2023, 1:33pm UTC](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940/23 "2023-12-11T13:33:41Z")

</div>

> [@chen\_zhe](#):
>
> i have no idea about the tag history

> [@Transistor](#):
>
> Tag History is not a good solution for this because you want values at 08:00 and 20:00 and the historian doesn't interpolate well.

I would use a transaction group for this (or a scripted equivalent).

I use a transaction group to store the following every ten seconds:

- actual count
- goal count (how many should have been made at that time)
- line status (we also have small stops in there)

This allows me to easily trend efficiencies, and caclulate uptimes / downtimes.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/3/d39dfec42413e8ba58d7e293a90b8ba2cdf9ee6b.png)

As an example, our line status is:

- 0 : running
- 1-4 : small stops
- 5 : down
- 6 : break

To calculate times (in seconds) the query would be something like:

```sql
SELECT line_status, COUNT(line_status) * 10
WHERE t_stamp >= '2023-12-11 08:00:00'
  AND t_stamp < '2023-12-11 20:00:00'
GROUP by line_status

```

---

<div class="post-metadata">

**Author:** ![chen\_zhe](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@chen\_zhe](https://forum.inductiveautomation.com/u/chen_zhe)\
**Post date:** [December 11, 2023, 2:15pm UTC](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940/24 "2023-12-11T14:15:09Z")

</div>

Where is the gateway event? for about the label text

---

<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 11, 2023, 2:22pm UTC](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940/25 "2023-12-11T14:22:54Z")

</div>

![Gateway event](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/a/1a7490c3fe8117e0ae9a8928d6e94c12a5d90d80.png)

[https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts)

> **[Gateway vs. Client Event Scripts Video at Inductive University](https://inductiveuniversity.com/video/gateway-vs-client-event-scripts/8.1)**
>
> Learn the difference between Gateway and Client event scripts to understand when to use one vs the other.

Have the gateway event update a memory tag.  
Bind the label `props.text` to the memory tag.

[Previous page](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940.md?page=1)
