Sepasoft MES Module Suite
XBar UCL Calculation
Script Description:
- The event.getData() returns the samples that will be used to calculate the new control limit. This dataset contains a row of data for each sample. Each sample row includes measurement values, calculated values (such as xBar, standard deviation, etc), and the sample date and time. For the p and u charts where the control limits can vary by sample, this dataset includes columns to which the the newly calculated control limit for each sample can be saved.
- The ds.getColumnIndex returns the column number of the XBar and Range 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 dataset is cycled through. This is done to total the xBar and range values. The ds.getValueAt() function returns the value in the dataset for the specified row and column.
- The average of the xBar values is calculated, also known as x double bar (XDBar).
- Calculates the average of the range values, also known as range bar (RBar).
- The event.getSampleSize() returns the number of measurements per sample. This will be used to determine which a2 value to use from the array in line 5. The a2 is a factor to calculate the 3 sigma or 3 times standard deviation value and changes based on the number of measurements in each sample.
- Lookup the a2 value that is going to be used to calculate the new control limit value. A quick range check is done to prevent reading a value that is outside of the array limits.
- calculates the new UCL value.
- The value is saved to pass back the new control limit value.
Default XBar UCL control limit calculation script
Python |
#XBar UCL Calculation #Define the A2 factors array. #The A2 factors correspond to the sample size which starts at 2. #This is why element 0 and 1 of the array are 0. a2 = [0.0, 0.0, 1.880, 1.023, 0.729, 0.577, 0.483, 0.419, 0.373, 0.337, 0.308, 0.285, 0.266, 0.249, 0.235, 0.223, 0.212, 0.203, 0.194, 0.187, 0.180, 0.173, 0.167, 0.162, 0.157, 0.153] #Get the SPC data that the XBar UCL will be calculated for ds = event.getData() #Get the columnn indexes within the SPC data xBarColNdx = ds.getColumnIndex("XBar") rangeColNdx = ds.getColumnIndex("Range") #Initialize xBar and range sums that are need to calculate average xBar and range. xBarSum = 0.0 rSum = 0.0 #Cycle through each row and add to the sums for row in range(ds.rowCount): xBarSum = xBarSum + ds.getValueAt(row, xBarColNdx) rSum = rSum + ds.getValueAt(row, rangeColNdx) #Calculate the average xBar and range xDBar = xBarSum / ds.rowCount rBar = rSum / ds.rowCount #Get the sample size. sampleSize = event.getSampleSize() #Lookup the A2 value if sampleSize < len(a2): a2Value = a2[sampleSize] else: a2Value = a2[len(a2) - 1] #Calculate the xBar UCL ucl = xDBar + a2Value * rBar #Return the new xBar UCL back to the SPC module event.setControlLimitValue(ucl) |
Sepasoft MES Module Suite