Jump to content

spy.pull() calculation over a fixed time period


Francesco

Recommended Posts

I am trying to apply the function totalized() when pulling data in Seeq Datalab. 

I want to apply the totalized() function over some data pulled between 6/6/2023 10:00 AM and 6/7/2023 10:00 AM. I am trying to use "$signal.totalized($capsule)" as the calculation parameter but I do no know how to specify the capsule. I was not expecting the need to specify the capsule since I am already defining the start and end time in pull().

Here is my code:


my_data = spy.pull(items = my_signals,
                   start = '6/6/2023 10:00 AM',
                   end   = '6/7/2023 10:00 AM',
                   calculation = "$signal.totalized()",
                   grid  = None
                  )

Of course it returns an error:

image.thumb.png.81c5895c338a52cd52d0122f57e0c69c.png

I had the same issue when trying to apply the average() formula. What should I do?

Thank you!

Link to comment
Share on other sites

  • Seeq Team

Hi Francesco,

When you use a calculation in a spy.pull, the calculation string needs to be something you can do in Seeq Formula and it can only reference the individual item being pulled. Based on this, if you look in the formula documentation for totalized, you can see that there's an example similar to your formula, but it is actually:

$signal.totalized($capsule)

Seeq doesn't know that you want the start and end to be the $capsule so you need to tell it that. For example, changing to this calculation instead should work:

$signal.totalized(capsule('2023-06-06T10:00Z', '2023-06-07T10:00Z'))

 

Link to comment
Share on other sites

Hello Joe, thank you for the answer.

In the end the following lines of code worked for me:

my_data = spy.pull(items = my_signals,
                   start = '6/6/2023 10:00 AM',
                   end   = '6/7/2023 10:00 AM',
                   calculation = "$signal.aggregate(totalized(), condition(capsule('2023-06-06T10:00Z', '2023-06-07T10:00Z')), startKey())",
                   grid  = None
                  )

This is the result:

image.png.c74ded13c107d3ee69d29252da16e498.png

 

On the other hand, your solution returned me the following error:

image.png.56bf0512b6f3cf4650836129c5de5579.png

Link to comment
Share on other sites

  • Seeq Team

The option Joe suggested gave that error because the calculation changed the return type of the item, which spy.pull isn't expecting. You're passing in a signal to the spy.pull call, while the result of 

$signal.totalized(capsule('2023-06-06T10:00Z', '2023-06-07T10:00Z'))

Is a scalar, which causes the error here. You could get around that by adding a toSignal() at the end to ensure the formula returns the same type as the input. By default, toSignal() will return a sample every day, which is fine in your case since your search window is a day.

$signal.totalized(capsule('2023-06-06T10:00Z', '2023-06-07T10:00Z')).toSignal()
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...