6 Replies Latest reply on Dec 15, 2016 5:12 PM by knightk

    Need help to calculate the consumption of the current shift and the previous shift in PI AF

    Nicolas.Isambourg

      Dear Forum Members,

       

      our plant works 24 hours a day, in 3 shifts of 8 hours.

      • Shift A from 6h to 14h
      • Shft B from 14h to 22h
      • Shift C from 22h to 6h

       

      I have to calculate the consumption for the current shift and the previous shift in PI AF.

      So I created 3 PI AF attributes:

      • "Consumption" linked to a PI Point
      • "Consumption in the current shift"

                          PITagVal('Consumption', '*') - PITagVal('Consumption', {StartTime of the current shift})

      • "Consumption in the previous shift"

                          PITagVal('Consumption', {EndTime of the previous shift}) - PITagVal('Consumption', {StartTime of the previous shift})

       

      How can I model the shifts and their starttime and endtime ?

      How can I determine the starttime of the current shift and the starttime and endtime of the previous shift ?

      How would you configure the attributes "Consumption in the current shift" and "Consumption in the previous shift" ?

       

      Thanks,

      Best regards,

        • Re: Need help to calculate the consumption of the current shift and the previous shift in PI AF
          Asle Frantzen

          Hello

           

          This issue has been discussed several times before, so please use the search function and see what others have concluded with before!

           

          Here's one of the top results when searching for "AF+shift":

          Configuring Shift times in AF

          1 of 1 people found this helpful
          • Re: Need help to calculate the consumption of the current shift and the previous shift in PI AF
            pthivierge

            Hello Nicolas,

             

            Thanks for coming to PI Square

            Did the link provided by Asle has provided you enough details to achieve what you need?

             

            Please let us know how it goes!

            • Re: Need help to calculate the consumption of the current shift and the previous shift in PI AF
              Nicolas.Isambourg

              Hello,

               

              Thank you Asie.

              Sorry, I didn't use the search function. I read your link with attention.

              Before posting my topic, I had developed a table "Shift" which is a little more complicated than in the Jeremy Korman's example.

               

              Like in the example the first step is to determine what the current and previous shifts are.

              I defined attributes referencing table lookup to extract the data of the table.

               

               

              The difficulty is to calculate the consumption when the current shift is "C" from 22:00 to 6:00.

              If the current time is for example 23:00 then the consuption of the current shift will be calculated by a PI Analysis between 22:00 and *

                  TagVal('Conso','*')-TagVal('Conso',22))

               

              If the current time is for example 3:00 then then the consuption of the current shift will be calculated by a PI Analysis between t-2h and *

                  TagVal('Conso','*')-TagVal('Conso','t-2h'))

               

              That's why I created a table column "StartTimeCurShift".

              Other difficulty, I have to calculate the consumption of the previous shift.

              Like for the current shift, I created a table column "StartTimePrevShift" to help me to calculate the consumptions between the start time of the previous shift and the end time.

               

              What tips could help me to simplify it ?

               

              Thanks,

              Best regards,

              Nicolas

              • Re: Need help to calculate the consumption of the current shift and the previous shift in PI AF
                knightk

                How about using a tag to store the current shift time, it's previous value will always be the previous shift start time. You could do this very easily in Analysis. Create an analysis to simply output parsetime("*") which runs every 8 hours with a  6 hour offset. I would place these in an element at the root path for easy access from anywhere in AF, having this in a tag is always handy for things like Processbook displays showing current shift start time.

                 

                To calculate the current consumption, I would write this to a tag, this is event triggered on any input.

                To get the previous shift value, you simply just need the max value from the current tag, I would schedule this every 8 hours with 6 hour offset also, but increase the offset by something like 5 minutes just so you know the current value has reset at the start of the new shift. Then use a timestamp override to write the value relative to trigger *-5m (for timestamp at end, or a bit more for start of the previous shift!) This way you don't really need to know the start time of the previous shift. Make sure your prevValue tag has step enabled. The formula is simply...

                 

                 

                TagMax('Current Consumption','*-10m','*')  - The 10 min is just to make sure you compensate for any slow data, you might want to decrease/increase according to rate of source data to save putting too much hit on PI server every time there's a shift change.

                 

                 

                Here is 1 day of current consumption, showing the prev value trailing... (showing overlap for shift)

                1 of 1 people found this helpful