Charting data based on position in a dataset

Hello,

I am creating a Load Curve in ignition. What I did is I have the data I need sorted into a dataset in the correct order (Not based on time but based on magnitude of the data). Now I am trying to get that data into a chart where the x axis is position in the dataset. Does anyone have experience with this?

Thanks in advance!

Since it’s already sorted, you can extract the load values as a list from the dataset. Then you make a list of values to rank them, then put them into a new dataset.

headers = ['rank', 'value']

#get load data as a list from the dataset
valueList = oldDataSet.getColumnAsList(oldDataSet.getColumnIndex('valueColumn'))

# make a list with the values from 0 to the length of the list of values
rankList = range(len(valueList))

# iterate through the values to create data for the new dataset.
data = [[rank, value] for rank, value in zip(rankList, valueList)] 

# make a new dataset
newDataSet = system.dataset.toDataSet(headers, data)

What Jordan said, but I would simplify it with python’s enumerate() function…

valueList = oldDataSet.getColumnAsList(oldDataSet.getColumnIndex('valueColumn'))
return system.dataset.toDataSet(['rank', 'value'], [[r, v] for r, v in enumerate(valueList)])

Or if we’re code-golfing, you can simplify the enumeration in @pturmel’s example a little bit with [list(pair) for pair in enumerate(valueList)]

But I should really just fix toDataset to allow you to pass a list of tuples directly :wink:

4 Likes

getColumnAsList isn’t an attribute of a dataset… unless I am missing something.

It is a method of a BasicDataset, the core of almost all of the implementations of the Dataset interface.

Moved to the common Dataset interface in 8, which might be why it’s not working. @jparsons, are you working with a dataset returned from a history query, by chance?

Hmm no I am in 7.9. I am pulling from a table, the table is tied to tag history though.

The basic idea of what I am doing is I am trying to pull data from a specific time period defined by the user, I am then reorganizing all of those data points from high to low and displaying that on a chart.

The way I am accomplishing this right now is using a date range to get the date defined by the user and pulling tag history for that time period into a table. I am then using property change script on the date range block to reorganize the data.

So a very long-winded answer to your question. Yes, I am kind of using tag history. Not a SQL query, not sure which one you are asking about.