Easy Chart - Save data for excel

I have historical data stored in no particular order with tag historian (default historical scan class with default settings, unlimited time between records). Now the customer is requesting all of last years historical data as an excel file with a fixed interval of one minute.

Obviously, my raw data isn’t in the required format so I’m attempting to export it via the easychart “save data for excel” function. It’s doing exactly what I’m looking for except I can’t seem to coerce it into minute intervals. Is this an option?

Any help much appreciated.

I don’t know if you can do it with the easy chart, but you could look into system.tag.queryTagHistory and system.dataset.exportExcel.

Specifically, look at the intervalMinutes argument for queryTagHistory.

1 Like

Personally for what your doing, if you want 1 minute intervals, I wouldn’t use the easy chart functions, I would create my own, you can use the easy chart to set a range, then give an export button with:

start = #set your start date
end = #set your end date
rs = system.date.minutesBetween(start,end)
tPaths = ['your tag path']

th = system.tag.queryTagHistory(paths=tPaths,startDate=start,endDate=end,returnSize=rs)

filePath = system.dataset.exportCSV("data.csv",1,th)

You still need to set your start and end date to use this, but you can link it to the start/end of your easy chart then put this in the action performed of a button.

2 Likes

Thanks lads, that’s exactly what I’m looking for. I knew there had to be a better way.

Can you suggest the correct syntax to link the tPaths to the pen list of an Easy Chart? Ive got a dozen or so charts already setup and would like to use your solution for exporting better data, but cant seem to get the tags list working.
Thanks!

I can think of two quick examples if you replace:

tPaths = ['your tag path']

with

pensDS = event.source.parent.getComponent('Easy Chart').tagPens
pensDS = system.dataset.toPyDataSet(pensDS)
tPaths = []
for row in pensDS:
	tPaths.append(row[1])

or

pensDS = event.source.parent.getComponent('Easy Chart').tagPens
tPaths = []
for x in range(pensDS.getRowCount()):
	tPaths.append(pensDS.getValueAt(x,1))

This is assuming you are using the tagPens for the easy chart. This is also assuming that your path to the easy chart is the same as what I showed.

Thanks for the speedy reply. We’ll give it a try.

No problem, you posted at the perfect time, I was checking the forum hoping the rain would slow down so I could walk to my car.

One other suggestion that is a little cleaner is:

pensDS = system.dataset.toPyDataSet(event.source.parent.getComponent('Easy Chart').tagPens)
tPaths = [row[1] for row in pensDS]
2 Likes

I took your first suggestion and ran with it. I had originally tried the nested getComponent / toPyDataSet functions but couldnt quite get it. We’ve already got a chunk of the data exported and off to be polished so thanks again!

Older post but relevant to a project im working on. Is there a way to amend the script to only generate tag paths for pens that are enabled?

Edit: I meant if the pen has User Selection enabled, and a user has turned the pen off. Anyway to ignore that pen in the tag path generation?

Something like this should work:

pensDS = system.dataset.toPyDataSet(event.source.parent.getComponent('Easy Chart').tagPens)
tPaths = [row[1] for row in pensDS if row[5]]
1 Like

Unfortunately no. Thats the property that is indeed if the pen is enabled statically, but it doesnt appear to follow the dynamic user selection of turning a pen off. Neither does row [17] which is the property that allows a pen to be turned off by a user. But i cant seem to find the dynamic value that indicates a pen HAS been turned off.

I realize my question was posed incorrectly. By "enabled" i meant user selected from the pen chart.

The goal is to have an easy chart with 20 pens available, user selectable on or off using the USER SELECT property. Depending on which pens are selected and being trended, i want to export the data only for those pins. Basically using the easy chart to handle the filtering of data as these charts already exist.

Okay, I'm an idiot. The ENABLED property does work that bpreston suggested. I didn't realize that the original Easy Chart creator did a 1:1 translation of tag pens to calculated pens (multiply by 1) and that the ENABLED on the pen select dialog was tied to the calculated pens, not the tag pens. Not sure why they did that, as I need to query the tag pens to get the tag paths, so I'll redo the chart to get rid of calculated pens and use tag pens direct since the calculations are all pass through multiply by 1.

2 Likes

I'll go out on a limb and say you'll probably see an uptick in performance as well.

1 Like

Implemented and working well. A trivial issue and I found some older threads of people asking, but no solutuon....

Is there a way to orgainze pens in a particular order in an easy chart without deleting and recreating? Alohabetical works fine for chart presentation, but for the data dump, the dataset strictly follows the order of the tag pen entry. Surprised that theres not a promote/demote feature to move the rows of the data set around in the configurator.

It is a dataset property. There are a number of ways to assign a sorted version to the chart. Start with system.dataset.sort() in a script, or use sortDataset() in an expression binding.

Or, if you are scripting pen addition and deletion, do the sort during that operation.

Interesting....might have to append an "1_", "2_" and so on to the row name to define the order i want and do a natural sort. As always, thanks for the direction. Something to play with.