How to access the data accessed by Easy Chart > Save button?

I have Ignition version 7.6.5. I have created an easy chart that plots the tag history data. When I click the save button on that easy chart, it saves the selected data in an excel file. I would like to store that data plus some other information into a MySQL table instead. So I need to create a button that would do a function similar to the ‘Easy Chart > Save’ button plus some more.

Therefore, I want to know where is the tag history data behind the ‘Easy Chart > Save’ button located so I can query it myself and store it in a MySQL table? Or alternatively, can I get the script behind the ‘Easy Chart > Save’ button?

Thanks,

Shreyas

Hi Shreyas,
The SQLTag history data is stored in database tables that start with sqlt_.

Each SQLTag storing history is associated with a datasource in the designer. The datasource determines which database the history data is being stored to.

It may be easier to query the tag history data using the system.tag.queryTagHistory scripting function: inductiveautomation.com/support/ … istory.htm

Nick

Hello Nick,

Thank you for your suggestion to use system.tag.queryTagHistory scripting function. However, I am running into a problem using it.

I start with the following script.

startts = 1396395715
stopts = 1396396003
tagpath = “[VeecoIonMill]VEECO6/PMs/PM1/Trace Data/ActualRotationSpeed”
print system.tag.exists(tagpath)
print system.tag.read(tagpath).value

The print system.tag.exists(tagpath) statement returns a value of True. Also, the print system.tag.read(tagpath).value statement returns a value of 9.96. This tells me that my tagpath definition is correct and the tag.read function is giving me at least one correct value.

However, when I use the following statement, I get an error message attached in the file along with. It indicates that my definition of tagpath is incorrect.
tracedata = system.tag.queryTagHistory(tagpath,startts,stopts)
print tracedata

When I tweak the tracedata statement, to the following,
tracedata = system.tag.queryTagHistory(‘tagpath’,startts,stopts)
print tracedata

I get the following result for print tracedata statement Dataset [0R ? 8C] - indicating no data.

What am I doing wrong? How should I define the tagpath in the system.tag.queryTagHistory function to get the result correctly?

Thanks,

Shreyas

Hi Shreyas,

You need to be sure that you are using the data types that the system.tag.queryTagHistory function expects to receive.

The paths parameter is a PySequence of strings. The startDate and endDate parameters are the type Date.

A Python list is a PySequence so you could put your string tag path in a Python list and use that as the argument for paths.

Here is an example script:

from java.util import Date
tagpath = "[factory]VEECO6/PMs/PM1/Trace Data/ActualRotationSpeed"
#create a list with one tag path
paths = [tagpath]
#get date objects from epoch time
startts = Date(1390395715 * 1000)
stopts = Date(1396396003 * 1000)
tracedata = system.tag.queryTagHistory(paths,startts,stopts)

Hello Nick,

Thanks once again! I tried your code and when I use the print tracedata command at the end of the code, it does give me the following result: Dataset [4824R ? 2C]

I wanted to check the contents of the array. So I added the following code.
for row in tracedata:
for col in row:
print tracedata[row][col]

However, that gives me the error shown in screen capture 1.

Question 1: What command can I use to view the contents of the array tracedata?

Also, I want to be able to get all the tags selected in the easy chart. If I use the following script, I can get all the tags defined within [VeecoIonMill]VEECO6/PMs/PM1/Trace Data. However, I want to get only those that are selected as shown in screen capture 2.

equipment = ‘VEECO6’
pm = ‘PM1’
folderPath = “[VeecoIonMill]”+equipment+"/PMs/"+pm+"/Trace Data"
folder = system.tag.browseTags(folderPath)

Question 2: What can I do to get only the selected tags?

I tried to use the folder defined above in the system.tag.queryTagHistory command as shown below.
tracedata = system.tag.queryTagHistory(folder,startts,stopts)
But I guess I am making the same mistake of not using the PyDataset.

Question 3: How can I convert the list of selected tags into the PyDataset that I can use in the system.tag.queryTagHistory command?

Thanks,

Shreyas

Hi Shreyas,

Here is the code for your first question. First it prints all the column names in tracedata. Then it prints each row in tracedata:

columns = tracedata.getColumnNames()
print columns
tracedata = system.dataset.toPyDataSet(tracedata)
for row in tracedata:
	for column in columns:
		print str(row[column])+",",
	print

The following code answers your second and third questions. Instead of getting the paths from a SQLTags folder the code gets the selected tags from the Easy Chart itself. The tagPaths variable contains a data structure that can be used by the system.tag.queryTagHistory function.

You may need to change the line of code that has the component path to the Easy Chart. If needed, change it to use the location and name that you are using for the Easy Chart in your project.

easyChart = event.source.parent.getComponent("Easy Chart")
tagPaths = []
for row in system.dataset.toPyDataSet(easyChart.tagPens):
	if row["ENABLED"] == True:
		tagPaths.append(row["TAG_PATH"])

tracedata = system.tag.queryTagHistory(tagPaths,startts,stopts)

Hello Nick,

Thank you very much for responding to my questions! I tried using your solution. I am able to view the contents of the array tracedata, I can get only the selected tags and I can convert the list of selected tags to PyDataSet using the code you suggested.

easyChart = event.source.parent.getComponent(“Easy Chart”)
tagPaths = []
for row in system.dataset.toPyDataSet(easyChart.tagPens):
if row[“ENABLED”]:
tagPaths.append(row[“TAG_PATH”])

tracedata = system.tag.queryTagHistory(tagPaths,startts,stopts)
print tracedata
columns = tracedata.getColumnNames()
print columns
tracedata = system.dataset.toPyDataSet(tracedata)
for row in tracedata:
for column in columns:
print str(row[column])+",",
print

However, I am not getting the same result as the Save function on the Easy Chart does. For example, the easy chart for one of the signals is as shown in image 1.

When I click on the Save button and save the data in excel, the data I see is as shown in image 2. Even when the data is unchanged, I do see those values using the Save button.

However, when I use the code, I get only the following 11 points as shown in image 3. This data is really small compared to the data I get using the Save button for easy chart. How can I extract the same data as the save button?

I want to store all the data that gets stored by the Save button plus some other information into a MySQL table instead. So I need to create a button that would do a function similar to the ‘Easy Chart > Save’ button plus some more.

Hello shreyaslimaye,

Did you find-out a solution?

Regards,

Ignition 7.7.3-rc1 has come out with an easyChart.exportDatasets() method that exports the time series data to datasets which can then be inserted into a database or put anywhere.

Find out more about it in this forum topic: inductiveautomation.com/for … 92&t=13508

Best,

shreyaslimaye,

I am curious as well. how did you execute your custom script from the EasyChart’s save button?