Get Time Running/Time Down from Easy Chart


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

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.

# 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
2 Likes

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. :grin:

1 Like

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

Can you past a screenshot with your pen setup?

image

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

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