Exporting Data to CSV

Hello,

I am using Ignition Perspective and I have built a page which allows you to:

1- select a tag from "TagBrowseTree'
2- select the start time
3- select the end time
4- click export button

The export button has the following OnClick Event:

def runAction(self, event):
	# Assuming you have a Tag Browser component named 'TagBrowser' and start/end time input components
	
	# Get selected tags from the Tag Browser
	selectedTags = self.getSibling("TagBrowseTree").props.selection.values
	
	# Get start and end times from input components (replace 'startTime' and 'endTime' with your actual component names)
	startTime = self.getSibling("startTime").props.value
	endTime = self.getSibling("endTime").props.value
	
	# Query historical data for selected tags within the specified time range
	historicalData = system.tag.queryTagHistory(paths=selectedTags, startDate=startTime, endDate=endTime)
	
	csv = system.dataset.toCSV(historicalData)
	
	# Use system.file.saveFile to have the user find a directory to write to.
	filePath = system.perspective.download("TrendExport.csv", csv, "Comma Separated Values")

I have noticed that when I click on the export button and the tag selected is of type float, the csv table duplicates the last value with the timestamp I clicked on the export button. Refer to images below.
I do not have this issue with non-float values such as datetime or string. How can I make sure that float values do get the duplicate? I just want what is stored in the database to be exported.

Notice the timestamp is 2:42:58 AM

When I clicked the export button at 2:44:05 AM, this is what I got in my csv file but the timestamp of the tag did not really change:
image

I did some more testing with a datetime tag and a string tag. I got the following results when I selected both tags and exported to CSV:

image

In my database, I have only 1 record for "Operator Initials" at the following timestamp:

  • 2:31:20 AM

And I have 4 records for "Sample Date and Time" at the following timestamps:

  • 2:21:32 AM
  • 2:24:08 AM
  • 2:31:20 AM
  • 2:35:55 AM

At the end, I want to export a csv which contains data from multiple tags and only shows values which are in the database. In the example above, I do not have a record in my database for "Operator Initials" at 2:35:55 AM so why is it showing up in the spreadsheet?

This looks related to your other question over here:

The simple answer is that you are using the tag historian for a task for which it is not designed. Every value it stores is "solitary", with its own timestamp, and not associated with any other.

You are trying to make Ignition's historian behave like a plain database, and that won't work. Use a plain database table, to which you insert rows from your user interface.

1 Like