8 Replies Latest reply on Jun 5, 2018 1:41 PM by Terpstrj

    Calculate time difference between 2 events.

    Terpstrj

      Hi all,

       

      I hope someone could help me.

      I have an event tag that stores who is logged in/out in a system and I want to show all results of people who are logged in for more than 8 hours on the same node.

      Can this be retrieved from this tag??

       

      Example: entries in the tag

      28-mei-18 08:54:43  ||USER1  logged in |NODE_A|

      28-mei-18 09:54:43  ||USER1  logged in |NODE_B|

      28-mei-18 10:54:43  ||USER1  logged out |NODE_B|

      28-mei-18 09:54:43  ||USER2  logged in |NODE_B|

      28-mei-18 17:54:43  ||USER1  logged out |NODE_A|

      28-mei-18 21:54:43  ||USER2  logged out |NODE_B|

       

      Desired Result:

      28-mei-18 08:54:43  ||USER1  logged in |NODE_A|

      28-mei-18 09:54:43  ||USER2  logged in |NODE_B|

      28-mei-18 17:54:43  ||USER1  logged out |NODE_A|

      28-mei-18 21:54:43  ||USER2  logged out |NODE_B|

       

      I'm really struggeling to create an filter expression  for this.

      I hope that people can point me in the right direction or else tell me that this isn't possible, because that is also an anwer of course

       

      Thanks in advance.

       

      Jorgen

        • Re: Calculate time difference between 2 events.
          rzandvliet

          I think  you can use AF and Event-frames to do this. Create an AFTemplate: user.

          The template includes an analysis that checks if a user logs on or off. An event-frame represents the time the user has been logged on to the specific node. 

          • Re: Calculate time difference between 2 events.
            John Messinger

            Hi Jorgen,

             

            Robert Zandvliet has made a good suggestion with using Event Frames. My question to you is, how do you intend to consume the information you have filtered from this data? Whilst EF would be a good way to capture the logon session for each user, the resulting event frames may not be the best provider of whatever the output is that you need.

              • Re: Calculate time difference between 2 events.
                rzandvliet

                John Messinger with PI DataLink you should be able to retrieve the starttime (login), endtime (logout), duration of session (endtime-starttime). This is also possible via the AF SDK.

                  • Re: Calculate time difference between 2 events.
                    John Messinger

                    Indeed you can, and PI DataLink would be the obvious choice for this kind of reporting. However if the OP plans to consume this information through a non-EF aware application (PI ProcessBook for example), then event frames won't be of any help. My question still stands - no mention was made in the original post of how this information will be consumed, and so while I agree that Event Frames appears to be a good solution for this problem, there is a possibility that the intended usage of this data requires an alternative method of producing the session information.

                    1 of 1 people found this helpful
                      • Re: Calculate time difference between 2 events.
                        Terpstrj

                        Hi all thanks for all your repsonses and helping me to find to a solution. I'm sorry I was not clear in the way I want to use it later.

                         

                        As I understand from Robert Zandvliet we could use an AF but as I'm not fimiliar with AF analytics this poses a bit of challenge for me as I have never done this. Although this would not stop me if this is the only solution/way so I want to thank also Rhys Kirk for his example.

                        But for me an output in excel via PI datalink would be more than sufficient. In a later stage I will going to use it in a RtReports template from which I generate a search over a period of app 3 months. ( that is the end goal). I just want to determine which users where logged on for a long time and on which node and at what time they did this. It is to find out if accounts are being missused.

                        CouldRhys Kirk solution also be put in a filter expression?  Or can this only be done by AF?

                        I was looking into the fiter expression but the problem that I have is that I can find the events with an Instr instruction but the big issue to by looking back in time and find the other event.
                        Normally I use something like Instr('tag',"logged out") OR Instr('tag',"logged in") and this results in the output

                        28-mei-18 08:54:43  ||USER1  logged in |NODE_A|

                        28-mei-18 09:54:43  ||USER1  logged in |NODE_B|

                        28-mei-18 10:54:43  ||USER1  logged out |NODE_B|

                        28-mei-18 09:54:43  ||USER2  logged in |NODE_B|

                        28-mei-18 17:54:43  ||USER1  logged out |NODE_A|

                        28-mei-18 21:54:43  ||USER2  logged out |NODE_B|

                         

                         

                        And now the next step to find/fiter out the corresponding other event that I do not have a clue for. At least not with a filter expression.

                          • Re: Calculate time difference between 2 events.
                            John Messinger

                            Hi Jorgen,

                             

                            The solution that Rhys offered couldn't really be translated to a single PI filter expression. The nice thing about this type of approach in AF Analysis is that you can break the filter up into multiple steps, and access these intermediate variables in later calculation steps to get to the final result.

                             

                            You could probably use a combination of Excel functions with a PI expression filter to get a similar result in Excel, but that way feels kind of clunky to me.

                             

                            As you indicated that the long term goal is to present this information via RtReports, then the original option of capturing this information via Event Frames would probably be the best choice, as you can consume Event Frame data in RtReports.

                            1 of 1 people found this helpful
                    • Re: Calculate time difference between 2 events.
                      Rhys Kirk

                      Perfectly possible through pure AF Analytics...then you choose how you wanted to report it out.

                      I've taken your example literally...here is something that works. You could do what you want with the output, strip the user and/or node, or just report the time of the event and lookup the event tag with the data in it.

                       

                      Your analysis trigger would be driven by the Event tag you have, and you would be looking for logged out events.

                       

                      2 of 2 people found this helpful