7 Replies Latest reply on Apr 9, 2014 11:54 PM by skwan

    Need to Calculate How Many Times a Digital Tag Changes State Excluding Duplicates

    jmarches

      Hi,

       

      I need to calculate how many times a digital tag changes states in a 24 hour timeframe and write the results to an AF attribute. I cant use the PE EventCount method because it doesnt filter out duplicate values (back to back events that contain the same value). I built a custom application using the AF SDK but that seems like overkill for such a simple task.I also considered writing a custom AF data reference, but I would need it to evaluate periodically - approx once an hour (I'm not sure if custom data references are capable of periodic analysis). Does anyone have any recommedations? I'm looking for a simple solution to a simple problem. Thanks!

        • Re: Need to Calculate How Many Times a Digital Tag Changes State Excluding Duplicates
          mhalhead

          Hi John,

           

          [Quote user="John Marchesino"]I cant use the PE EventCount method because it doesnt filter out duplicate values (back to back events that contain the same value).

          You can use the compression settings on the output tag to remove the duplicates. Setting compressing to true with a compdevpercentage = 0 will prevent the storage of duplicate; just watch the compmax setting by default PI will log a value every 28800 (i.e 8 hours).

           

          I'm assuming the duplicates are on the output. If the duplicate is on the input you can use the previous event function.

           

          A totalizer would probably be a more robust (sometimes) way of achieving this desired effect (at least my guess). You would have to use the filter parameter to exclude duplicate inputs; I believe that you can use the previous event function in a totalizer filter.

            • Re: Need to Calculate How Many Times a Digital Tag Changes State Excluding Duplicates
              Warren Armstrong

              Hi John

               

              The totalizers filter can not access the archive, archive calls do not work. so previous value (PrevVal) in the filter will cause an error.

               

              There is however a setting for counting when the values change  - you would have to test to get the settings correct.

               

              A data reference will not fire every hour unless you call it from a service every hour.

               

              your case sounds like a perfect candidate for the AF analytics, available for download from yesterday. This will run on a schedule and you can run performance equations expressions with it, you should be able to get a filter into it.

               

              Another option is to put the raw tag into a performance equation, that only records the changes. You Can then build a simple totalizer off this PE, or use a simple count in the PI Point data reference.

               

              Warren

                • Re: Need to Calculate How Many Times a Digital Tag Changes State Excluding Duplicates
                  skwan

                  John:

                   

                  You mentioned you want to store the result as an AF attribute.  What is the reasoning for that and not a PI point to preserve history?  A related question - what will you use to visual the result(s)?

                    • Re: Need to Calculate How Many Times a Digital Tag Changes State Excluding Duplicates
                      jmarches

                      Warren,

                       

                      I will focus on your suggestion regarding AF Analytics since this is my preferred option at the moment.  I already tried to make this work using the beta version of AF Analytics. Like Performance Equations, I was not able to come up with a graceful solution that filters out back to back duplicate events. AF Analytics has an EventCount function but it behaves just like the PE EventCount function – it can’t be configured to ignore duplicates (to OSIsoft: I recommend adding a parameter to the EventCount function to make it ignore duplicates).

                       

                      I can use the following logic to record a change in status each time a new value is inserted:

                       

                      If 'STATUS' <> PrevVal('STATUS', PrevEvent('STATUS', '*')) Then 'NO OF SWITCHES 24 HRS' + 1

                       

                      However, this would result in a continuous total. I’m only interested in knowing how many times the state changed in the last 24 hours (or last 72 hours).

                       

                      You mentioned that AF Analytics should be able to filter. Can you please elaborate? I really appreciate your assistance.

                       

                      Michael,

                       

                      In response to the comment related to compression settings. I don’t have any control over the tag compression and exception attributes so I have to make do with the current settings.

                       

                      Steve,

                       

                      Thanks for your inquiry. I'm choosing to use an AF attribute because we dont need to preserve history on many times the status tag changed in a 24 timeframe. Part of the requirement is to trigger an alert if the status tag changes state more than 4 times the past 24 hours. I have another similar requirement to send an alert if a capacitor doesnt change at all in the past 72 hours. I was planning on using a "24 hour count"  Attribute and a AF "72 hour count" attribute as my trigger condition. We also want to visualize the 72 and 24 hour count, possibly in DataLink or Coresight.

                        • Re: Need to Calculate How Many Times a Digital Tag Changes State Excluding Duplicates

                          You can use the continuous total on the "NO OF SWITCHES"   and then have your trigger logic such as:

                           

                          ( 'NO OF SWITCHES' - TagVal('NO OF SWITCHES','*-24h')) > 4

                            • Re: Need to Calculate How Many Times a Digital Tag Changes State Excluding Duplicates
                              jmarches

                              This would work but I would need to create a PI tag to store the number of switches. My plan was to just store the number of switches in an AF Attribute. The attribute value would contain the number of switches that took place within the past 24 hours and it would be updated every hour. However, I could make this AF Attribute a PI data reference that writes data to PI whenever its updated. I was trying not to store this information in PI, but I may need to. Thanks for the advice!

                                • Re: Need to Calculate How Many Times a Digital Tag Changes State Excluding Duplicates
                                  skwan

                                  John:

                                   

                                  If you store the result as an AF attribute, you need to be careful.  For example, an AF attribute really doesn't have a calculation timestamp.  One reason I asked earlier what client application you will use to view the result(s) is because you need to be absolutely sure your users are viewing the correct results.  For example, if your users are using PI System Explorer to view the results, they would have to ensure they refresh immediately prior to view the most up to date results.  Admittedly you would have to do the same with a PI Point DR but at least with a PI Point DR, you can show the timestamp in PSE to aid the user.  In addition, you can't trend a plain AF attribute where as you can trend a PI Point DR.  My recommendation is for you to seriously consider storing the results as a PI Point.