Jump to content

Creating a period condition based on signal value


Ali

Recommended Posts

Hello, 

I have a signal that presents the total rolling downtime duration for 1 week every 3 hours. I'm trying to extract each value from the signal and create a condition such that each capsule has the same duration of the extracted value. I would usually use periods(1week,3h) if I have a constant value of one week duration.

The intent here  is to create a condition to calculate a rolling average of a signal based on a unit downtime values. 

Thanks

  • Like 1
Link to comment
Share on other sites

  • Administrators

Hello Ali,

The following formula should allow you to convert your duration signal into a condition.

$signal.transformToCapsules(
  $sample -> capsule(
    $sample.getKey()-$sample.getValue(), 
    $sample.getKey()), 
  3 weeks)

Below is a screen shot of the formula tool setup.

Capture.PNG

Let me know if this gets you what you want.

Teddy

  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...

My Question matches the title of this post, but is a little different. I have a signal that is a counter (increments by 1 every time a product is made). The signal/tag value resets when it reaches 32000. I want to create a period condition that is every 5000 logs. So the time of each capsule may be different but the delta of my signal from start to end of each capsule is 5000, except for the instances where a reset occurs during the capsule when the delta will appear to be -27000.

Edited by Jules
Link to comment
Share on other sites

Hi Jules,

as I do not know your data I created an example based on the sample data generated within Seeq. Therefore I created a sawtooth signal resetting every 60 days. So you may have to do adjustments to that solution.

.image.png.5ddf1d4bef4dd493f7061fa4c591a8f3.png

First step was transforming this to a continous signal using formula:

$values.runningDelta().max(1).runningAggregate(sum(),years()).toLinear()

More details can be found in this post from @Allison Buenemann:

image.png.9d773fe2df4faead9f7ec5eb9d282fca.png

Last step is creating a condition that contains exactly 5000 samples:

(($continousValues-($continousValues / 5000).floor()).runningDelta() == 0) // -> create capsules when counter % 5000 == 0
.growEnd(1y) // -> grow capsule to start of the next capsule
.transform($c -> $c.setProperty('Values', $continousValues.count($c))) // -> create capsule property containing the count of samples inside the capsule

image.thumb.png.5565429c53633ff5c5f93c3101232556.png

Hope this helps.

Regards,

Thorsten

  • Thanks 1
Link to comment
Share on other sites

Can you go through some of the theory of your formula so I can understand how to apply it to my data? 

When I use the above formula my capsules are various counts (3000 to 16000). My tag has a highly variable rate of change which I believe is the reason for my various counts. 

Link to comment
Share on other sites

Hi Jules,

I guess converting your sawtooth signal to a continous one should work, so I modified the last formula a little bit:

(($continousValues / 5000)-($continousValues / 5000).floor() == 0) // -> create capsules when continous signal can be divided by 5000
.growEnd(1y) // -> grow capsule to start of the next capsule
.transform($c ->{
 $c.setProperty('Values', $continousValues.count($c))  // -> create capsule property containing the count of samples inside the capsule
  .setProperty('ValueStart', $continousValues.getValue($c.getStart())) // -> create capsule property containing the value at start of the capsule
.setProperty('ValueEnd', $continousValues.getValue($c.getEnd())) // -> create capsule property containing the value at end of the capsule
}) 

The first part of the formula creates a capsule each time the value of the signal can be divided by 5000 (0, 5000, 10000, 15000, ...). These capsules are very short in duration, but can be extended to the start of the next capsule using grow(). The last part just adds some properties to the capsules used to validate the formula . Result should look like this:

image.png.08e90ec49f616647958ffbce6fb96a1d.png

You may notice that the number of values is sometimes greater than 5000. I think this may occur because it counts the number of samples. If the value in the Historian does not change it may create another sample with the same value anyway. I guess the better values to check are the values at start and end of the capsule, which always can be divided by 5000.

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...