From 3b89202b059116b8fe4eead8eaf2555d42525090 Mon Sep 17 00:00:00 2001 From: James Higgie Date: Wed, 20 Dec 2023 10:19:08 +1100 Subject: [PATCH 1/3] Fix import error and add utility functions --- .../correlation/_seeq_worksheet_writer.py | 19 ++++++++++++++++--- seeq/addons/correlation/utils/__init__.py | 4 ++-- seeq/addons/correlation/utils/_common.py | 9 +++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/seeq/addons/correlation/_seeq_worksheet_writer.py b/seeq/addons/correlation/_seeq_worksheet_writer.py index 6a5ab6b..4726c07 100644 --- a/seeq/addons/correlation/_seeq_worksheet_writer.py +++ b/seeq/addons/correlation/_seeq_worksheet_writer.py @@ -1,10 +1,11 @@ import warnings import pandas as pd import pickle +import re from IPython import display from IPython.core.display import HTML from seeq import spy, sdk -from .utils import create_condition, create_workstep_signals, get_seeq_url +from .utils import create_condition, create_workstep_signals, get_seeq_url, path_list_to_string, path_string_to_list from . import default_preprocessing_wrapper from . import lags_coeffs, signals_from_formula @@ -37,7 +38,7 @@ def create_lagged_signals(signal_ids, signal_names, workbook_id, time_shifts, ti lagged_signals.extend([signalId, r.data_id]) else: lagged_signals.append(r.data_id) - + print(lagged_signals) return lagged_signals @@ -47,6 +48,17 @@ def get_existing_worksheet(workbook_id, worksheet_id, api_client): worksheet_id=worksheet_id) # type: sdk.WorksheetOutputV1 return existing_worksheet +def create_analysis_search_query(workbook) -> tuple[dict[str, str], str]: + workbook_spec_parts = path_string_to_list(workbook) + search_query = dict() + if len(workbook_spec_parts) > 1: + search_query['Path'] = path_list_to_string(workbook_spec_parts[0:-1]) + workbook_name = workbook_spec_parts[-1] + else: + workbook_name = workbook_spec_parts[0] + search_query['Name'] = f'/^{re.escape(workbook_name)}$/' + search_query['Workbook Type'] = 'Analysis' + return search_query, workbook_name def get_workbook(workbook, worksheet, datasource): if workbook is None: @@ -66,7 +78,7 @@ def get_workbook(workbook, worksheet, datasource): }]), include_inventory=False, quiet=True)[0] else: - search_query, workbook_name = spy._push.create_analysis_search_query(workbook) + search_query, workbook_name = create_analysis_search_query(workbook) search_df = spy.workbooks.search(search_query, quiet=True) if len(search_df) == 0: primary_workbook = spy.workbooks.Analysis({'Name': workbook_name}) @@ -207,6 +219,7 @@ def worksheet_corrs_and_time_shifts(signal_pairs_ids: list, workbook_id: str, workbook_id, worksheet_id = get_workbook(workbook_id, worksheet_name, datasource) existing_worksheet = get_existing_worksheet(workbook_id, worksheet_id, api_client) + create_workstep_signals(existing_worksheet, workbook_id, all_new_signals, diff --git a/seeq/addons/correlation/utils/__init__.py b/seeq/addons/correlation/utils/__init__.py index ce383f3..54ff43d 100644 --- a/seeq/addons/correlation/utils/__init__.py +++ b/seeq/addons/correlation/utils/__init__.py @@ -1,4 +1,4 @@ -from ._common import validate_argument_types, print_red +from ._common import validate_argument_types, print_red, path_list_to_string, path_string_to_list from ._cache_management import clear_cache_all from ._permissions import get_user, get_user_group from ._sdl import pull_only_signals, get_worksheet_url, get_workbook_worksheet_workstep_ids, get_seeq_url @@ -7,4 +7,4 @@ __all__ = ['validate_argument_types', 'print_red', 'create_condition', 'create_workstep_signals', 'get_user', 'get_user_group', 'pull_only_signals', 'get_worksheet_url', 'get_workbook_worksheet_workstep_ids', - 'clear_cache_all', 'get_seeq_url'] + 'clear_cache_all', 'get_seeq_url', 'path_list_to_string', 'path_string_to_list'] diff --git a/seeq/addons/correlation/utils/_common.py b/seeq/addons/correlation/utils/_common.py index b0161b2..ae8f43a 100644 --- a/seeq/addons/correlation/utils/_common.py +++ b/seeq/addons/correlation/utils/_common.py @@ -1,3 +1,5 @@ +import re + def validate_argument_types(expected_types): for _value, _name, _types in expected_types: if _value is None: @@ -16,3 +18,10 @@ def validate_argument_types(expected_types): def print_red(text): print(f"\x1b[31m{text}\x1b[0m") + + +def path_list_to_string(path_list): + return ' >> '.join(path_list) + +def path_string_to_list(path_string): + return re.split(r'\s*>>\s*', path_string.strip()) \ No newline at end of file From 791cbddcf6d78582cb830a5cddd5c161bb7983ee Mon Sep 17 00:00:00 2001 From: James Higgie Date: Wed, 20 Dec 2023 10:28:12 +1100 Subject: [PATCH 2/3] tweak --- seeq/addons/correlation/_seeq_worksheet_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seeq/addons/correlation/_seeq_worksheet_writer.py b/seeq/addons/correlation/_seeq_worksheet_writer.py index 4726c07..044a4cb 100644 --- a/seeq/addons/correlation/_seeq_worksheet_writer.py +++ b/seeq/addons/correlation/_seeq_worksheet_writer.py @@ -48,7 +48,7 @@ def get_existing_worksheet(workbook_id, worksheet_id, api_client): worksheet_id=worksheet_id) # type: sdk.WorksheetOutputV1 return existing_worksheet -def create_analysis_search_query(workbook) -> tuple[dict[str, str], str]: +def create_analysis_search_query(workbook): workbook_spec_parts = path_string_to_list(workbook) search_query = dict() if len(workbook_spec_parts) > 1: From a7b520d269efb8ce4dece8dc13ea336bc58469cb Mon Sep 17 00:00:00 2001 From: James Higgie Date: Thu, 21 Dec 2023 19:45:42 +1100 Subject: [PATCH 3/3] remove print --- seeq/addons/correlation/_seeq_worksheet_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seeq/addons/correlation/_seeq_worksheet_writer.py b/seeq/addons/correlation/_seeq_worksheet_writer.py index 044a4cb..6ffc142 100644 --- a/seeq/addons/correlation/_seeq_worksheet_writer.py +++ b/seeq/addons/correlation/_seeq_worksheet_writer.py @@ -38,7 +38,7 @@ def create_lagged_signals(signal_ids, signal_names, workbook_id, time_shifts, ti lagged_signals.extend([signalId, r.data_id]) else: lagged_signals.append(r.data_id) - print(lagged_signals) + return lagged_signals