Ruben Posted June 2, 2019 Share Posted June 2, 2019 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 Link to comment Share on other sites More sharing options...
Thorsten Vogt Posted June 3, 2019 Share Posted June 3, 2019 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. 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 Link to comment Share on other sites More sharing options...
Seeq Team Kjell Raemdonck Posted September 11, 2020 Seeq Team Share Posted September 11, 2020 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. Link to comment Share on other sites More sharing options...
nurhazx Posted October 19, 2022 Share Posted October 19, 2022 How to customize timestamp format, if I want to display like this "20 April 2022"? Link to comment Share on other sites More sharing options...
Seeq Team Sharlinda Salim Posted October 19, 2022 Seeq Team Share Posted October 19, 2022 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. Link to comment Share on other sites More sharing options...
nurhazx Posted October 19, 2022 Share Posted October 19, 2022 (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 October 19, 2022 by nurhazx Link to comment Share on other sites More sharing options...
Seeq Team Sharlinda Salim Posted October 19, 2022 Seeq Team Share Posted October 19, 2022 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. Link to comment Share on other sites More sharing options...
nurhazx Posted October 19, 2022 Share Posted October 19, 2022 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 I want to change the date format Link to comment Share on other sites More sharing options...
Seeq Team Sharlinda Salim Posted October 19, 2022 Seeq Team Share Posted October 19, 2022 (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 Hope this helps. Edited October 19, 2022 by Sharlinda Salim Link to comment Share on other sites More sharing options...
nurhazx Posted October 19, 2022 Share Posted October 19, 2022 Yups, it works. Many thanks Sharlinda😄 Link to comment Share on other sites More sharing options...
Super Seeqer Shamus Cunningham Posted October 25, 2022 Super Seeqer Share Posted October 25, 2022 A newer and simpler method for this using the Table view and conditions is linked below Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now