1 of 1 people found this helpful
I have moved your post to All Things PI because it lacked having code to justify being in PI Developers Club.
Do you not have a continuous measurement of tank percent full (or tank percent empty)? Is the only related measurement you receive truly a UOM from the Mass class? I find that odd because short of a tank percent fill, I normally would expect a Volume to know how much liquid is in the tank. It's Mass (or weight) would require knowing more about the density of the liquid.
To calculate a percent level based on Volume requires knowing meta data about the tank. Is the tank shape a cylinder, bullet, or sphere? Is the tank orientation vertical or horizontal? What is the height or length of the tank? What is the diameter or radius? Each answer would require a different set of calculations, some easier than others. Typically for most plants, these calculations would be done at the DCS reading the Volume. Then the PI interface would read that calculated value from the DCS just as if it were an instrument reading.
Are you trying to skimp and save on tag counts, which makes the a possible solution either very difficult or horribly slow, or do you have freedom to create tags as outputs from Asset Analytics? I don't think you need event frames.
You have 2 valves: input and output. It sounds like logically that one is the negative of the other. That is Input is open, Output is closed, and vice versa. As long as both cannot be open or both cannot be closed at the same time, you can treat them in a binary manner. You don't need a new tag for this, you would just look at either the Input valve being open or closed to decide if the tank is filling or discharging. Alternatively, you could look at the Output valve instead.
Using one of the valve's to decide the tank's Filling/Discharging state, I would suggest trying to calculate a DAILY value for both 'Daily Filling Mass' and 'Daily Discharge Mass'. This requires 2 new PI tags to be used as outputs from an Analysis. Then for a MONTHLY calculation, you would need yet another 2 new output tags ('Monthly Filling Mass' and 'Monthly Discharge Mass'). The monthly calculations will be much faster since they will be grabbing at most 31 daily values each. This also gives you the benefit of being able to see a partial monthly calculation quickly, or perhaps only recalculating for a specific day if the need arises.
If you are an EA customer with virtually unlimited tags, you could create a new tag to hold the binary tank state (filling vs discharging). This could be a Boolean, an integer 1 or 0, but I would recommend it be a digital state. I would have 3 states (0 = None, 1 = Discharging, 2 = Filling). The None state would be used in case the Input/Output valve has a bad value. You should try to set up the Analysis to update this state tag only on a change in state, which means NoOutput() is your friend.
Again, you don't need event frames for this.