False Appears after I add into a new subplot

Hello all!

To give some clarification as to what is going on. My easy chart graph’s legend’s appear normal for one tag pen while the other has ‘false/’ in front of the other tag pen. I was wondering if anyone knew why this was happening and know how to fix this issue? My script dynamically allows for a user to keep adding other tags to trend at different subplots. This ‘false/’ tends to appear when I try to add a trend into another subplot instead of the first one.

You will need to provide your script. Appears that you are writing a boolean value as a string into the tag name in the script somewhere.

I would start by looking at the route which is taken in the script when a subplot is added.

1 Like
def get_tag_name_from_metadata(tagpath):
	site_path = "/".join(tagpath.split("]")[-1].split("/")[:3])
	equip_path = tagpath.split("/")[-2]
	tagname = tagpath.split("/")[-1]
	sql = """
		SELECT xsn.Site_Name, xen.Equip_Name, xen.Product
		FROM XEC_Site_Navigation xsn 
		LEFT JOIN XEC_Equipment_Navigation xen on xen.Site_Id = xsn.Site_Id
		WHERE xsn.Tagpath = ? and xen.Tagpath = ?
	"""
	data = system.db.runPrepQuery(sql, [site_path, equip_path], "SQL_SCADA_Admin")
	if system.tag.exists(tagpath + ".Documentation"):
		documentation = system.tag.read(tagpath + ".Documentation")
		documentation = documentation.value
	else:
		documentation = tagname
	if str(documentation) == "":
		documentation = tagname
	if len(data) > 0:
		tag = data[0]
	else:
		return '-'.join(tagpath.split('/')[1:])
			
				
				
	if tag["Product"]:
		if self.getComponent('CheckBox 2').selected:
			name = "%s - %s %s - %s" % (tag["Site_Name"], tag["Equip_Name"], tag["Product"], documentation)
		else:
			name = "%s %s - %s" % (tag["Equip_Name"], tag["Product"], documentation)
	else:
		if self.getComponent('CheckBox 2').selected:
			name = "%s - %s - %s" % (tag["Site_Name"], tag["Equip_Name"], documentation)
		else:
			name = "%s - %s" % (tag["Equip_Name"], documentation)

Starting at line 34, this is where I output the names of the tags for the legends. This was working fine before. It wasn’t until I started to add trends to different subplots that the string ‘false/’ appears. I’ve been trying to modify this but I’m still not getting rid of that portion.

1 Like

I see you wrote a funciton inside the configChart funciton, which is fine, but you are going to have to show your wohle code which includes how you call get_tag_name_from_metadata as there’s a good chance the parameter you are putting into the function is the culprit or culprit-adjacent.

Also don’t show screen shots of your code, use
image
to format copy/pasted code or
or three backticks
```

if something:
    do()

```
to format blocks of code.

It’s not just a legibility thing, but being able to copy/paste your code helps people here to help you debug the issue.

1 Like

I edited the previous post to have my code be copy/pasted. Thank you for the advice!
Also is there a way to find the original source of where that function was created (get_tag_name_from_metadata)? I am new to the project and I have trouble trying to find the source of user-defined functions for me to edit.

The function is defined inside of the configChart function, so it is unique to that scope. It must be called from within configure chart, other wise it isn’t being called at all (which seems unlikely).

If you can, post the entirety of the configChart function.

1 Like

def configChart(self):

def get_tag_name_from_metadata(tagpath):
	site_path = "/".join(tagpath.split("]")[-1].split("/")[:3])
	equip_path = tagpath.split("/")[-2]
	tagname = tagpath.split("/")[-1]
	sql = """
		SELECT xsn.Site_Name, xen.Equip_Name, xen.Product
		FROM XEC_Site_Navigation xsn 
		LEFT JOIN XEC_Equipment_Navigation xen on xen.Site_Id = xsn.Site_Id
		WHERE xsn.Tagpath = ? and xen.Tagpath = ?
	"""
	data = system.db.runPrepQuery(sql, [site_path, equip_path], "SQL_SCADA_Admin")
	if system.tag.exists(tagpath + ".Documentation"):
		documentation = system.tag.read(tagpath + ".Documentation")
		documentation = documentation.value
	else:
		documentation = tagname
	if str(documentation) == "":
		documentation = tagname
	if len(data) > 0:
		tag = data[0]
	else:
		return '-'.join(tagpath.split('/')[1:])

	if tag["Product"]:
		if self.getComponent('CheckBox 2').selected:
			name = "%s - %s %s - %s" % (tag["Site_Name"], tag["Equip_Name"], tag["Product"], documentation)
		else:
			name = "%s %s - %s" % (tag["Equip_Name"], tag["Product"], documentation)
	else:
		if self.getComponent('CheckBox 2').selected:
			name = "%s - %s - %s" % (tag["Site_Name"], tag["Equip_Name"], documentation)
		else:
			name = "%s - %s" % (tag["Equip_Name"], documentation)
			
	#print(documentation)
	return name

easy_chart = self.getComponent('MultitrendChart')

headers = 	["NAME","TAG_PATH","AGGREGATION_MODE","AXIS","SUBPLOT","ENABLED","COLOR","DASH_PATTERN","RENDER_STYLE","LINE_WEIGHT","SHAPE","FILL_SHAPE","LABELS","GROUP_NAME","DIGITAL","OVERRIDE_AUTOCOLOR","HIDDEN","USER_SELECTABLE","SORT_ORDER","USER_REMOVABLE"]
check = self.getComponent('CheckBox').selected
#checkFacility = self.getComponent('CheckBox 2').selected
#tag_pens = [x for x in system.dataset.toPyDataSet(easy_chart.tagPens)]
existing_pens = []
axes = []
temp = system.dataset.toPyDataSet(self.tagpens)
tag_pens_ds = system.dataset.toPyDataSet(easy_chart.tagPens)
engUnits = []
iterate = 0
numbers = []
tag_pens = []
for row in tag_pens_ds:
	new_row = []

	for x in headers:
		if check and x == "AXIS":
			new_row.append(row["TAG_PATH"])
			axes.append([row["TAG_PATH"], system.tag.getAttribute(row["TAG_PATH"], 'EngUnit'), "Numeric","#000000","#000000","#000000","0","false",'true', "false","0.05","0","100","true","5","5","","normal", '','false','#000000','#000000'])
			numbers.append(iterate)
			engUnits.append(system.tag.getAttribute(row["TAG_PATH"], 'EngUnit'))
			iterate = iterate + 1
			#unitValue = system.tag.getAttribute(row["TAG_PATH"], 'EngUnit')
			#print(unitValue)
		elif x == "NAME":
			name = get_tag_name_from_metadata(row["TAG_PATH"])
			new_row.append(name)
		else:
			new_row.append(row[x])


	tag_pens.append(new_row)
	#print(system.tag.getAttribute(new_row["TAG_PATH"], 'EngUnit'))
	
unitHeaders = ['Values', 'Label']
engUnitsDS = system.dataset.toDataSet(unitHeaders, [list(pair) for pair in enumerate(engUnits)])
dropdown = self.getComponent('Dropdown')
dropdown.data = engUnitsDS


axes_data = easy_chart.axes
axes_columns = system.dataset.getColumnHeaders(axes_data)
axestag = ''
axesunit = ''
#axes = [['tag', 'doc', "Numeric","#000000","#000000","#000000","0","false",'true', "false","0.05","0","100","true","5","5","","normal", '','false','#000000','#000000']]
data = self.new_tags
py_data_set = system.dataset.toPyDataSet(data)
for row in py_data_set:
	existing_pens.append(row['tag'])
	axestag = row['tag']
	axesunit = system.tag.getAttribute(axestag, 'EngUnit')
axes.append([axestag, axesunit, "Numeric","#000000","#000000","#000000","0","false",'true', "false","0.05","0","100","true","5","5","","normal", '','false','#000000','#000000'])	

#colors = ['#00aedb', '#a200ff', '#f47835', '#d41243', '#8ec127', '#CC6600', '#009933', '#FF5050']
colors = ['#191970', '#ff0000', '#006400', '#ffd700', '#00ff00', '#00ffff', '#ff00ff', '#ffb6c1']
#colors = [ Color.getHSBColor((h*0.25751810740024195) * h % 1, s/100.0, l/100.0) for s in [50, 75, 100] for h in range(0,100) for l in [50, 75] ]
color_index = len(tag_pens)
for row in existing_pens:
	name = get_tag_name_from_metadata(row)
	color = colors[color_index % len(colors)]
	color_index += 1
	unit = system.tag.getAttribute(row, 'EngUnit')
	#doc = system.tag.getAttribute(row, 'Documentation')
	#if not doc:
	doc = '-'.join(row.split('/')[1:])
	#tag_pens.append([row.replace('devices/', ''), row, 'MinMax', row, 1, 1, color, '', 1, 1.0, 0, 1, '', 0, 0, 0])
	parts = row.split('/')
	#dv = parts[1] + ' - ' + doc
	dv = doc
	#dv = parts[2] + ' - ' + parts[len(parts) - 2] + " " + doc
	tag_pens.append([name, str(row), 'LastValue', str(row), "1", "1", color, '', "1", "1.0", "0", "1", "0", '', "0","0", "0", "1","","1"])
	if check:
		axes.append([row, unit, "Numeric","#000000","#000000","#000000","0","false",'true', "false","1","1","100","true","5","5","","normal",'','false','#000000','#000000'])

axesHeaders = ["NAME","LABEL","TYPE","LABEL_COLOR","TICK_LABEL_COLOR","TICK_MARK_COLOR","POSITION", 'INVERT', "AUTO_RANGE","AUTO_RANGE_INCL_ZERO","AUTO_RANGE_MARGIN","LOWER_BOUND","UPPER_BOUND","AUTO_TICK_UNITS","TICK_UNIT","GRID_UNIT","NUMBER_FORMAT","LOG_LABEL_STYLE", 
																'SYMBOL_STRING', 'GRID_BANDS_VISIBLE', 'GRID_BAND_COLOR', 'GRID_BAND_ALTERNATE_COLOR']
headers = ["NAME","TAG_PATH","AGGREGATION_MODE","AXIS","SUBPLOT","ENABLED","COLOR","DASH_PATTERN","RENDER_STYLE","LINE_WEIGHT","SHAPE","FILL_SHAPE","LABELS","GROUP_NAME","DIGITAL","OVERRIDE_AUTOCOLOR","HIDDEN","USER_SELECTABLE","SORT_ORDER","USER_REMOVABLE"]
#print(tag_pens)
new_data = system.dataset.toDataSet(headers, tag_pens)



easy_chart.tagPens = new_data
#print(easy_chart.tagPens)
easy_chart.axes = system.dataset.toDataSet(axes_columns, axes)
trend_tags = system.dataset.toPyDataSet(self.trend_tags)
trend_tags_py_data = []
for row in trend_tags:
	#for col in row:
	trend_tags_py_data.append([row['tag']])
#print(trend_tags_py_data)
for row in py_data_set:
	trend_tags_py_data.append([row['tag']])
#print(trend_tags_py_data)
self.trend_tags = system.dataset.toDataSet(['tag'], trend_tags_py_data)
#print(self.trend_tags_py_data)
self.new_tags = system.dataset.toDataSet([], [[]])
#add new tags to trend_tags
self.loadedTags = system.dataset.toDataSet([], [[]])

@lrose @bkarabinchak.psi
Here is the whole function of configChart() which includes the other function. Please let me know if there was anything else I can do. I would also like to thank you both for taking the time to read and help me out, I really really appreciate it!

Okay, so looks like the easy chart has a custom property on it which is called on this line:

data = self.new_tags

Looks like it is of type dataset. How is that property filled (e.g. binding, other script, etc…)

From what I can tell, the tagPath parameter in get_tag_name_from_metadata() is a row from this dataset.

1 Like

image

Currently, these are the Custom Properties for the Easy Chart. It appears to not be bound to anything. The image below shows the other Custom Properties for the window.

Most likely it is filled by some script on another component, perhaps where the user selects or adds tags?

1 Like

I will try to see where “new_tags” is being called from and how its being populated. This will take some time as I will need to be going through a lot of components and scripts. I will update with anything new that I come across, thank you so so much @lrose !!