Jump to content

spy.search() and regex


Go to solution Solved by Tayyab,

Recommended Posts

Posted (edited)

I'm trying to use the below to search a workbook for the conditions off of a list. The returned list is empty.

for x in conditions_found:
    alerts = spy.search({
        'Type': 'CalculatedCondition',
        'Name': f'/{x}$/'
    }, workbook=workbook_id, limit=None)
    all_conditions = all_conditions.append(alerts, ignore_index=True)

The resulting shows this:

Query successful
  Type Name Time Count Pages Result
0 CalculatedCondition /Time Average Step Change (B-C)$/ 00:00:00.23 0 1 Success

 

If I remove the regex and just do f'{x}' it works correctly. The documentation says that this format should be the same as what's done in the search bar in workbench. /{Time Average Step Change (B-C)}$/ works correctly in workbench.

My seeq version is 62.0.17 and seeq-spy 192.22 and running this locally on VS code instead of datalab

Edited by Tayyab
Link to comment
Share on other sites

  • Seeq Team

 

Hi Tayyab,

I am able to use regex within a spy search. Here's two example scripts that use the Example dataset that you can test.  

Example using a for loop with a list.

from seeq import spy
import pandas as pd
import re

search_results = spy.search(
    {
        'Name': '/^Area [A-H]_Temperature$/', 
        'Type': 'Signal', 
        'Datasource Name': 'Example Data'
    }
)

signal_list = search_results['Name'].tolist()

all_conditions = pd.DataFrame()

for x in signal_list:
    # Search for conditions related to the current signal name
    alerts = spy.search({
        'Name': f'/^{x}$/'
    }, limit=None)
    # Concatenate the search results to the all_conditions DataFrame
    all_conditions = pd.concat([all_conditions, alerts], ignore_index=True)
    
all_conditions

Example using a dataframe for the search parameters instead of a list.

from seeq import spy
import pandas as pd
import re

x= 'Area [A-H]_Temperature'
search_results = spy.search(
    {
        'Name': f'/^{x}$/', 
        'Type': 'Signal', 
        'Datasource Name': 'Example Data'
    }
)

signal_list = search_results['Name'].tolist()

search_df = pd.DataFrame({
    'Name': signal_list
})

all_conditions = spy.search(search_df)
    
all_conditions

Hope this helps.

Chris

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...