Skip to content

Commit 1a41935

Browse files
committed
[sc-241566] Add ElementName column to attribute search
1 parent ecde671 commit 1a41935

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

python-connectors/pi-system_attribute-search/connector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def generate_rows(self, dataset_schema=None, dataset_partitioning=None,
121121
):
122122
if limit.is_reached():
123123
return
124-
output_row = format_output(row, attribute, is_enumeration_value=is_enumeration_value)
124+
output_row = format_output(
125+
row, attribute,
126+
is_enumeration_value=is_enumeration_value,
127+
add_element_name=True
128+
)
125129
yield output_row
126130
else:
127131
for row in self.client.search_attributes(
@@ -134,7 +138,7 @@ def generate_rows(self, dataset_schema=None, dataset_partitioning=None,
134138
if is_child_attribute_path(path):
135139
continue
136140
remove_unwanted_columns(row)
137-
output_row = format_output(row)
141+
output_row = format_output(row, add_element_name=True)
138142
yield output_row
139143
end_time = datetime.datetime.now()
140144
duration = end_time - start_time

python-lib/osisoft_constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class OSIsoftConstants(object):
259259
{"name": "Name", "type": "string"},
260260
{"name": "Description", "type": "string"},
261261
{"name": "Path", "type": "string"},
262+
{"name": "ElementName", "type": "string"},
262263
{"name": "Type", "type": "string"},
263264
{"name": "TypeQualifier", "type": "string"},
264265
{"name": "DefaultUnitsName", "type": "string"},
@@ -284,6 +285,7 @@ class OSIsoftConstants(object):
284285
{"name": "Name", "type": "string"},
285286
{"name": "Description", "type": "string"},
286287
{"name": "Path", "type": "string"},
288+
{"name": "ElementName", "type": "string"},
287289
{"name": "Timestamp", "type": "date"},
288290
{"name": "Value", "type": "string"},
289291
{"name": "Value_ID", "type": "string"},

python-lib/osisoft_plugin_common.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def remove_unwanted_columns(row):
278278
row.pop(unwated_column, None)
279279

280280

281-
def format_output(input_row, reference_row=None, is_enumeration_value=False):
281+
def format_output(input_row, reference_row=None, is_enumeration_value=False, add_element_name=False):
282282
output_row = copy.deepcopy(input_row)
283283
type_column = None
284284
if "Value" in output_row and isinstance(output_row.get("Value"), dict):
@@ -299,6 +299,8 @@ def format_output(input_row, reference_row=None, is_enumeration_value=False):
299299
if type_column:
300300
reference_row["Type"] = type_column
301301
output_row.update(reference_row)
302+
if add_element_name and "Path" in output_row:
303+
output_row["ElementName"] = get_element_name_from_path(output_row.get("Path"))
302304
return output_row
303305

304306

@@ -495,6 +497,19 @@ def change_key_in_dict(input_dictionary, key_to_change, new_key_name):
495497
return input_dictionary
496498

497499

500+
def get_element_name_from_path(path):
501+
# input: \\osisoft-pi-serv\Well\Assets\TX532|Current
502+
# output: TX532
503+
if not path:
504+
return None
505+
element_name = None
506+
path_tokens = path.split("\\")
507+
if len(path_tokens) > 0:
508+
last_token = path_tokens[-1:][0]
509+
element_name = last_token.split("|")[0]
510+
return element_name
511+
512+
498513
class RecordsLimit():
499514
def __init__(self, records_limit=-1):
500515
self.has_no_limit = (records_limit == -1)

0 commit comments

Comments
 (0)