SPC Measurement of a dataset

I have measurement data from a device stored in a SQL database in a cell as a tab delimited string. The size of the actual dataset that was stored inside the cell can be something like 1000 rows x 1 col. I created a SQL tag to extract this measurement data, which returns a tab delimited string.

I have setup a line/location that points to this SQL tag and collects it every time a certian event happens. I’d like to use the SPC to calculate the mean, range, etc. of the measurement data set.

Since the whole dataset is a tab delimited string, how do I tell the SPC module that the “measurement” isn’t one data point, but actually a bunch of points all together? More simply, how do I setup the SPC location to collect X number of datapoints and group them into 1 measurement?

The automatic collection of sample data only supports recording one measurement value per sample (sample size of one). Support for multiple measurements per sample is on our development list.

Currently, it can be done with the following script.
It can be in a timer script that queries the database at a timed interval or it can be modified for a tag change event for your tag containing the tab delimited string.

First you will need to created a sample definition with the correct attribute(s) and sample size. This is done in the definition management screen that come with the demo or it can be done in script (see the MES user’s manual). It can be named an appropriate name, but I’m calling it TempDefinition for this discussion.

Then use this code creates a new sample based on the sample definition and location path:

locationPath = ‘QualityDemo\New Enterprise\New Site\Packaging\Line 1\Line 1 Quality’ sampleDefName = 'TempDefinition' sample = system.quality.sample.data.getNewByDefName(sampleDefName, locationPath)

Next, measurements can be added to the sample where Temp is the name of the attribute:

for row in range(data.rowCount): temp = data.getValueAt(row, "Temperature") sample.setSampleData(row + 1, "Temp", str(temp))

Last, save the sample:

system.quality.sample.data.updateSample(‘QualityDemo\New Enterprise\New Site\Packaging\Line 1\Line 1 Quality’, sample, 1)

After samples are added, the mean, range, control limits and more can be view using the control charts.

So, if the SPC module doesn’t yet handle multiple data points per measurement, how can it calculate the range and standard deviation of a measurement with 1 data point? Doesn’t that ruin the XbarS and XbarR charts?

Ok, I follow what you are suggesting. It’s just not clear how the sample gets updated/added with the new measurement. If I follow your example, with using an existing sample, I made the following code:

[code] #–Get some info about a sample and location that is already setup
dat=event.source.parent.getComponent(‘Table’).data #look at some SPC data in a table
id=str(dat.getValueAt(0,“SampleUUID”)) #pull out the unique ID (of just the first row for now) that is auto created for each measurement sample by the SPC module

sample=system.quality.sample.data.getSample(id) #return the reference to the sample based on the UUID
ent=sample.getEnterprise()+ “\” #get the enterprise string
ste=sample.getSite()+ “\” #get the site string
ar=sample.getArea()+ “\” #get the area string
loc=sample.getLocation() #get the location string
strlocation=ent+ste+ar+loc #build the path string

#—To test, just create a 2nd measurement and write a value to it.
m_num=sample.getSampleDefinition().getMeasurementCount() #how many measurements are there in the current sample? (returns 1)
new_num=sample.getSampleDefinition().setMeasurementCount(2) #set the measuremment count to 2, just to test writing to a new row
val=124 #a randowm number to try out
d=sample.getSampleData(1,“Mean”) #Return the value of the data in row 1. the tag’s name is “Mean”
print d #display the value
newval=sample.setSampleData(new_num,“Mean”,str(val)) # set the value of the data in the new row. the tag’s name is “Mean”
print newval #did the new data get sucessfully written?
system.quality.sample.data.updateSample(strlocation,sample,1) #update the sample [/code]

Everything seems to work fine, except that it doesn’t seem to want to write the sample data in the new row (newval returns “False”).
Also, the updateSample() function returns an error with “Invalid Location string”. Since I know exactly the string, and am reading directly from it, how can it be invalid?

After some playing around, I got the following code to change the number of measurements in the Sample Definition and also write a value to any measurement I wanted to. Great!

The only question is how do I tell the SPC module to do this automatically in the Production Line setup? I’m guessing I’ll have to create a custom sample interval…

[code]#–Get some info about a sample and location that is already setup
dat=event.source.parent.getComponent(‘Table’).data #look at some SPC data in a table
id=str(dat.getValueAt(0,“SampleUUID”)) #pull out the unique ID (of just the first row for now) that is auto created for each measurement sample by the SPC module

sample=system.quality.sample.data.getSample(id) #return the reference to the sample based on the UUID
p1=sample.getLocationPath()

#—Use this code to change the number of measurements–
a=system.quality.definition.getSampleDefinition(33) #33 is the ID of the sample definition. get from SQL browser for now.
a.setMeasurementCount(3)
system.quality.definition.updateSampleDefinition(a) #This updates the sample definition measurement count

#—write a new measurement
val=453
newval=sample.setSampleData(2,“Mean”,str(val))

#update sample
system.quality.sample.data.updateSample(p1,sample,1) #update the sample
[/code]