7 Replies Latest reply on Apr 19, 2018 1:01 PM by Rick Davin

    AF monthly Event Frames

    thomas.kretschmer

      Hi everyone,

       

      I'm new in AF and I have a first use case in my Company:

       

      I wand to calculate a summary of a flow rate PI-Tag over a month. The values sould be stored in a second Tag at every first day of a month.

      Example :

      01.01.2018 00:00 - 01.02.2018 00:00 TagTot( FlowRate01x ) --> FlowRate02

      01.02.2018 00:00 - 01.03.201800:00  TagTot( FlowRate01x ) --> FlowRate02

      ...

       

      I tried to use the Analyses in AF for this but I didn't found a solution that works... So, can someone tell me how I can build this? Should I use Event Frames for this? Or is there a better way?

       

      Thank you very much in advanced!

        • Re: AF monthly Event Frames
          mamyrand

          hello Thomas,

          can you please be more explicit on your question?

          For now, Tagtot('myflowtag','starttime','endtime') returns the volume between the specified range time.

          You just need to consider the flow uom.

          If m3/h, and your time range is about 2 days then you need to multiply by 24 since one day is 24 hours.

          regards,

          Mamy

           

          .

            • Re: AF monthly Event Frames
              thomas.kretschmer

              Mamy,

              thanks for the fast Response!

               

              The idea is to have a calculation in AF to build a sum of the hole month and store the result in another Tag:

              TagTot( 'FlowRate01', 'beginning of month', 'end of month') this calculation should run automatically at the beginning of every month and I want to store the result in another Tag.

               

               

               

              To me the main question is:

              How can I Trigger the calculation at the beginning of every month and how can I configure a dynamic scope (start time and end time) for the function?

                • Re: AF monthly Event Frames
                  mamyrand

                  Hello Thomas, referring to Rick post.

                  Just a remark, might be right might be wrong.

                  setting

                  StartTime ='y'

                  and

                  EndTime=Bom('y')

                  Assuming that the calculation will start at every first of the month

                  regards,

                  Mamy

                    • Re: AF monthly Event Frames
                      Rick Davin

                      Hi Mamy,

                       

                      Your times are wrong.  In the context of an analysis, '*' does not necessarily mean now, but rather means trigger time, which is a critical distinction when backfilling.  BOM('*') when run on the first of the month returns the first of the month set at midnight.  However, 'y' truly means yesterday.  For the start time, I offset that yet again by 24 hours, as shown by '+24h' to denote a time span, rather than 1 day, which could also have been used.  Doesn't matter because when you BOM that, it sets to the first of previous month, also at midnight.  That means my time range is correct from the first of the previous month (relative to trigger) to the full end of that month (first of trigger month at midnight - no need to offset by -1 second).  Your suggested changes are from the first of the last month up to the beginning of the last day of month. Coming up on May 1, your time range effectively covers only 29 days of April.

                        • Re: AF monthly Event Frames
                          mamyrand

                          Hello Rick,

                          I’m afraid, I don’t see my mistake on this.

                          Your explanation might clarify.

                          Below is the shot screen from PI AF Explorer editor.

                           

                          From this next 1 of May 2018 at 5AM

                           

                          (‘y’)        would returns 30/04/2018 12:00:00 AM

                          Bom(‘y’) would returns 01/04/2018 12:00:00 AM

                           

                          I Think you are right in your post, my mine might be just another option.

                           

                           

                           

                          Regards,

                          Mamy.

                            • Re: AF monthly Event Frames
                              Rick Davin

                              No, Mamy, yours is wrong.  A monthly summary should include ALL of April 30.  You stop 1 day short.  The time needs to extend through END of day April 30, which is the equivalent of May 1 at midnight, although you may jump through more hoops to make it 30/04/2018 11:59:59 PM.

                               

                              And again your code only works when the trigger time is Now, but it will not work with backfilling.

                    • Re: AF monthly Event Frames
                      Rick Davin

                      Hi Thomas,

                       

                      I would not recommend an event frame.  I suggest using an Asset Analysis that writes to your second tag.  The analysis should be periodically scheduled, and perhaps should be executed every day at some fixed time, such as 4 or 5 AM.  You should avoid anytime that lies around DST transition so as to avoid any ambiguity.  Typing free-form at my keyboard (not within Analytics editor), it would be something like:

                       

                      IsBOM     Day('*') = 1

                      EndTime    BOM('*')

                      StartTime     BOM('*' - '+24h')

                      summary     If IsBOM Then your summary here Else NoOutput()

                       

                      This addresses your earlier question of  How can I Trigger the calculation at the beginning of every month and how can I configure a dynamic scope (start time and end time) for the function?  You really can't set a trigger for the beginning of the month given the pesky details that some months have 31 days while others have only 30, and don't get me started on February.  By triggering every day, you are sure to hit the first of the month eventually.  You also restrict the calculating as well as outputting the results to only the day that is indeed the first of the month.  The psuedo-code I posted also dynamically scopes the previous month's time range for you.

                      2 of 2 people found this helpful