Trouble Downloading time series chart data

def runAction(self, event):
	
	dataset = self.getSibling("TimeSeriesChart").props.series[0].data
	system.perspective.print(dataset)

this just prints "Dataset [111R ⅹ 2C]"

I can't seam to be able to get the actual data. I've tried dataset[0] just to see if the print method is dumb and not recognizing it as an array. but that didn't work. I'm missing something here. Maybe a function or something that makes the data available.

Any help would be great. The end goal is to be able to export the data by downloading in browser.

data = system.dataset.toCSV(dataset, localized)
	
system.perspective.download("Data.csv", data)

When you print anything in java or jython or python, there's an implicit "stringification" performed on any object, because printing is fundamentally about printing strings.

Objects control their own stringification, and the default for most complex objects in the java world is to make a simple summary. Which is what dataset objects do. That means, if you want to print the content, you have to iterate through the rows, and iterate through the columns, to build your own string.

That said, have you tried the last two lines of code you supplied?

1 Like

This was a rabbit hole I wasn't expecting :slight_smile:

Turns out you have to be explicit when passing a dataset to the toCSV() function. That was the error which was pretty annoying to find.

And I learned that Dataset is not python standard or it would have printed just fine. No idea why you would use python and then cram into it a non standard datatype. Fortunately you can just iterate through the Dataset and make a simple C style array.. Then make a CSV string when you are done with it.

Here is the doc for DATASET
DATASET DOC

Here is working code if anyone has had trouble with exporting a single series from TimeSeriesChart.. If you need more then one series it gets a bit more complicated depending on how you want to download it.

	chartdata = self.getSibling("TimeSeriesChart").props.series[0].data
	
	#Example of how to pring a single value from dataset
	system.perspective.print(chartdata.getValueAt(1,1))
	
	CSVstring = system.dataset.toCSV(dataset = chartdata)
	
	#Example of how to print to the browser console
	system.perspective.print(CSVstring)
	
	system.perspective.download("Data.csv", CSVstring)
		
	

Ignition uses Python-the-language not Python-the-C-implementation.

Ignition uses Jython-the-java-implementation, so naturally works with java types, because they are standard for jython. Ignition is written in java. :man_shrugging:

The definitive details on the Dataset type are here:

Also, Dataset is a way richer type than anything in the Python stdlib.
It's not equivalent to a list of lists (because you've got column names and types, plus optional quality information) and it's not equivalent to a list of dictionaries (because you get O(1) access, [1], to any given row/column index).

For what it's worth, the tension between "this is awkward to use from Python/Jython" and "this is the underlying Java interface" can be papered over somewhat in 8.1 and prior using system.dataset.toPyDataSet. In 8.3, you won't have to do this manually, any dataset you encounter from scripting will automatically appear to be a PyDataset.


  1. generally ↩︎

4 Likes

is it the same approx interface as Pandas?

I've never used pandas, but I'll say no. The behavior of PyDatasets is essentially unchanged; the only difference is that you no longer have to manually wrap to get all the ergonomic benefits.

Dataset introduction — pyDataset 0.16.3 documentation is this the pydataset library?
Or is it something internal to ignition

Specific to Ignition.
It's a Java class that implements the right Java interfaces so that Jython knows to expose it directly, rather than doing auto-wrapping.

In 8.1:

In 8.3:

Note the explicit dunder method declarations in the Javadoc and that the base class is PyObject.