I have a client requesting the ability to add/remove set categories of tags on the Power Chart, I have a rough working method where I browse for all the tags of that type depending on the site selected, and append the JSON object with "name" and "source" parameterized using substrings from the tag paths. See below for code:
basePath = self.session.custom.basePath
pens = []
ambTemp = system.tag.browse(basePath, {'name':'AMBIENT_TEMP*', 'tagType':'AtomicTag', 'recursive': True})
for pyr in ambTemp:
name = str(pyr['fullPath'])[38:]
source = str(pyr['fullPath'])[5:]
#ignore the weird quality check for now
#was trying to find a way of creating pens for tags with Bad quality without breaking the chart
if str(pyr['value'].quality).find("Bad_") == -1:
if str(pyr['value'].quality).find("Good") != -1:
pens.append(
{
"name": name,
"visible": True,
"enabled": True,
"selectable": True,
"axis": "Axis 1",
"plot": 0,
"display": {
"type": "line",
"interpolation": "curveLinear",
"breakLine": True,
"radius": 3,
"styles": {
"normal": {
"stroke": {
"color": "#DE7E41",
"width": 1,
"opacity": 0.8,
"dashArray": 0
},
"fill": {
"color": "#DE7E41",
"opacity": 0.8
}
},
"highlighted": {
"stroke": {
"color": "#DE7E41",
"width": 1,
"opacity": 1,
"dashArray": 0
},
"fill": {
"color": "#DE7E41",
"opacity": 1
}
},
"selected": {
"stroke": {
"color": "#DE7E41",
"width": 1,
"opacity": 1,
"dashArray": 0
},
"fill": {
"color": "#DE7E41",
"opacity": 1
}
},
"muted": {
"stroke": {
"color": "#DE7E41",
"width": 1,
"opacity": 0.4,
"dashArray": 0
},
"fill": {
"color": "#DE7E41",
"opacity": 0.4
}
}
}
},
"data": {
"source": "histprov:Stellar_ROC:/drv:default:default:/tag:HISTORIAN/Stellar_ROC/"+source,
"aggregateMode": "Average"
}
}
)
self.parent.parent.getChild("PowerChart").props.pens = pens
Basically I have an onActionPerformed event on a button that will fire the tag browse, fill in the list with array objects, and set the chart's Pens property to that list of arrays. If I weren't building this out for multiple sites I'd just set custom properties with static lists and have that be that but it has to handle dynamic sets of tags. My problem right now is there are some categories that are returning 100+ results and looping through for all of that is really slow.
I'm wondering if there's a way to maybe store these lists of arrays to a set of memory tags in each site's tag folder and just have the button event set the chart's pens property equal to the tag? Or if there's an altogether better way to approach this whole thing.