# Creating a Signal for a Running Count of Capsules

## Recommended Posts

• Seeq Team

FAQ:

I've created a condition for a particular event of interest and now I would like to create a signal that is the running count of these events in a given time period.

This analysis is common in equipment fatigue use cases when equipment degrades slowly based on a number of cycles (thermal, pressure, tension, etc) that it has undergone during it's life or since a last component replacement.

Solution:

We can convert each of these capsules into a signal comprised of a single sample (with value of 1) per capsule, then take a running sum of this new signal over the current equipment life condition.

1) Use Formula to create a signal with a constant value of 1 and a sample every 1 second.

`(1).toSignal(1sec)`

2) Use Signal from Condition to create a new signal with a single sample of value 1 per capsule. Take the average of the "1 signal" during each of the event capsules.

3) Use Formula to calculate the running sum of the 1 sample per capsule signal during the Current Equipment Life capsule.

`\$OneSamplePerCapsule.runningSum(\$CurrentLife).toLinear(7d)`

##### Share on other sites

• 2 years later...
• Seeq Team

There is another approach to this solution that I thought would be good to share, as it is a bit less involved.

The assumptions for the below solution are:

1. You have a condition (\$condition) of interest that you would like to understand the running count for
2. There is a defined timeframe of interest, where counting will start and end. Note the end date can be sometime in the future. For the below example, this condition is referenced as \$manualCondition, but could very well be another condition that wasn't created via the Manual Condition tool. Just note that for each capsule in this condition, the count will restart at 0.

Solution - Utilize the runningCount() formula function:

1) runningCount() currently only accepts signals as inputs, so convert your \$condition to a signal by using .toSignal(), which produces a single sample for each capsule:

`\$condition.toSignal(SAMPLE_PLACEMENT)`

SAMPLE_PLACEMENT should be specified as startKey(), middleKey(), or endKey(). If you want your count to increase at the start of each event, then use startKey(). If wanting the count to increase in the middle or end of each event, then use middleKey() or endKey()

2) Use the runningCount() function on the signal created above.

`\$signal.runningCount(\$conditionToStartAndEndCounting)`

Both steps are shown below in a unified Formula:

```/*
This portion yields a SINGLE point for each capsule.
startKey() generates the point at the START of each capsule,
where middleKey() and endKey() could also be used to generate
a point at the MIDDLE or END of each capsule. Where these points
are placed matter, as that is the point in time the count will
increase.
*/
\$samplePerCapsule = \$condition.toSignal(startKey())

/*
This portion yields the running count of each sample (capsule).
The 15d in toStep() can be adjusted. Ideally this number will be
the duration of the longest expected time between two events that
are being counted.
*/
\$samplePerCapsule.runningCount(\$manualCondition).toStep(15d)```

.toStep(15d) ensures the output signal is step interpolated, interpolating points at most 15 days apart. If step interpolation is not required, then this can be removed or replaced with something like .toLinear(15d). Below shows the associated output.

## Create an account

Register a new account