Jump to content

Merging to the end of a day


Go to solution Solved by John Cox,

Recommended Posts

So I have code that I am trying to merge when there are more than one sensor tests in a day, but when I try and limit the merge to the end of the day with a periodic condition created, it doesn't take it as merge doesn't like merging based off of other capsules, though that's what I would like for it to merge off of as it is the time period I want for each day. Here's the code and I can show what I want with a quick fix that's only foolproof to the point of shorter periods of time but doesn't cover sensor test late in the day.

 

//When there is more than one test per day, finding the time between those tests as 
//potential downtime to be safe.
//Count Sensor Tests per day
$testsPerDay = $sta.aggregate(count(),days('US/Eastern'),durationkey())

//Only include tests if more than 1x per day
$repeatTests = $sta.inside($testsPerDay > 1)

// Create a condition for each day
//$days = days('US/Eastern')

// Join all events together 
$mergeIt = $repeatTests.afterend(0ns).merge(24h)

$mergeIt

Below is what is created currently with this code.

image.png.87bff27a97107a802ac1c3d481fddfbd.png

But what I want is this below which I can achieve as a quick fix by changing the merge hours to 12h instead, which makes it pick up what I want. I want to only make capsules that include the sensor test and the time between those capsules. If there are more than 2 capsules, it'll capture from the first one in the day to the last one in the day, even if it's the 28th one. The reason I can't leave it at 12h is because the first CDT that occurs doesn't trigger a capsule to be created drifts over time. This means that capsule, during one part of the year may be happening at 6am instead of around 7am, where it is now.

image.png.f30bd2e0437d7bb007d0fea2d04052fc.png

This is what I want it to look like.

In this last picture below I have the daily interval you can see in the main two pics that I want the merge function to follow to.

image.png.2f769827ac047bc0f69baea0900341a3.png
Thanks for the help and hopefully this isn't super confusing.

Link to comment
Share on other sites

  • Seeq Team
  • Solution

Hello,

I'm not certain I understand exactly what you want, but I think you want to merge all the time between the first and last sensor test on each daily time period, but only on days where there are 2 or more tests. 

If this is what you want, please give this formula a try:

$days = days('US/Eastern')

//When there is more than one test per day, finding the time between those tests as 
//potential downtime to be safe.
//Count Sensor Tests per day
$testsPerDay = $sta.aggregate(count(),$days,durationkey())

//Only include tests if more than 1x per day
$repeatTests = $sta.inside($testsPerDay > 1)

// Find the first test on multiple test days

$FirstTestEachDay = $days.transform($w ->
  $repeatTests.toGroup($w).first())

// Find the last test on multiple test days

$LastTestEachDay = $days.transform($w ->
  $repeatTests.toGroup($w).last())

// Join the first and last tests

$FirstTestEachDay.join($LastTestEachDay, 24h, false)

 

  • Like 1
Link to comment
Share on other sites

Posted (edited)

Hey John,

That's what I wanted. I'm at what the $w variable is for but I see it's used in transform as an example. Would you or anyone else if they want be able to explain?

I'll be looking into using transform when I can now as I hadn't seen that approach yet. 

Thank you.

Edited by ANHammann
Didn't like what I had before.
Link to comment
Share on other sites

  • Seeq Team

You are welcome!

Yes, I can explain the $w variable in the transform. It is a variable name that the user chooses to represent the "capsules" in the condition to the left of .transform. You can think of the .transform as a way to "loop" over all the capsules in the condition to the left of .transform (which in this case is our daily condition, so we loop through all of those daily 24 hour capsules and do some additional logic). 

I could have chosen any valid variable name I want in place of $w. For example I could have done this and it would work just as well:

$FirstTestEachDay = $days.transform($daycapsule ->
  $repeatTests.toGroup($daycapsule).first())

In summary, we use the .transform to go individually through all the capsules in the daily condition. We convert all the $repeatTests capsules into a group of capsules for each individual day. After we have converted them to a group, we can then do things like pick the first or last capsule in the group. The overall result of the .transform is a set of capsules (one capsule for each day there were repeated tests, and no capsules on days without repeated tests) that make up our $FirstTestEachDay condition. 

Hope this helps!

Link to comment
Share on other sites

Thank you John! It has helped me understand that better. 

I will say I had to change the first() and last() functions to pick(1) and pick(-1) respectively as capsules being created were saying they were missing data when they really weren't and were going crazy not wanting to load as quick. It still has the notification that there is no data for the pick(-1) function, but the capsules are showing in full color and not just the outlines from not having enough data.

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