tip Creating a Signal for a Running Count of Capsules

Recommended Posts

As a Seeq user, you may have created a condition for a particular event of interest and would like to create a signal that is the running count of these events over 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.

This use case can be done very efficiently in Seeq Formula. 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.

Content Verified DEC2023

Edited by John Cox
Updating to best solution
• 1