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([], [[]])