# Get Time Running/Time Down from Easy Chart

**URL:** <https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [September 10, 2019, 8:08pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153 "2019-09-10T20:08:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DANewton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/danewton/32/10851_2.png) [@DANewton](https://forum.inductiveautomation.com/u/DANewton)\
**Post date:** [September 10, 2019, 8:08pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153/1 "2019-09-10T20:08:58Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d10468afd757c564510fc76d7b4a0a54737e80ef.png)  
I need to get the time running and time down for this bar chart. It isn’t really a bar chart. I’m showing on = 1 and off = zero vs. time (absolute). Each plot represents a different device (blue and green).

I have been asked to show the amount of time on and off for each device as it shows in the chart. For the blue plot in the image shown, that means about 59 hours on and 13 hours off.

Since the chart’s time range can change (i.e. form 3 hours to 3 days), the on/off time range would also change. What’s the best way to handle this?

Thanks,  
Darrell

---

<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:** [September 11, 2019, 1:27pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153/2 "2019-09-11T13:27:59Z")

</div>

Hi Darrell,

You can get the dataset with the pen valuse and iterate over it to calculate uptime.

Completely untested script. You will have to modify to your specific chart data.

```python
# Path to the easychart
chart = event.source.parent.getComponent('Easy Chart')

# Get the datrasets from the cart
chartDatasets = chart.exportDatasets()

# Convert to PyDataSet
dataIn = system.dataset.toPyDataSet(chartDatasets[0])

# Intialtize uptime variable
uptime = 0

# Get length of the dataset
dataLength = len(dataIn)

# Initialize the last item flag
lastItem = 0

# Iterate over the dataset using an index. this lets us access the row after the current one we are working with. 
for i in range(dataLength):
	# Check to see if it's the last row
	if i+1 == dataLength:
		lastItem = 1
	# If it's not the last row...
	if lastItem == 0:
		# Check to see if the pen value is 1
		if dataIn[i]['penName'] == 1:
			# Add the seconds between the t_stamps of the current row and the next row.
			uptime += system.date.secondsBetween(dataIn[i]['t_stamp'], dataIn[i+1]['t_stamp'])
			
print uptime

```

---

<div class="post-metadata">

**Author:** ![DANewton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/danewton/32/10851_2.png) [@DANewton](https://forum.inductiveautomation.com/u/DANewton)\
**Post date:** [September 12, 2019, 6:58pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153/3 "2019-09-12T18:58:38Z")

</div>

Thanks for the quick reply, Jordan. I’m new to scripting, so it’s taking me a while to implement. I’ll post the results as soon as I get it working … or not. 😁

---

<div class="post-metadata">

**Author:** ![DANewton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/danewton/32/10851_2.png) [@DANewton](https://forum.inductiveautomation.com/u/DANewton)\
**Post date:** [September 12, 2019, 7:43pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153/4 "2019-09-12T19:43:44Z")

</div>

I’m getting an error on ‘penName’, line 27. I’m assuming that the PyDataSet acts as an array, and we’re indexing [i] in the for loop to check all the “1” values in the column under ‘penname.’ In your script, I’m also assuming that the ‘penName’ is a generic term that I would replace with the real pen name in the Easy Chart, which is “Ball Mill Running”. But when I run it, I still get an error. T

I also have this script is attached to a numeric display that should accept the value returned for uptime.

Thanks,  
Darrell

---

<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:** [September 12, 2019, 7:47pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153/5 "2019-09-12T19:47:22Z")

</div>

Can you past a screenshot with your pen setup?

---

<div class="post-metadata">

**Author:** ![DANewton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/danewton/32/10851_2.png) [@DANewton](https://forum.inductiveautomation.com/u/DANewton)\
**Post date:** [September 12, 2019, 7:49pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153/6 "2019-09-12T19:49:04Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/75a30b2a0995f253a96b77d7f08e5da25ec8a833.png)

---

<div class="post-metadata">

**Author:** ![DANewton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/danewton/32/10851_2.png) [@DANewton](https://forum.inductiveautomation.com/u/DANewton)\
**Post date:** [September 12, 2019, 7:55pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153/7 "2019-09-12T19:55:39Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/40f7a835d2447c453db5e6cb5cef39f02489358c.png)

---

<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:** [September 12, 2019, 9:06pm UTC](https://forum.inductiveautomation.com/t/get-time-running-time-down-from-easy-chart/28153/8 "2019-09-12T21:06:48Z")

</div>

Ok, had to spin this up again, because I don’t use historical tags. 🙂

It looks like you will need to use the tag path (minus the provder). Example: _Ball Mill_/B3:2\_4
