Jump to content

Is there a way to pass in extra signal when using spy.pull calculation


Sivaji
Go to solution Solved by Thorsten Vogt,

Recommended Posts

I'm using spy.pull to pull the data however I need to resample the signal based on another signal before I pull the data. I see pushing the resampled signal and pulling is an alternative option, I was wondering if there is a way to pass in another signal in the 'calculation' since I've to repeat this for a lot of signals. 

image.png.b3387e217577a96124961193e9d6f2cb.png

 

for the above code, for 'calculation' I've to use '$signal.resample($signalKeySource)'  . I've SEEQ ID for the $signalKeySource, not sure how can I reference this in the 'calculation'. There is something like formula parameters for spy.push, not sure about the equivalent in spy.pull.

Link to comment
Share on other sites

  • Solution

Hi Sivaji,

I don't think it is possible to add another signal to the calculation argument. One way would be pushing new signals that do the resampling to Seeq and pulling the data as you mentioned. Another way might be using the API instead. The following code runs a formula and transforms the result into a DataFrame. The results of the run_formula method must be parsed to a dictionary, as the datatype of each entry is of type seeq.sdk.models.sample_output_v1.SampleOutputV1.

from seeq import sdk
import pandas as pd

signal1_id = "A925A450-CCF2-43E5-8342-0623DD650270"
signal2_id = "3A7B47C8-A45D-4615-9758-B93A8136AF0F"

apiClient = spy.client
formulasApi = sdk.FormulasApi(apiClient)
result = formulasApi.run_formula(start = "2024-07-01T00:00:00Z", end = "2024-07-02T00:00:00Z", formula = "$signal1.resample($signal2)", parameters = [f"signal1={signal1_id}", f"signal2={signal2_id}"])

dict_list = [entry.to_dict() for entry in result.samples.samples]

df = pd.DataFrame(dict_list)

df['key'] = pd.to_datetime(df['key'], unit='ns', utc=True)
df.set_index('key', inplace=True)

df.drop(columns=['is_uncertain'], inplace=True)

Nevertheless, I think the preferred way would be creating signals in Seeq that do the resampling and pull the values from these signals.

An example of creating calculated items in Seeq can be found here:

Regards,

Thorsten

  • Like 1
Link to comment
Share on other sites

Hi Sivaji,

you can either change the limit parameter in the run_formula function to a higher value or use a contination token to run subsequent queries on the data:

from seeq import sdk
import pandas as pd

signal1_id = "A925A450-CCF2-43E5-8342-0623DD650270"
signal2_id = "3A7B47C8-A45D-4615-9758-B93A8136AF0F"

apiClient = spy.client
formulasApi = sdk.FormulasApi(apiClient)
token = ''
while True:
    result = formulasApi.run_formula(start = "2024-06-01T23:00:00Z", end = "2024-07-02T00:00:00Z", formula = "$signal1.resample($signal2)", parameters = [f"signal1={signal1_id}", f"signal2={signal2_id}"], continuation_token = token)

    dict_list = [entry.to_dict() for entry in result.samples.samples]

    if (token == ''):
        df = pd.DataFrame(dict_list)
    else:
        df = pd.concat([df,pd.DataFrame(dict_list)])
        
    token = result.samples.continuation_token
    
    if token == None:
        break

df['key'] = pd.to_datetime(df['key'], unit='ns', utc=True)
df.set_index('key', inplace=True)

df.drop(columns=['is_uncertain'], inplace=True)

Regards,

Thorsten

  • Like 1
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...