I have this script that takes in a dataset (of tag pens from an easy chart) and replaces the storage provider portion of the path and places the resulting dataset in a different dataset property.
It seems like the script is working just fine, but the resulting dataset property never changes.
I'm triggering the script when the window the easy chart is on is opened and using a tag change script on a custom property on the component.
The component also has 2 custom dataset properties 'edge' and 'master'.
onVisionWindowOpened
:
#setting windowOpened to 1 allows tag change script on the pens datasets to run
system.gui.getParentWindow(event).getComponentForPath('Root Container.Pens').windowOpened = 1
propertyChange
:
#property change script used to update the derived 'edge' dataset from the 'master' dataset
#make changes to the master dataset and they will popuplate to the edge set automatically
#root container will detect if this is the master or edge gateway and use the appropriate dataset
if event.source.parent.edge :
Trending.penCopy_MasterToEdge(event,1)
area_providers = [
{0 : "[MySQL/ignition-desktop-av4v6h5:"},
{1: "[Edge Historian/"},
{8: "[Edge Historian/"},
{10: "[Edge Historian/"},
{15: "[Edge Historian/"},
{19: "[Edge Historian/"},
]
def penCopy_MasterToEdge(event, area):
#copy pens from master dataset to edge dataset when window is opened
if event.propertyName == 'windowOpened' and event.newValue == 1:
Trending.logger.info('Area '+str(area)+' Trending window opened.')
#get historical path for replacement
histRootPath = Trending.getHistoryProvider(area)
Trending.logger.info('Historical root path is '+histRootPath+'.')
#get master pens dataset
data_master = event.source.master
penData_master = system.dataset.toPyDataSet(data_master)
#get headers for the dataset
headers = list(data_master.getColumnNames())
#initialize an empty list
penData_edge = []
#get the index for the tag path column
TAG_PATH_index = data_master.getColumnIndex('TAG_PATH')
#for each row in master data
for row in penData_master:
#create new blank row as a list
new_row = list(row)
#update the "area_xx" portion of the tag path to match the area for the tag provider
new_row[TAG_PATH_index] = row['TAG_PATH'].replace(Trending.area_providers[0][0],histRootPath)
#append the new row to the list
penData_edge.append(new_row)
Trending.logger.info('Sample row from new dataset: '+str(penData_edge[0]))
#create dataset from list and assign to edge dataset property
event.source.edge = system.dataset.toDataSet(headers, penData_edge)
#reset windowOpened to 0 so that this can run again the next time the window is opened.
event.source.windowOpened = 0
def getHistoryProvider(tagProvider = None):
if tagProvider is None:
area = system.tag.readBlocking(['Areas/Station_Area'])[0].value
else:
area = tagProvider
for provider in Trending.area_providers:
if area in provider:
return str(provider[area])
return Trending.area_providers[0][0]
My logs seem to indicate that the replace is working as intended and the dataset should be correct, but the 'edge' dataset on the component still looks like a duplicate of the 'master'.
logs:
14:45:12.790 [AWT-EventQueue-0] INFO Trending - Area 1 Trending window opened.
14:45:12.794 [AWT-EventQueue-0] INFO Trending - Historical root path is [Edge Historian/.
14:45:12.799 [AWT-EventQueue-0] INFO Trending - Sample row from new dataset: [u'Runtime', u'[Edge Historian/area_01]pumps_motors/01111-inf/runtime/total/runtime_total', u'MinMax', u'Default Axis', 1, False, java.awt.Color[r=188,g=129,b=67], u'', 0, 1.0, 0, True, False, u'Pump 1', False, False, False, True, None, False]
What am I missing?