Signal Script Example

Sepasoft MES Module Suite

Signal Script Example

In the example script, any lines that start with the pound (#) character are comments and are ignored when the script is executed.

  • Initializes a variable used to track how many consecutive calculated values (like the x bar value) are above the control line (like the x double bar value).
  • The event.getData() returns the samples that will be used to calculate the signal state values. It is a data set (see Ignition Dataset in scripting for more information) and contains a row of data for each sample. Each sample row includes measurement values, calculated values (such as xBar, standard deviation, etc), sample date and time and control limits. There is also a column named the sample as the signal to save the signal state value. By setting the value of this column to a zero (0), the sample is in control for this signal, and by setting the value of this column to a one (1), the sample is out of control.
  • The ds.getColumnIndex returns the column number of the XBarXDBar and signal result columns. This is done for speed reasons because it is faster to reference the column by number instead of finding the column by name.
  • Each sample row in the data set is cycled through.
  • Reads the calculated value that in this case is the xBar value.
  • Reads the average of the calculated values, which in this case is the xDBar value.
  • A test is performed for the xBar value being greater than the xDBar. If it is, further checking is done in lines 22 through 38. If it is not, then the consecutive count variable is reset and the signal state value is set to 0 for the sample in lines 42 and 43.
  • Adds to the consecutive count variable before checking if the threshold of 8 has been exceeded.
  • Checks if the consecutive count threshold has been exceed. If not, the signal state value for the sample is set to 0 and the consecutive count variable is left at its current value.
  • Checks if the consecutive count just exceeded the threshold. If it just did, the signal state values for the previous 8 samples are set to 1. This flags the current sample and the previous 7 samples as out of control.
  • The else statement checks if more than 8 consecutive xBar values exceed the xBar value. It sets the signal state value to 1 and leaves the consecutive count variable at its current value.
Python
#8 Consecutive points above control line signal calculation
consecutiveCount = 0

#Get the SPC data that the signal will be calculated for
ds = event.getData()

#Get the columnn indexes within the SPC data
xBarColNdx = ds.getColumnIndex("XBar")
xDBarColNdx = ds.getColumnIndex("XDBar")
resultColNdx = ds.getColumnIndex("XBar 8 Above Control Line")

#Cycle through each row and check signal
for row in range(ds.rowCount):

	#Get the values to compare
 	xBar = ds.getValueAt(row, xBarColNdx)
	xDBar = ds.getValueAt(row, xDBarColNdx)

	#Test if the x bar value is above x double bar value
	if xBar > xDBar:
		#Add to the consecutive count
		consecutiveCount = consecutiveCount + 1

		#Test if less than 8 consecutive x bar values are above x double bar
		if consecutiveCount < 8:
			#Write a zero to the result column, meaning we are in control
			ds.setValueAt(row, resultColNdx, 0)                                
		elif consecutiveCount == 8:
			#Now 8 consecutive x bar values are above the x double bar
			#Write a 1 into the last 8 row because, they are all out of control
			ndx = row
			while ndx > 0 and ndx > row - 8:
				ds.setValueAt(ndx, resultColNdx, 1)
				ndx = ndx - 1
		else:
			#Over 8 consecutive x bar values are above x double bar
			#Continue writing a 1 into the result because this row is still out of control
			ds.setValueAt(row, resultColNdx, 1)                
	else:
	#x bar value is below, reset the consecutive count
	#and write a zero to the result column, meaning we are in control
	consecutiveCount = 0
	ds.setValueAt(row, resultColNdx, 0)

Sepasoft MES Module Suite