I would like to remove all the data from the value list except for the value itself. What I tried didn't work due to the BasicQualifiedValue object being unscriptable. Any ideas on how to do this differently that would work? Thank you so much in advance!
# script builder. You may modify this script, but if you do,
# you will not be able to use the navigation builder to update
# this script without overwriting your changes.
data = system.tag.browse("[default]DataMemory")
headers = data.getResults()
keys_to_keep = ["name","value"]
filtered_list = [
{key: dct[key] for key in keys_to_keep}
for dct in headers
]
for dictionary in filtered_list:
for key, value_list in dictionary.iteritems():
dictionary[key] = [value_list[0].value]
print(filtered_list)
I feel like you're making things way more complicated than they actually are.
I'd propose an alternative, but I can't even figure out what you're trying to do !
Can you give me an example of input and expected output ?
Lets say I have three tags: Pressure, Temperature, Flow Rate. Each of them have their own value. I want to collect those tags and their values, and then make the names of the tags the header for a dataset, and make the values the data for a dataset. I want to then save this dataset as a new dataset type tag. I just want the value itself from the tag though, not the tag quality and timestamp that come with it.
# script builder. You may modify this script, but if you do,
# you will not be able to use the navigation builder to update
# this script without overwriting your changes.
data = system.tag.browse("[default]DataMemory")
headers = data.getResults()
print (headers)
keys_to_keep = ["name","value"]
filtered_list = [
{key: dct[key] for key in keys_to_keep}
for dct in headers
]
new_data = []
for item in filtered_list:
modified_item = {"name": item["name"], "value": item["value"].value}
new_data.append(modified_item)
newlod = [{d['name']: d['value']} for d in new_data]
headers, data = zip(*[d.items()[0] for d in newlod])
ds = system.dataset.toDataSet(headers, [data])
print(ds)
event.source.parent.getComponent('Power Table').data = ds
Realizing now though that when you send the dataset to a tag, its no longer a type '<type 'com.inductiveautomation.ignition.common.BasicDataset'>', its now a <type 'java.util.ArrayList'> so I am unsure what to do.
You already have the tags, why does this dataset need to be a tag as well?
Just build the dataset at point of use.
paths = ['path/to/tag1','path/to/tag2','path/to/tag3']
tagValues = [qv.v for qv in system.tag.readBlocking(paths)]
headers = [path.split('/')[-1:] for path in paths]
ds = system.dataset.toDataSet(headers,[tagValues])
Because I have them generating from two different buttons, so have to be able to store the first dataset in a tag. Also because I will need to convert each dataset back into a list of dicts at some point later.