How do I test an AF enumeration set in an AF formula as in:A=DeviceState;[if A == FailoverState("OFF") then 1 else 0]
Unfortunately the Formula DR doesn't do string comparisons - see this thread. You will need to use the underlying enumeration value to perform the comparison.
How about providing an example of how to do that? I have searched PI documentation and PISquare for the past 2 hours trying to find one example of how to work with digital states in AF Formulas. By the way I do have an enumeration set. That's why I asked "How do I test an AF enumeration set in an AF formula..." I didn't ask how to test a string.Don't get me wrong, I appreciate getting a response. But it would be valuable if you actually read the question and provided some useful information.
While I can appreciate your frustration, your treatment of John is a bit rough. Maybe you are not aware, but John is not an employee of OSIsoft. He is a customer, just like you. One nice thing about the PI Square community is its involvement of customers and employees alike. Employees have to help you. Fellow customers like John do not. Considering you may have more questions to ask the entire community, it may not be in your best interests to give fellow customers reasons not to help you.
Secondly, your snippy reply suggests that John did not fully read your question. I can assure you he did. Perhaps you did not bother to go to the link he provided because you were so outraged at his use of "string". Yes, you didn't ask how to test a string. Nonetheless, your Formula does contain a string, right? What else do you call "OFF", i.e. the collection of letters enclosed in double quotes?
An AFEnumerationValue and a PI Digital State are similar in that they are dual valued objects. One one had they contain a string setting (e.g. "OFF"), and on the other hand they contain an integer value (perhaps 0). What John suggested to you, and what was evident in the link he provided, is that you cannot refer to a digital value in a Formula by using its string, as you currently do. This is because Formulas do not support strings. You will need to use the underlying enumeration value to perform the comparison. Which by the way, is a direct quote from John's very correct answer above.
So look up what the integer value is for state "OFF". And in your Formula change the comparison to use a strict numeric comparison. Pretending the value for "OFF" is 0, that would make your formula:
A=DeviceState;[if A == 0 then 1 else 0]
The above formula assumes nothing but good data. If DeviceState could have a bad value, you will want to check that state as well. You will want to review the logic to see if this applies to you.
A=DeviceState;[if badval(A) then 1 else if A == 0 then 1 else 0]
I did not intend to be ‘rough’ on John, although I can see where my response could be interpreted that way. Part of my problem is that PISquare has become like any other social media in that users pop out an answer trying to be the first so they can boost their rating on the site. Now I have no idea whether John is like that or not. I’m sure he is well meaning and an experienced PI user. You provided a useful answer, “A=DeviceState;[if A == 0 then 1 else 0]”, in your text below. But you won’t find that in the link John sent.
That one statement would have answered my question. Because I had already viewed the link John sent and many others similar to that none of the provide the answer. I also haven’t been find it in any OSIsoft documentation. Not saying it’s not there it’s just well hidden. Usually you get something like:
“Correct, the AF Formula data reference does not work with strings. To output strings I would suggest using an enumeration set with formula. To read strings I would recommend using an AF Analysis Express type. Overall, the AF Analysis Expression type offers much more flexibility and I'm using it more and more often.” – Dan Fishman
Not “A=DeviceState;[if A == 0 then 1 else 0]” which is much quicker to write and ten times as useful.
David M. Fairchild
PI System Administrator
I did read your question, and very clearly understood what you were asking for. I'm sorry that my initial response didn't provide the kind of clarity that you were expecting. Fortunately I'm thick skinned enough to not take offence at any of these comments, and for the record I'm not interested in simply answering questions first so that I can boosting my rankings in this (or any other) site. I do this to help others learn more about the PI system technology, which I am quite passionate about. In my day job I get paid to do this as a system integrator, but PI Square is my personal contribution back to the community, and the compensation I get for this is the satisfaction of helping others in the community - truly.
I will take your comments as a fair request - perhaps it's better to absolutely spell out the answer to a question like this and then assume that doing so will not be interpreted as spoon-feeding information in a way that is demeaning to one's intellect (unfortunately I have seen that as well). My natural assumption now is that people asking questions like this know enough about what they are working with to take a response like this and make the connection between the question and answer.
Rick has provided a very clear example of what was meant by comparing the underlying enumeration (integer) value, so I have nothing further to add to that. You now have a crystal clear example of how to move past the roadblock you have been stuck on, and I hope that this allows you to make further progress in what you are trying to achieve.
Code of conduct aside, I found this enumeration behavior quite interesting and as opportunity to ask some clarification on how enumeration works in AF and AF Analysis as we are not using them at all.
If I understood OP right, he is using enumerations in attribute data reference formula. Does same rule apply to functions available in analysis expressions?
Let's say I have an attribute "Running state" with enumeration STARTING/RUNNING/STOPPING/STOPPED and I would like to have an event frame creation based on Starting/Stopping states.
I could not find functions allowing comparing attribute enum value to EnumerationSet values, so would my only option be to compare integer values behind enumeration?
Coming from developer background, a bit more flexible use of enumerations would be nice.Something conceptually like 'Running State' == ((int)RunningStatusEnum.STARTING) or have a method to get enum int value by string.
So AF Analyses are a different proposition to the attribute based Formula DR when performing these type of comparisons, as you can actually do a string comparison in Analysis expressions. For an event frame start trigger expression you can do the following:
'Running State' = "STARTING"
and have the boolean result properly determined for the trigger evaluation. The assumptions here are that the 'Running State' attribute is configured as an AFEnumeration data type, so in this case you are comparing the string representation of the Attribute's current Enumeration value to a specific required text value (which should be one of your Enumeration set values) - no conversion or casting is required. This would be a slightly different story if you were doing something with the Enumerations in a programmatic environment.
Excellent, thanks heaps John.This is good news, as I mentioned, our AF journey is at very beginning, so easy and simple ways to use enums is going to help adoption of new tools easier for end users.
Retrieving data ...