Skip to content

[sc-241566] Add ElementName column to attribute search #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: feature/sc-241416-allow-maxCount-tuning
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python-connectors/pi-system_attribute-search/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def generate_rows(self, dataset_schema=None, dataset_partitioning=None,
):
if limit.is_reached():
return
output_row = format_output(row, attribute, is_enumeration_value=is_enumeration_value)
output_row = format_output(
row, attribute,
is_enumeration_value=is_enumeration_value
)
yield output_row
else:
for row in self.client.search_attributes(
Expand Down
2 changes: 2 additions & 0 deletions python-lib/osisoft_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class OSIsoftConstants(object):
{"name": "Name", "type": "string"},
{"name": "Description", "type": "string"},
{"name": "Path", "type": "string"},
{"name": "ElementName", "type": "string"},
{"name": "Type", "type": "string"},
{"name": "TypeQualifier", "type": "string"},
{"name": "DefaultUnitsName", "type": "string"},
Expand All @@ -284,6 +285,7 @@ class OSIsoftConstants(object):
{"name": "Name", "type": "string"},
{"name": "Description", "type": "string"},
{"name": "Path", "type": "string"},
{"name": "ElementName", "type": "string"},
{"name": "Timestamp", "type": "date"},
{"name": "Value", "type": "string"},
{"name": "Value_ID", "type": "string"},
Expand Down
15 changes: 15 additions & 0 deletions python-lib/osisoft_plugin_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ def format_output(input_row, reference_row=None, is_enumeration_value=False):
if type_column:
reference_row["Type"] = type_column
output_row.update(reference_row)
if "Path" in output_row:
output_row["ElementName"] = get_element_name_from_path(output_row.get("Path"))
return output_row


Expand Down Expand Up @@ -495,6 +497,19 @@ def change_key_in_dict(input_dictionary, key_to_change, new_key_name):
return input_dictionary


def get_element_name_from_path(path):
# input: \\osisoft-pi-serv\Well\Assets\TX532|Current
# output: TX532
if not path:
return None
element_name = None
path_tokens = path.split("\\")
if len(path_tokens) > 0:
last_token = path_tokens[-1:][0]
element_name = last_token.split("|")[0]
return element_name


class RecordsLimit():
def __init__(self, records_limit=-1):
self.has_no_limit = (records_limit == -1)
Expand Down
10 changes: 9 additions & 1 deletion tests/python/unit/test_osisoft_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from osisoft_client import format_output_row
from osisoft_plugin_common import is_child_attribute_path
from osisoft_plugin_common import is_child_attribute_path, get_element_name_from_path


class TestCommonMethods:
Expand Down Expand Up @@ -31,3 +31,11 @@ def test_is_child_attribute_path(self):
assert is_child_attribute
is_child_attribute = is_child_attribute_path(self.path_to_element)
assert not is_child_attribute

def test_get_element_name_from_path(self):
assert get_element_name_from_path("\\osisoft-pi-serv\\Well\\Assets\\TX532|Current") == 'TX532'
assert get_element_name_from_path("\\osisoft-pi-serv\\Well\\Assets\\TX532") == 'TX532'
assert get_element_name_from_path("TX532") == 'TX532'
assert get_element_name_from_path("") is None
assert get_element_name_from_path("|mknnkn") == ""
assert get_element_name_from_path("\\something\\|mknnkn") == ""