Jump to content

Recommended Posts

Posted

Hi - I am wanting to get a time value for the last sample in a signal. What is the formula for this?

I am using it to create a 24hr average from the last value in a signal, and have this updating as the signal is updated. the now() function takes the current time, not the last sample time.

Any advice? Thanks

Posted

Hi Ruben, 

you can do it by using this formula. The formula gets the values for the last eight hours, picks the last sample and gets its key (timestamp). Based on that timestamp the condition of the previous 24 hours is build.

image.png.220596862e149f8bac6641bcca52d3e8.png

You can also use pick(-1) instead of last(). You should keep in mind that the capsule itself is uncertain because of the use of now().

Regards,

Thorsten

 

  • 1 year later...
  • Seeq Team
Posted

Post below documents how you could pull the last sample's timestamp into a Scorecard - in case all you wanted was to just view that timestamp.

Enter the following into a new Formula:

//In this formula, we will create a signal of all the timestamps for each sample point coming into Seeq

//Create a condition with tiny capsules for each sample point
// NOTE - to the get the accurate timezone date/time, I need to delay my signal according to my UTC-6h adjustment for Mountain timezone
//        if you are in Central for instance, you would do UTC-5h, or .delay(-5h)
$sampleCapsules = $signal.delay(-6h).toCapsules()

//Find the timestamp of each recorded sample point
// NOTE - you may need to change the 1d to a larger value, as this is the interpolation length
//        so if your samples are spaced by more than 1d, increase to 2d and see if this interpolates
$sampleCapsules.toSignal('End').toLinear(1d).toString()

//Below transform is Optional to view the timestamp in a neater format of MM/DD/YYYY HH:MM
  .replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , 
           '${month}/${day}/${year} ${hour}:${minute}')

Then, in a new Scorecard Metric, grab the Value at End. Every time you return to Seeq, you can "step to now" and get the latest timestamp for the last sample, corrected for your timezone per the delay above. 

image.png

 

  • 2 years later...
  • Seeq Team
Posted

Hi Nurhaz,

The easiest will be to configure at the header. In this example, I used Simple Table >> Last Value, followed by customizing the header as showed in the second screenshot. If you click at the '?' beside the Date Format it will provide you more formatting options. Finally, you can add another column and name it 'Last Sample Time".

This method is applicable still if you prefer to use Scorecard Metric.

The difference between this method and the one discussed above is this method will generate the last value too.

image.png

image.png

image.png

Posted (edited)

Oh sorry, my mistake. I mean this formula.

//Below transform is Optional to view the timestamp in a neater format of MM/DD/YYYY HH:MM
  .replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , 
           '${month}/${day}/${year} ${hour}:${minute}')

I want to show the scorecard value as a date "20 April 2022" like this.

Edited by nurhazx
  • Seeq Team
Posted

Yes, understood but it will not be straightforward though thus I recommended formatting the header. Can you please let me know the background of your use case? It it still in the context you would like to display the time of the last value? If yes, may I know why you do not prefer to configure the header.

Posted

I created scorecard when the signal reach high alarm.

$f=($signal < $alarm).afterStart(1s)

$f.toSignal('End').toLinear(1d).toString()
.replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , 
           '${month}-${day}-${year} ${hour}:${minute}')

 

The value comes out like this

image.png.ae1e1946a10311547ba2a9c70dcc634c.png

I want to change the date format

  • Seeq Team
Posted (edited)

Hi Nurhaz,

This is one possible method:-

Step 1 : Create a new formula where we convert the month format based on your preference

$month_numeric = 

$f
.toSignal('End')
.toString()
.replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , 
          '${month}')

//changing the name format

$month_alphabet =

experimental_lookupTable(
"[
 ['01', 'Jan'],
 ['02', 'Feb'],
 ['03', 'March'],
 ['04', 'April'],
 ['05', 'May'],
 ['06', 'June'],
 ['07', 'July'],
 ['08', 'August'],
 ['09', 'September'],
 ['10', 'October'],
 ['11', 'November'],
 ['12', 'December']  
 ]",
InterpolationMethod.Discrete)
$month_alphabet.experimental_lookup($month_numeric, 'B')

Step 2 : Configure the sequence/format based on your preference

$extract = $f.toSignal('End').toString()

$day = $extract
       .replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , 
                '${day}')



$YYYYhhmm = $extract
            .replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , 
                    '${year} ${hour}:${minute}')



$final = $day + ' ' +$month_alphabet+ ' ' +$YYYYhhmm
return $final

image.png

Hope this helps.

Edited by Sharlinda Salim

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