Administrators Lindsey.Wilcox Posted September 17, 2019 Administrators Share Posted September 17, 2019 Often, users that are familiar with coding or Excel ask how to use IF statements in Seeq's Formula language. Essentially, these users are looking to perform certain calculations or analytics under a specific condition when the IF statement is true. In Seeq, users can use Conditions (or, less frequently, Boolean signals) to replace IF statements. When we identify a Condition, we are saying IF a condition is met [the value is above x, Shift 1 is occurring, the equipment is running, etc.], outline this period. Thus, Seeq Conditions are IF statements, and calculations done within a Condition (as well as functions applied to or during a Condition), are the THEN statements. This approach is unique, as making the Condition (defining the IF statement) is disconnected from the THEN statement, unlike many analytics apps in which the IF and THEN statement are always written together. However, this approach can be advantageous, as we can define an IF statement (make a Condition) and then do many THENs based on that Condition, saving time and making our calculations more efficient. The remainder of this post describes how to use Boolean signals to replace IF statements, which is recommended when performing calculations with capsules that have a maximum duration of longer than 30 days. If the maximum capsule duration is less than 30 days, users may use Conditions to replace IF statements, as described in the following post: This example creates a new single signal which runs different calculations during different periods of time. This technique can be used to replicate "if" logic or "if / else" logic currently being used in excel. Example existing code from excel or other systems IF Temperature > 90F Temperature * 100 IF Temperature < 90F Temperature + 10 Step 1: Create a Boolean Signal for High Temperature The following formula creates a Boolean signal that is equal to 1 when the high temperature (>90) condition is true and 0 when false. Using sign() adds an interpolated sample at the zero crossing so that the resulting signal steps at exactly the correct transition. The ($x.sign()+1)/2 idiom compensates for sign()'s behavior of producing values -1,1 when we want the boolean signal to be have values 0,1. (($Temperature - 90).sign() + 1)/2 Step 2: Create a Boolean Signal for Low Temperature The following formula creates a Boolean signal that is equal to 1 when the low temperature condition is true and 0 when false. ((90 - $Temperature).sign() + 1)/2 Step 3: Create the Final Signal This formula first multiplies each Boolean signal by the intended calculations that would be present for the respective conditions and then combines the two series. 1 Link to comment Share on other sites More sharing options...
Thorsten Vogt Posted September 18, 2019 Share Posted September 18, 2019 Hi Lindsey, another approach would be using the externalCalculation() function. The advantage is the general availability and reusibility of the function, but I am not quite sure if performance degradation may occur? Regards, Thorsten Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now