4 Replies Latest reply on Oct 22, 2013 1:13 PM by Darren.Metcalfe

    Running total of tags

    Darren.Metcalfe

      Hi, PI Newbie here!!

       

      I'm trying various methods to calculate the running total of numerous tags from current time to 30 days previous (the dates are changed to reflect 24 hours, 30 days 365 days etc)

       

      So far I'm using;

       

      tagtot('tagname','*-30d','*')

       

      The start time is set as *-30d and the end time is set as current *.

       

      Would this be the recommended method or is there an alternative?. The raw data the tags are reading contains electrical readings at 15 minute intervals and are received per hour.

       

      The results I'm receiving seem to be providing an average over the last 30 days rather than a total?

       


      Any help would be greatly appreciated

       

       

        • Re: Running total of tags
          xwang

          Hi Darren,

           

          I believe tagtot you used should be from PI PE function.  However, in the description of this function in PEReference, it says this function is used to "Find the totalized value (time integral) of a point over a given time, according to values stored in the Archive."  The red words, time integral, in the description means this function used time-weighted way to calculate total.  If you need the event-weighted way to do the calculation, PI SDK / AF SDK function should be considered.  Please see the help menu of PI SDK.  The function is under PI DATA part named as Summary method

           

          Please see the following code as the reference:

           

           

           
          PISDK.PISDK pi_sdk = new PISDK.PISDK();
                      Server pi_server = pi_sdk.Servers["WIN-01ARJPPGTEJ"];
                      PIPoint point = pi_server.PIPoints["cdt158"];
                      PITimeFormat start_time = new PITimeFormat();
                      start_time.InputString = "*-30d";
                      PITimeFormat end_time = new PITimeFormat();
                      end_time.InputString = "*";
                      PIValue value = point.Data.Summary(start_time, end_time, ArchiveSummaryTypeConstants.astTotal, CalculationBasisConstants.cbEventWeighted);
          

           Xi Wang

           

          v-Campus team

            • Re: Running total of tags
              hanyong

              Hi Darren,

               

              As Xi mentioned, the tagtot() function is really finding the time integral value for the given time range based on the values stored in the archive for the tag. In layman's term, it is finding the area under the graph. So you want to consider for your total calculation, would time-weighted total be appropriate, or it is better to use an event-weighted total.

               

              Xi gave a code snippet that will get event-weighted total in PI SDK. But If you are looking for something in PE syntax that will give that, there isn't a PE function that does that directly. You can do something like tagmean('tagname', '*-30d', '*') * eventcount('tagname', '*-30d', '*') instead

               

              tagmean() function calculates the mean of the tag's value (in another words, the event weighted average), and multiplying it by count of events will give the total.

               

              Another thing that you want to take note for time-weighted total calculation is conversion factor. Without the appropriate conversion factor setting, time-weighted total calculation results from tagtot function may give the wrong result. What this does and why we need to consider a conversion factor is explained in this video on our youtube learning channel. 

            • Re: Running total of tags
              ChrisDaycock

              Darren,

               

               This is from the help file,

               

              Usage Note

               

              The system chooses a scale factor such that the integral will be correct only if the flow is expressed in units per day. If the flow is expressed in units per hour, or per some other time unit, you must multiply this result by a conversion factor. The conversion factor equals the number of actual flow time units in a day.

               

              For instance, if you totalize a point measured in gallons per minute, you must multiply the result of TagTot by 1440 to get the answer in gallons. This conversion factor is not related to the time period you are totalizing over; it is strictly a function of the point's engineering units.

               

              It sounds to me like a conversion factor.  If you are reading KWH then *24.  Hope that helps

               

              Chris